Comparing version 0.2.2 to 0.2.3
@@ -102,17 +102,19 @@ function valueEnumerable(value) { | ||
}; | ||
function machineToPromise(machine) { | ||
return function(ctx, ev) { | ||
return new Promise(resolve => { | ||
const machineToThen = machine => function(ctx, ev) { | ||
return { | ||
then: resolve => { | ||
this.child = interpret(machine, s => { | ||
this.onChange(s); | ||
if(s.machine.state.value.final) { | ||
delete this.child; | ||
resolve(s.context); | ||
} | ||
}, ctx, ev); | ||
}); | ||
return { catch: identity }; | ||
} | ||
}; | ||
} | ||
}; | ||
export function invoke(fn, ...transitions) { | ||
return create(invokeType, { | ||
fn: valueEnumerable(machine.isPrototypeOf(fn) ? machineToPromise(fn) : fn), | ||
fn: valueEnumerable(machine.isPrototypeOf(fn) ? machineToThen(fn) : fn), | ||
transitions: valueEnumerable(transitionsToMap(transitions)) | ||
@@ -119,0 +121,0 @@ }); |
{ | ||
"name": "robot3", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "A function, immutable Finite State Machine library", | ||
"main": "machine.js", | ||
"main": "dist/machine.js", | ||
"module": "machine.js", | ||
"type": "module", | ||
"files": [ | ||
"dist/", | ||
"debug.js", | ||
@@ -16,3 +17,5 @@ "machine.js" | ||
"server": "http-server -p 1965", | ||
"test": "node-qunit-puppeteer http://localhost:1965/test/test.html 10000" | ||
"test": "node-qunit-puppeteer http://localhost:1965/test/test.html 10000", | ||
"build": "rollup -d dist -f cjs machine.js debug.js", | ||
"preversion": "npm run build" | ||
}, | ||
@@ -40,4 +43,5 @@ "repository": { | ||
"node-qunit-puppeteer": "^1.0.13", | ||
"rollup": "^1.21.4", | ||
"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
15222
7
373
9