Skip to content

Commit

Permalink
linting stuff and html stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Aug 5, 2017
1 parent 1753f36 commit 0b8715a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dist/jssm.es5.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/lib/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>jssm 4.1.5 | Documentation</title>
<title>jssm 4.1.6 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>4.1.5</code></div>
<div class='mb1'><code>4.1.6</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "4.1.5",
"version": "4.1.6",
"engines": {
"node": ">=6.0.0"
},
Expand Down Expand Up @@ -88,7 +88,7 @@
"del-cli": "^1.1.0",
"documentation": "^4.0.0",
"eslint": "^4.3.0",
"eslint-config-stonecypher": "^1.12.3",
"eslint-config-stonecypher": "^1.13.1",
"eslint-plugin-ava": "^4.2.1",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-fp": "^2.3.0",
Expand Down
5 changes: 4 additions & 1 deletion src/demo/index.html
Expand Up @@ -18,9 +18,12 @@
var jssm, sm;

window.onload = () => {

jssm = require('jssm');
sm = jssm.sm;
document.body.innerHTML = '<h1>Ready</h1><p>JSSM has now been loaded, 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 -> red => green => yellow => red; [red yellow green] ~> 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>';

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 -> red => green => yellow => red; [red yellow green] ~> 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>`;

}

</script>
Expand Down
20 changes: 17 additions & 3 deletions src/js/jssm.js
Expand Up @@ -23,7 +23,7 @@ const parse : (string) => JssmTransitions<string, any> = require('./jssm-dot.js'

function compile_rule_handle_transition_step<mNT, mDT>(acc : Array<mixed>, from : mNT, to : mNT, se : any) { // todo flow describe the parser representation of a transition step extension

const new_acc = acc.concat({ from, to });
const new_acc : Array<mixed> = acc.concat({ from, to }); // todo whargarbl can do better than array mixed

if (se) {
return compile_rule_handle_transition_step(new_acc, to, se.to, se.se);
Expand Down Expand Up @@ -55,9 +55,14 @@ function compile<mNT, mDT>(tree : any) : JssmGenericConfig<mNT, mDT> { // todo

const results = {};

tree.map( (tr) => {
const { agg_as, val } = compile_rule_handler(tr);
tree.map( tr => {

const crh_result : mixed = compile_rule_handler(tr),
agg_as : string = crh_result.agg_as,
val : mixed = crh_result.val;

results[agg_as] = (results[agg_as] || []).concat(val);

});

const assembled_transitions = [].concat(... results['transition']);
Expand Down Expand Up @@ -527,7 +532,16 @@ function sm<mNT, mDT>(template_strings : Array<string> /* , arguments */) : any
*/

return new Machine(compile(parse(template_strings.reduce(

// in general avoiding `arguments` is smart. however with the template
// string notation, as designed, it's not really worth the hassle

/* eslint-disable fp/no-arguments */
/* eslint-disable prefer-rest-params */
(acc, val, idx) => `${acc}${arguments[idx]}${val}` // arguments[0] is never loaded, so args doesn't need to be gated
/* eslint-enable prefer-rest-params */
/* eslint-enable fp/no-arguments */

))));

}
Expand Down
4 changes: 2 additions & 2 deletions src/js/tests/compile.js
@@ -1,7 +1,7 @@

/* eslint-disable max-len */

import {test, describe} from 'ava-spec';
import {describe} from 'ava-spec';

const jssm = require('../../../build/jssm.es5.js');

Expand Down Expand Up @@ -35,7 +35,7 @@ describe('compile/1', async _parse_it => {
describe('error catchery', async _parse_it => {

describe('unknown rule', async it => {
it('throws', t => t.throws( () => { jssm.compile( [{"key":"FAKE_RULE","from":"a","se":{"kind":"->","to":"b"}}] ); } ))
it('throws', t => t.throws( () => { jssm.compile( [{"key":"FAKE_RULE","from":"a","se":{"kind":"->","to":"b"}}] ); } ));
});

});
Expand Down
6 changes: 3 additions & 3 deletions src/js/tests/sm_tag.js
Expand Up @@ -13,15 +13,15 @@ const jssm = require('../../../build/jssm.es5.js'),
describe('sm``', async _parse_it => {

describe('simple sm`a->b;`', async it => {
it('doesn\'t throw', t => t.notThrows(() => { const foo = sm`a -> b;`; }) );
it('doesn\'t throw', t => t.notThrows(() => { const _foo = sm`a -> b;`; }) );
});

describe('long and chain sm`a->b;c->d;e->f->g;h->i;`', async it => {
it('doesn\'t throw', t => t.notThrows(() => { const foo = sm`a->b;c->d;e->f->g;h->i;`; }) );
it('doesn\'t throw', t => t.notThrows(() => { const _foo = sm`a->b;c->d;e->f->g;h->i;`; }) );
});

describe('template tags`', async it => {
it('doesn\'t throw', t => t.notThrows(() => { const bar = 'c->d', baz = 'b->h->i;f->h', foo = sm`a->b;${bar};e->f->g;${baz};`; }) );
it('doesn\'t throw', t => t.notThrows(() => { const bar = 'c->d', baz = 'b->h->i;f->h', _foo = sm`a->b;${bar};e->f->g;${baz};`; }) );
});

});
Expand Down

0 comments on commit 0b8715a

Please sign in to comment.