statetransition-mixin
Advanced tools
Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "statetransition-mixin", | ||
"description": "mixin to declare state transition methots like start & stop", | ||
"main": "StatesTransitionMixin.js", | ||
"main": "StateTransitionMixin.js", | ||
"scripts": { | ||
@@ -38,3 +38,3 @@ "cover": "node --harmony ./node_modules/istanbul/lib/cli.js cover --hook-run-in-context ./node_modules/mocha/bin/_mocha -- --R spec --U exports tests", | ||
"homepage": "https://github.com/arlac77/statetransition-mixin#readme", | ||
"version": "1.3.0" | ||
"version": "1.3.1" | ||
} |
@@ -28,2 +28,4 @@ /* jslint node: true, esnext: true */ | ||
const duringTransitions = {}; | ||
let target; | ||
Object.keys(a).forEach(initialState => { | ||
@@ -38,2 +40,3 @@ const t = a[initialState]; | ||
addState(t.target); | ||
target = t.target; | ||
}); | ||
@@ -43,3 +46,4 @@ actions[actionName] = { | ||
initial: initialTransitions, | ||
during: duringTransitions | ||
during: duringTransitions, | ||
target: target | ||
}; | ||
@@ -56,3 +60,3 @@ }); | ||
const _Base = { | ||
const BaseMethods = { | ||
/** | ||
@@ -108,3 +112,3 @@ * Called when state transition action is not allowed | ||
Object.assign(object, Base); | ||
Object.assign(object, BaseMethods); | ||
Object.defineProperties(object, properties); | ||
@@ -162,6 +166,2 @@ }; | ||
console.log( | ||
`KEYS: ${Object.getOwnPropertyNames(module.exports.StateTransitionMixin)} ${module.exports.StateTransitionMixin}` | ||
); | ||
function rejectUnlessResolvedWithin(promise, timeout) { | ||
@@ -229,3 +229,9 @@ if (timeout === 0) return promise; | ||
value: function () { | ||
// normal start | ||
// target state already reached | ||
if (this.state === action.target) { | ||
return Promise.resolve(this); | ||
} | ||
// normal start we are in the initial state of the action | ||
if (action.initial[this.state]) { | ||
@@ -232,0 +238,0 @@ this._transition = action.initial[this.state]; |
@@ -88,2 +88,9 @@ /* global describe, it, xit */ | ||
it('can be started while running', function (done) { | ||
o.start().then(() => { | ||
assert.equal(o.state, 'running'); | ||
done(); | ||
}, done); | ||
}); | ||
it('and stoped', function (done) { | ||
@@ -90,0 +97,0 @@ o.stop().then(() => { |
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
23106
354