How to use jssm - 2 common examples

To help you get started, we’ve selected a few jssm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StoneCypher / jssm / src / demo / index.html View on Github external
window.onload = () => {

        let jssm = require('jssm'),
            sm   = jssm.sm;

        document.body.innerHTML = `<h1>Ready</h1><p>JSSM has now been loaded at version ${jssm.version}, and is bound to the global <code>jssm</code> (aka <code>window.jssm</code>.)  Also, the state machine template string tag is exposed as <code>sm</code> (aka <code>window.sm</code>).</p><p>Please open a console and type something like</p><p><code>var traffic_light = sm<b>\` off -&gt; red =&gt; green =&gt; yellow =&gt; red; [red yellow green] ~&gt; off; \`</b>;</code></p><p>Now you have a working state machine to play with:</p><pre>&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("green");\nfalse\n\n&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("red");\ntrue\n\n&gt; traffic_light.state();\n"red"</pre><p>Consoles are <kbd>f12</kbd> on Windows and Linux PCs, or <kbd>command-option-j</kbd> on Macs.</p>`;

      }
github StoneCypher / jssm / src / demo / index.html View on Github external
window.onload = () =&gt; {

        let jssm = require('jssm'),
            sm   = jssm.sm;

        document.body.innerHTML = `<h1>Ready</h1><p>JSSM has now been loaded at version ${jssm.version}, and is bound to the global <code>jssm</code> (aka <code>window.jssm</code>.)  Also, the state machine template string tag is exposed as <code>sm</code> (aka <code>window.sm</code>).</p><p>Please open a console and type something like</p><p><code>var traffic_light = sm<b>\` off -&gt; red =&gt; green =&gt; yellow =&gt; red; [red yellow green] ~&gt; off; \`</b>;</code></p><p>Now you have a working state machine to play with:</p><pre>&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("green");\nfalse\n\n&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("red");\ntrue\n\n&gt; traffic_light.state();\n"red"</pre><p>Consoles are <kbd>f12</kbd> on Windows and Linux PCs, or <kbd>command-option-j</kbd> on Macs.</p>`;

      }

jssm

A Javascript finite state machine (FSM) with a terse DSL and a simple API. Most FSMs are one-liners. Fast, easy, powerful, well tested, typed with TypeScript, and visualizations. MIT License.

MIT
Latest version published 2 months ago

Package Health Score

70 / 100
Full package analysis

Popular jssm functions