Skip to content

customizable abstract function layer for your JavaScript application

License

Notifications You must be signed in to change notification settings

oltdaniel/watasu

Repository files navigation

watasu

Watasu (Japanese: 渡す; English: pass on) is a simple JavaScript abstraction, that simply passes on a function call from a safe run context to the outside. This allows for a quick execution, as the program will only describe the order and values of calls in native JavaScript.

Example

This is a screenshot of the example that can be found in ./index.html. It is deployed at oltdaniel.eu/watasu.

Usage

The project is compiled as an esmodule. So you can use it like:

<script type="module">
  import Watasu from 'http://cdn.jsdelivr.net/gh/oltdaniel/watasu/dist/watasu.js';

  const watasu = new Watasu();
  watasu.loadProgram(`
  set(sum, 0);
  inc(sum);
  print("current sum is ", sum);
  `);

  watasu.registerCall('set', function set(name, value) {
    if (name.name === 'dataReference') {
      this._context[name.value] = this.resolveParameterValue(value);
    } else {
      throw new Error('invalid set call');
    }
  })
  watasu.registerCall('inc', function inc(name) {
    if (name.name === 'dataReference') {
      this._context[name.value]++;
    } else {
      throw new Error('invalid inc call');
    }
  })
  watasu.registerCall('print', function print(...args) {
    console.log(...this.resolveParametersValues(args));
  })

  while(!watasu._runner.isDone) {
    watasu.step();
  }
</script>

Developing

We use esbuild because it is easy and supports exactly what we need to build a simple library.

# get the repo
git clone https://github.com/oltdaniel/watasu.git
cd watasu
# start live rebuild
yarn watch
# fix all eslint errors
yarn eslint . --fix
# all changes done. do production build
yarn build
# commit

License

Do what you'd like to do. But keep sharing it publicly.

GitHub

About

customizable abstract function layer for your JavaScript application

Topics

Resources

License

Stars

Watchers

Forks