vepp

0.12.0 • Public • Published

Vepp

A light TypeScript framework for ZeppOS, be maked to solve the rubbish widget system in native ZeppOS.

Languagues

Before start

You have to know, in ZeppOS, there are so many hard-to-solve limits:

  • eval() and new Function() are disabled
  • Rubbish widget system
  • Rubbish running efficiency (may be caused by hardware)
  • Deceptive APIs

But maybe you don't believe, Vepp solves all of them:

  • Skip new Function()'s limit by a special way
  • Build a pefect widget system in your favourite way
  • Make core codes short, easy and fast
  • Precompile the VML syntax (see below) by CLI, make it faster and faster
  • Deal with deceptive APIs for you

Now, start learning and enjoy!

Quick start

Let's see what ZeppOS apps made by Vepp is like:

<!-- this is the special syntax called VML (Vepp Markup Language), you can use it in `.vepp` suffixed files -->

<!-- each common element stands for a widget in ZeppOS -->
<!-- and each common property stands for a parameter or a property of a widget in ZeppOS -->
<text
    :h="
        // there are two built-in variables: `$w` and `$h`, they reference to device's width and height
        $h * 0.5
    "
    :text="
        /* use `:name='expression'` to set a reactive property */
        txt + '~'
    "
    @click-up="
        /* use `@name='statements'` to set an event */
        // get event argument by built-in variable `$arg`
        test($arg);
        // get the current widget object in native by `$widget`
        console.log('ID of the widget: ' + $widget.getId());
    "
    @vepp-init="
        // this is our built-in event named `vepp_init`
        // the codes here will be executed after the widget is first rendered
        console.log('first rendered!!!')
    ">
</text>
<!-- what's more, you can also use the form of `name="text"` to set a static and stringify property easily -->

<!-- we have special elements `script` which allow you to write your own JS -->
<!-- the following one has a `pre` attribute, the codes in it will be executed BEFORE Vepp's instance is initialized -->
<script pre>
    /* you MUST declare your reactive variables here, otherwise they may cause crash when they are not declared or initialized but are used before the first render */

    // `this`              :    references to all your reactive variables

    this.txt = 'hello, world'
    this.test = (arg) => {
        console.log('event argument: ' + JSON.stringify(arg))
        this.txt += '!'
    }
</script>
<!-- this one does not has a `pre` attribute, the codes in it will be executed AFTER Vepp's instance is initialized i.e. AFTER the first render -->
<script>
    // `$vepp`             :    references to your Vepp instance
    // `this`              :    the short form of $vepp.data, i.e. your reactive variables

    // use `$vepp.watch(...)` to watch your reactive variables
    // when variable `txt` is changed, `func` will be triggered here:
    $vepp.watch('txt', () => console.log(`[A] variable 'txt' was changed as: ` + this.txt))
    // ditto:
    $vepp.watch(() => console.log(`[B] variable 'txt' was changed as: ` + this.txt))
</script>

Are you surprised? Yes, that's the way to work with her: everyone who has experienced front-end development knows how to use it now!

But wait a moment! This syntax which seems like HTML cannot be compiled by ZeppCLI directly. You may use Vepp's CLI and be with its help. Here is how to install Vepp and its CLI:

# Vepp merges its core part and its CLI in a package.
# WARNING: it is invalid to import global packages in ZeppOS's project, so you MUST do like this:
npm install vepp
npm install vepp -g

And then initialize and compile your .vepp files in the project:

vepp init test-project
cd ./test-project
vepp compile

It's done! What's more, you can do this and use the watcher mode to compile automatically when changing:

# WARNING: although this mode is cool, it may not work as usual while other file watchers are working (like ZeppCLI)
vepp auto

Advanced Features

Two-way Bindings

Although Vepp follows the native ZeppOS's APIs overall, for example, you can do anything in Vepp as you are in native ZeppOS, there are many troublesome and trivial things: e.g. forms, lists, etc. But Vepp has already considered!

Let's see an easy example of form:

<!-- you can make two-way bindings on forms by the special property `vepp_value` -->
<!-- NOTICE!! Only the widgets `radio_group`, `checkbox_group` and `slide-switch` supports this feature now, wait for a while as I'm hard developing! -->

<checkbox-group
        :h="64"
        select-src="select.png"
        unselect-src="unselect.png"
        :vepp-value="checked">
    <state-button :x="40" :y="200" :w="64" :h="64" vepp-value="A"></state-button>
    <state-button :x="190" :y="200" :w="64" :h="64" vepp-value="B"></state-button>
    <state-button :x="340" :y="200" :w="64" :h="64" vepp-value="C"></state-button>
</checkbox-group>
<text :y="100" :h="100" :text="'checked: ' + checked"></text>
<button :y="400" :h="100" text="check all" :click-func="()=>{checked=['A','B','C']}"></button>

<script pre>
    this.checked = ['B']
</script>

Is it pretty enough? You needn't do anything but to set the special built-in property named vepp_value, and then you achieve the data stream on forms! I think it's no need for me to introduce more in this example :)

Polyfills

Vepp prepares varied polyfills for you, here we have the list of them:

  • class Buffer
  • class Function
  • class Logger
  • function setTimeout
  • function clearTimeout
  • function setInterval
  • function clearInterval
  • function setImmediate
  • function clearImmediate
  • function console.time
  • function console.timeEnd

Other details

  • The dependencies tracking feature is only for Array and plain Object (with native constructor Object), other objects like Map and Set are NOT including
  • - and _ are the same in VML; VML ignores case

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.12.02latest

Version History

VersionDownloads (Last 7 Days)Published
0.12.02
0.11.210
0.11.200
0.11.190
0.11.180
0.11.170
0.11.160
0.11.150
0.11.140
0.11.130
0.11.120
0.11.110
0.11.101
0.11.90
0.11.80
0.11.70
0.11.60
0.11.50
0.11.40
0.11.30
0.11.21
0.11.10
0.11.00
0.10.290
0.10.280
0.10.270
0.10.260
0.10.250
0.10.241
0.10.230
0.10.221
0.10.211
0.10.200
0.10.190
0.10.180
0.10.170
0.10.160
0.10.150
0.10.140
0.10.130
0.10.120
0.10.110
0.10.100
0.10.90
0.10.80
0.10.70
0.10.60
0.10.50
0.10.40
0.10.30
0.10.20
0.10.10
0.10.00
0.9.20
0.9.10
0.9.00
0.8.140
0.8.130
0.8.120
0.8.110
0.8.100
0.8.90
0.8.80
0.8.70
0.8.60
0.8.50
0.8.40
0.8.30
0.8.10
0.8.00
0.7.10
0.7.00
0.6.30
0.6.20
0.6.10
0.5.50
0.5.40
0.5.30
0.5.20
0.5.10
0.5.00
0.4.80
0.4.70
0.4.60
0.4.40
0.4.30
0.4.20
0.4.10
0.4.00
0.3.70
0.3.60
0.3.50
0.3.40
0.3.31
0.3.20
0.3.10
0.3.00
0.2.50
0.2.40
0.2.20
0.2.10
0.2.00
0.1.41
0.1.30
0.1.21
0.1.10

Package Sidebar

Install

npm i vepp

Weekly Downloads

10

Version

0.12.0

License

MIT

Unpacked Size

62.4 kB

Total Files

18

Last publish

Collaborators

  • jwhgzs