Comparing version 0.1.0 to 0.2.0
@@ -13,5 +13,4 @@ function valueEnumerable(value) { | ||
let identity = a => a; | ||
let identity2 = (a, b) => b; | ||
let callBoth = (par, fn, self, args) => par.apply(self, args) && fn.apply(self, args); | ||
let callForward = (par, fn, self, [a, b]) => fn.call(self, a, par.call(self, a, b)); | ||
let callForward = (par, fn, self, [a, b]) => fn.call(self, par.call(self, a, b), b); | ||
let create = (a, b) => Object.freeze(Object.create(a, b)); | ||
@@ -31,5 +30,2 @@ | ||
let actionType = {}; | ||
export let action = fnType.bind(actionType); | ||
let reduceType = {}; | ||
@@ -47,3 +43,3 @@ export let reduce = fnType.bind(reduceType); | ||
let guards = stack(filter(guardType, args).map(t => t.fn), truthy, callBoth); | ||
let reducers = stack(filter(reduceType, args).map(t => t.fn), identity2, callForward); | ||
let reducers = stack(filter(reduceType, args).map(t => t.fn), identity, callForward); | ||
return [guards, reducers]; | ||
@@ -111,3 +107,3 @@ } | ||
return function() { | ||
return new Promise((resolve, reject) => { | ||
return new Promise(resolve => { | ||
this.child = interpret(machine, s => { | ||
@@ -137,7 +133,7 @@ this.onChange(s); | ||
}; | ||
export function createMachine(states, contextFn) { | ||
export function createMachine(states, contextFn = empty) { | ||
if(d._create) d._create(states); | ||
let current = Object.keys(states)[0]; | ||
return create(machine, { | ||
context: valueEnumerable(contextFn || empty), | ||
context: valueEnumerable(contextFn), | ||
current: valueEnumerable(current), | ||
@@ -152,3 +148,3 @@ states: valueEnumerable(states) | ||
if(guards(context)) { | ||
service.context = reducers.call(service, fromEvent, context); | ||
service.context = reducers.call(service, context, fromEvent); | ||
@@ -186,2 +182,3 @@ let original = machine.original || machine; | ||
}; | ||
export function interpret(machine, onChange) { | ||
@@ -196,2 +193,2 @@ let s = Object.create(service, { | ||
return s; | ||
} | ||
} |
{ | ||
"name": "robot3", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A function, immutable Finite State Machine library", | ||
@@ -13,2 +13,4 @@ "main": "machine.js", | ||
"scripts": { | ||
"minify": "terser machine.js -o machine.min.js", | ||
"bundlesize": "npm run minify && bundlesize --config bundlesize.json", | ||
"server": "http-server -p 1965", | ||
@@ -21,3 +23,5 @@ "test": "node-qunit-puppeteer http://localhost:1965/test/test.html 10000" | ||
}, | ||
"keywords": ["Finite State Machine"], | ||
"keywords": [ | ||
"Finite State Machine" | ||
], | ||
"author": "Matthew Phillips <matthew@matthewphillips.info>", | ||
@@ -32,7 +36,9 @@ "license": "BSD-2-Clause", | ||
"@11ty/eleventy-plugin-syntaxhighlight": "^2.0.3", | ||
"bundlesize": "^0.18.0", | ||
"http-server": "^0.11.1", | ||
"markdown-it": "^9.1.0", | ||
"markdown-it-toc-and-anchor": "^4.2.0", | ||
"node-qunit-puppeteer": "^1.0.13" | ||
"node-qunit-puppeteer": "^1.0.13", | ||
"terser": "^4.3.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7901
40
8
178