Comparing version 0.5.2 to 0.5.3
@@ -40,2 +40,3 @@ declare const Finity: { | ||
on(event: E): TriggerConfigurator<S, E>; | ||
onAny(): TriggerConfigurator<S, E>; | ||
onTimeout(timeout: number): TimerConfigurator<S, E>; | ||
@@ -42,0 +43,0 @@ do(asyncOperation: AsyncOperation<S, E>): AsyncConfigurator<S, E>; |
@@ -41,2 +41,3 @@ 'use strict'; | ||
events: Object.create(null), | ||
anyEventTrigger: null, | ||
timers: [], | ||
@@ -66,2 +67,9 @@ asyncActions: [], | ||
StateConfigurator.prototype.onAny = function onAny() { | ||
if (!this.config.anyEventTrigger) { | ||
this.config.anyEventTrigger = new _TriggerConfigurator2.default(this); | ||
} | ||
return this.config.anyEventTrigger; | ||
}; | ||
StateConfigurator.prototype.onTimeout = function onTimeout(timeout) { | ||
@@ -68,0 +76,0 @@ var timerConfigurator = new _TimerConfigurator2.default(this, timeout); |
@@ -265,4 +265,14 @@ 'use strict'; | ||
var transitionConfig = null; | ||
var eventConfig = stateConfig.events[context.event]; | ||
return eventConfig ? StateMachine.getFirstAllowedTransition(eventConfig.transitions, context) : null; | ||
if (eventConfig) { | ||
transitionConfig = StateMachine.getFirstAllowedTransition(eventConfig.transitions, context); | ||
} | ||
if (!transitionConfig && stateConfig.anyEventTrigger) { | ||
transitionConfig = StateMachine.getFirstAllowedTransition(stateConfig.anyEventTrigger.transitions, context); | ||
} | ||
return transitionConfig; | ||
}; | ||
@@ -269,0 +279,0 @@ |
{ | ||
"name": "finity", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "A finite state machine library for Node.js and the browser with a friendly configuration DSL", | ||
@@ -51,3 +51,3 @@ "keywords": [ | ||
"webpack": "^2.2.1", | ||
"cross-env": "^3.1.4", | ||
"cross-env": "^3.2.3", | ||
"typescript": "^2.2.1", | ||
@@ -54,0 +54,0 @@ "shx": "^0.2.2", |
@@ -95,3 +95,3 @@ # finity | ||
To add a transition that is triggered by an event, first call the `on` method, passing in the name of the event. Then call the `transitionTo` method, passing in the name of the target state. | ||
To add a transition that is triggered by a specific event, first call the `on` method, passing in the name of the event. Then call the `transitionTo` method, passing in the name of the target state. | ||
@@ -108,2 +108,14 @@ ```javascript | ||
To add a catch-all transition that is triggered by any event, use the `onAny` method. (Event-specific transitions take precedence over catch-all transitions.) | ||
```javascript | ||
Finity | ||
.configure() | ||
.initialState('state1') | ||
// Perform a transition to state2 when eventA occurs | ||
.on('eventA').transitionTo('state2') | ||
// Perform a transition to state3 when any other event occurs | ||
.onAny().transitionTo('state3') | ||
``` | ||
##### Time-based triggers | ||
@@ -110,0 +122,0 @@ |
@@ -9,15 +9,6 @@ # Roadmap | ||
- [x] Hierarchical state machines | ||
- [ ] Ignoring events | ||
- [x] Ignoring events | ||
- [ ] Async transitions *(in progress)* | ||
- [ ] Persistence support | ||
### Ignoring events | ||
```javascript | ||
.state('state1').on('eventA').ignore() | ||
``` | ||
### Persistence support | ||
TBD... | ||
## Documentation | ||
@@ -29,2 +20,3 @@ | ||
- [ ] Project website *(in progress)* | ||
- [ ] Hierarchical state machines | ||
- [ ] Clarify that final states don't need to be explicitly defined | ||
@@ -31,0 +23,0 @@ - [ ] Execution order of entry, exit, and transition actions and global hooks |
@@ -386,2 +386,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
events: Object.create(null), | ||
anyEventTrigger: null, | ||
timers: [], | ||
@@ -411,2 +412,9 @@ asyncActions: [], | ||
StateConfigurator.prototype.onAny = function onAny() { | ||
if (!this.config.anyEventTrigger) { | ||
this.config.anyEventTrigger = new _TriggerConfigurator2.default(this); | ||
} | ||
return this.config.anyEventTrigger; | ||
}; | ||
StateConfigurator.prototype.onTimeout = function onTimeout(timeout) { | ||
@@ -1088,4 +1096,14 @@ var timerConfigurator = new _TimerConfigurator2.default(this, timeout); | ||
var transitionConfig = null; | ||
var eventConfig = stateConfig.events[context.event]; | ||
return eventConfig ? StateMachine.getFirstAllowedTransition(eventConfig.transitions, context) : null; | ||
if (eventConfig) { | ||
transitionConfig = StateMachine.getFirstAllowedTransition(eventConfig.transitions, context); | ||
} | ||
if (!transitionConfig && stateConfig.anyEventTrigger) { | ||
transitionConfig = StateMachine.getFirstAllowedTransition(stateConfig.anyEventTrigger.transitions, context); | ||
} | ||
return transitionConfig; | ||
}; | ||
@@ -1092,0 +1110,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Finity=e():t.Finity=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=17)}([function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=n(16),s=o(u),a=function(){function t(e){r(this,t),this.parent=e}return t.prototype.getAncestor=function(t){return this.parent?this.parent instanceof t?this.parent:this.parent.getAncestor(t):null},t.prototype.buildConfig=function(){var e=function e(n){return n?n instanceof t?n.buildConfig():Array.isArray(n)?n.map(e):n&&"object"===("undefined"==typeof n?"undefined":i(n))?(0,s.default)(n,e):n:n};return(0,s.default)(this.config,e)},t}();e.default=a},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(6),f=o(c),l=function(t){function e(n){r(this,e);var o=i(this,t.call(this,n));return o.config={transitions:[]},o}return u(e,t),e.prototype.transitionTo=function(t){return this.transition(t)},e.prototype.selfTransition=function(){return this.transition(null)},e.prototype.internalTransition=function(){return this.transition(null,{isInternal:!0})},e.prototype.ignore=function(){return this.transition(null,{ignore:!0})},e.prototype.transition=function(t,e){var n=new f.default(this,t,e);return this.config.transitions.push(n),n},e}(a.default);e.default=l},function(t,e,n){"use strict";function o(t,e){return Object.keys(e).forEach(function(n){t[n]=e[n]}),t}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(1),f=o(c),l=function(t){function e(n,o){r(this,e);var u=i(this,t.call(this,n));return u.config={action:o,successTrigger:new f.default(u),failureTrigger:new f.default(u)},u}return u(e,t),e.prototype.onSuccess=function(){return this.config.successTrigger},e.prototype.onFailure=function(){return this.config.failureTrigger},e}(a.default);e.default=l},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=function(t){function e(n){r(this,e);var o=i(this,t.call(this,n));return o.config={stateEnterHooks:[],stateExitHooks:[],stateChangeHooks:[],transitionHooks:[],unhandledEventHooks:[]},o}return u(e,t),e.prototype.onStateEnter=function(t){return this.config.stateEnterHooks.push(t),this},e.prototype.onStateExit=function(t){return this.config.stateExitHooks.push(t),this},e.prototype.onStateChange=function(t){return this.config.stateChangeHooks.push(t),this},e.prototype.onTransition=function(t){return this.config.transitionHooks.push(t),this},e.prototype.onUnhandledEvent=function(t){return this.config.unhandledEventHooks.push(t),this},e}(a.default);e.default=c},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(1),f=o(c),l=n(10),h=o(l),p=n(3),y=o(p),d=function(t){function e(n){r(this,e);var o=i(this,t.call(this,n));return o.config={entryActions:[],exitActions:[],events:Object.create(null),timers:[],asyncActions:[],submachine:null},o}return u(e,t),e.prototype.onEnter=function(t){return this.config.entryActions.push(t),this},e.prototype.onExit=function(t){return this.config.exitActions.push(t),this},e.prototype.on=function(t){return this.config.events[t]||(this.config.events[t]=new f.default(this)),this.config.events[t]},e.prototype.onTimeout=function(t){var e=new h.default(this,t);return this.config.timers.push(e),e},e.prototype.do=function(t){var e=new y.default(this,t);return this.config.asyncActions.push(e),e},e.prototype.submachine=function(t){return this.config.submachine=t,this},e}(a.default);e.default=d},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},a=n(0),c=o(a),f=function(t){function e(n,o){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r(this,e);var a=i(this,t.call(this,n));return a.config=s({targetState:o},u,{actions:[],condition:null}),a}return u(e,t),e.prototype.withAction=function(t){return this.config.actions.push(t),this},e.prototype.withCondition=function(t){return this.config.condition=t,this},e}(c.default);e.default=f},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var i=n(13),u=o(i),s=n(14),a=o(s),c=function(){function t(e,n,o){r(this,t),this.rootStateMachine=e,this.currentStateMachine=n,this.taskScheduler=o}return t.start=function(e){var n=new a.default,o=void 0,r=function(e){return{stateMachine:new t(o,e,n)}};return o=new u.default(e,n,r),n.execute(function(){return o.start()}),new t(o,o,n)},t.prototype.getCurrentState=function(){return this.currentStateMachine.getCurrentState()},t.prototype.getSubmachine=function(){var e=this.currentStateMachine.getSubmachine();return e?new t(this.rootStateMachine,e,this.taskScheduler):null},t.prototype.getStateHierarchy=function(){return this.getStateMachines().map(function(t){return t.getCurrentState()})},t.prototype.canHandle=function(t,e){for(var n=this.getStateMachines(),o=n.length-1;o>=0;o--)if(n[o].canHandle(t,e))return!0;return!1},t.prototype.handle=function(t,e){var n=this;return this.taskScheduler.enqueue(function(){for(var o=n.getStateMachines(),r=o.length-1;r>=0;r--)if(o[r].tryHandle(t,e))return;n.currentStateMachine.handleUnhandledEvent(t,e)}),this},t.prototype.getStateMachines=function(){var t=[],e=this.rootStateMachine;do t.push(e),e=e.getSubmachine();while(e);return t},t.prototype.toString=function(){return"StateMachine(currentState: "+this.getCurrentState()+")"},t}();e.default=c},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0;var r=n(12),i=n(7),u=o(i),s={configure:function(){return new r.StateMachineConfigurator},start:function(t){return u.default.start(t)}};e.default=s},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(4),f=o(c),l=n(5),h=o(l),p=n(7),y=o(p),d=function(t){function e(){r(this,e);var n=i(this,t.call(this));return n.config={global:new f.default(n),initialState:null,states:Object.create(null)},n}return u(e,t),e.prototype.global=function(){return this.config.global},e.prototype.initialState=function(t){return this.config.initialState=t,this.state(t)},e.prototype.state=function(t){return this.config.states[t]||(this.config.states[t]=new h.default(this)),this.config.states[t]},e.prototype.getConfig=function(){return this.buildConfig()},e.prototype.start=function(){var t=this.getConfig();return y.default.start(t)},e}(a.default);e.default=d},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(1),a=o(s),c=function(t){function e(n,o){r(this,e);var u=i(this,t.call(this,n));return u.config.timeout=o,u}return u(e,t),e}(a.default);e.default=c},function(t,e,n){"use strict";function o(t,e){var n=t.prototype,o=e.prototype;Object.getOwnPropertyNames(o).filter(function(t){return!n[t]&&o[t]instanceof Function&&o[t]!==e}).forEach(function(t){n[t]=function(){for(var n=o[t],r=arguments.length,i=Array(r),u=0;u<r;u++)i[u]=arguments[u];return n.apply(this.getAncestor(e),i)}})}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0,e.StateMachineConfigurator=void 0;var r=n(9),i=o(r),u=n(4),s=o(u),a=n(5),c=o(a),f=n(1),l=o(f),h=n(6),p=o(h),y=n(3),d=o(y),g=n(11),b=o(g);e.StateMachineConfigurator=i.default,(0,b.default)(s.default,i.default),(0,b.default)(c.default,i.default),(0,b.default)(p.default,c.default),(0,b.default)(p.default,l.default),(0,b.default)(p.default,d.default)},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=n(15),s=o(u),a=n(2),c=o(a),f=function(){},l=function(){function t(e,n,o){if(r(this,t),void 0===e||null===e)throw new Error("Configuration must be specified.");if("object"!==("undefined"==typeof e?"undefined":i(e)))throw new Error("Configuration must be an object.");if(void 0===e.initialState||null===e.initialState)throw new Error("Initial state must be specified.");this.config=e,this.taskScheduler=n,this.contextFactory=o,this.currentState=null,this.submachines=Object.create(null),this.timerIDs=null,this.asyncActionCancelers=null,this.handleAsyncActionComplete=this.handleAsyncActionComplete.bind(this),this.handleTimeout=this.handleTimeout.bind(this)}return t.prototype.getCurrentState=function(){return this.currentState},t.prototype.canHandle=function(t,e){if(!this.isStarted())return!1;var n=this.createContextWithEvent(t,e);return!!this.getFirstAllowedTransitionForEvent(n)},t.prototype.tryHandle=function(t,e){if(!this.isStarted())return!1;var n=this.createContextWithEvent(t,e),o=this.getFirstAllowedTransitionForEvent(n);return!!o&&(this.executeTransition(o,n),!0)},t.prototype.handleUnhandledEvent=function(t,e){if(!(this.config.global.unhandledEventHooks.length>0))throw new Error("Unhandled event '"+t+"' in state '"+this.currentState+"'.");(0,s.default)(this.config.global.unhandledEventHooks,t,this.currentState,this.createContextWithEvent(t,e))},t.prototype.isStarted=function(){return null!==this.currentState},t.prototype.start=function(){this.isStarted()||this.enterState(this.config.initialState,this.createContext())},t.prototype.stop=function(){this.isStarted()&&(this.exitState(this.createContext()),this.currentState=null)},t.prototype.getSubmachine=function(){return this.isStarted()?this.submachines[this.currentState]:null},t.prototype.executeTransition=function(t,e){if(!t.ignore){t.isInternal||this.exitState(e);var n=null!==t.targetState?t.targetState:this.currentState;(0,s.default)(this.config.global.transitionHooks,this.currentState,n,e),(0,s.default)(t.actions,this.currentState,n,e),t.isInternal||this.enterState(n,e)}},t.prototype.enterState=function(t,e){(0,s.default)(this.config.global.stateEnterHooks,t,e);var n=this.config.states[t];n&&(0,s.default)(n.entryActions,t,e),null!==this.currentState&&this.currentState!==t&&(0,s.default)(this.config.global.stateChangeHooks,this.currentState,t,e);try{this.startAsyncActions(t,e),this.startTimers(t),this.startSubmachines(t)}catch(t){throw this.stopTimers(),this.cancelAsyncActions(),t}this.currentState=t},t.prototype.exitState=function(t){this.stopSubmachines(),this.stopTimers(),this.cancelAsyncActions(),(0,s.default)(this.config.global.stateExitHooks,this.currentState,t);var e=this.config.states[this.currentState];e&&(0,s.default)(e.exitActions,this.currentState,t)},t.prototype.startAsyncActions=function(t,e){var n=this,o=this.config.states[t];o&&o.asyncActions.forEach(function(o){return n.startAsyncAction(o,t,e)})},t.prototype.startAsyncAction=function(t,e,n){var o=t.action,r=t.successTrigger,i=t.failureTrigger,u=this.handleAsyncActionComplete;o(e,n).then(function(t){return u(r,{result:t})},function(t){return u(i,{error:t})}),this.asyncActionCancelers=this.asyncActionCancelers||[],this.asyncActionCancelers.push(function(){u=f})},t.prototype.cancelAsyncActions=function(){this.asyncActionCancelers&&((0,s.default)(this.asyncActionCancelers),this.asyncActionCancelers=null)},t.prototype.handleAsyncActionComplete=function(t,e){var n=(0,c.default)(this.createContext(),e);this.executeTrigger(t,n)},t.prototype.startTimers=function(t){var e=this,n=this.config.states[t];n&&n.timers.length>0&&(this.timerIDs=n.timers.map(function(t){return setTimeout(e.handleTimeout,t.timeout,t)}))},t.prototype.stopTimers=function(){this.timerIDs&&(this.timerIDs.forEach(clearTimeout),this.timerIDs=null)},t.prototype.handleTimeout=function(t){this.executeTrigger(t,this.createContext())},t.prototype.startSubmachines=function(e){var n=this.config.states[e];n&&n.submachine&&(this.submachines[e]||(this.submachines[e]=new t(n.submachine,this.taskScheduler,this.contextFactory)),this.submachines[e].start())},t.prototype.stopSubmachines=function(){var t=this.submachines[this.currentState];t&&t.stop()},t.prototype.createContext=function(){return this.contextFactory(this)},t.prototype.createContextWithEvent=function(t,e){var n=this.createContext();return n.event=t,void 0!==e&&(n.eventPayload=e),n},t.getFirstAllowedTransition=function(t,e){for(var n=0;n<t.length;n++)if(!t[n].condition||t[n].condition(e))return t[n];return null},t.prototype.getFirstAllowedTransitionForEvent=function(e){var n=this.config.states[this.currentState];if(!n)return null;var o=n.events[e.event];return o?t.getFirstAllowedTransition(o.transitions,e):null},t.prototype.executeTrigger=function(e,n){var o=this;this.taskScheduler.execute(function(){var r=t.getFirstAllowedTransition(e.transitions,n);r&&o.executeTransition(r,n)})},t}();e.default=l},function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var r=function(){function t(){o(this,t),this.queue=[],this.isBusy=!1}return t.prototype.enqueue=function(t){this.isBusy?this.queue.push(t):this.execute(t)},t.prototype.execute=function(t){if(this.isBusy)throw new Error("Cannot execute task because another task is already running.");this.isBusy=!0;try{for(t();this.queue.length>0;){var e=this.queue.shift();e()}}finally{this.queue.length>0&&(this.queue=[]),this.isBusy=!1}},t}();e.default=r},function(t,e,n){"use strict";function o(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];t.forEach(function(t){return t.apply(void 0,n)})}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";function o(t,e){var n=Object.getPrototypeOf(t),o=Object.create(n);return Object.keys(t).forEach(function(n){o[n]=e(t[n])}),o}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";var o=n(8).default,r=n(2).default;r(e,o),e.default=o}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Finity=e():t.Finity=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=17)}([function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=n(16),s=o(u),a=function(){function t(e){r(this,t),this.parent=e}return t.prototype.getAncestor=function(t){return this.parent?this.parent instanceof t?this.parent:this.parent.getAncestor(t):null},t.prototype.buildConfig=function(){var e=function e(n){return n?n instanceof t?n.buildConfig():Array.isArray(n)?n.map(e):n&&"object"===("undefined"==typeof n?"undefined":i(n))?(0,s.default)(n,e):n:n};return(0,s.default)(this.config,e)},t}();e.default=a},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(6),f=o(c),l=function(t){function e(n){r(this,e);var o=i(this,t.call(this,n));return o.config={transitions:[]},o}return u(e,t),e.prototype.transitionTo=function(t){return this.transition(t)},e.prototype.selfTransition=function(){return this.transition(null)},e.prototype.internalTransition=function(){return this.transition(null,{isInternal:!0})},e.prototype.ignore=function(){return this.transition(null,{ignore:!0})},e.prototype.transition=function(t,e){var n=new f.default(this,t,e);return this.config.transitions.push(n),n},e}(a.default);e.default=l},function(t,e,n){"use strict";function o(t,e){return Object.keys(e).forEach(function(n){t[n]=e[n]}),t}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(1),f=o(c),l=function(t){function e(n,o){r(this,e);var u=i(this,t.call(this,n));return u.config={action:o,successTrigger:new f.default(u),failureTrigger:new f.default(u)},u}return u(e,t),e.prototype.onSuccess=function(){return this.config.successTrigger},e.prototype.onFailure=function(){return this.config.failureTrigger},e}(a.default);e.default=l},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=function(t){function e(n){r(this,e);var o=i(this,t.call(this,n));return o.config={stateEnterHooks:[],stateExitHooks:[],stateChangeHooks:[],transitionHooks:[],unhandledEventHooks:[]},o}return u(e,t),e.prototype.onStateEnter=function(t){return this.config.stateEnterHooks.push(t),this},e.prototype.onStateExit=function(t){return this.config.stateExitHooks.push(t),this},e.prototype.onStateChange=function(t){return this.config.stateChangeHooks.push(t),this},e.prototype.onTransition=function(t){return this.config.transitionHooks.push(t),this},e.prototype.onUnhandledEvent=function(t){return this.config.unhandledEventHooks.push(t),this},e}(a.default);e.default=c},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(1),f=o(c),l=n(10),h=o(l),p=n(3),y=o(p),d=function(t){function e(n){r(this,e);var o=i(this,t.call(this,n));return o.config={entryActions:[],exitActions:[],events:Object.create(null),anyEventTrigger:null,timers:[],asyncActions:[],submachine:null},o}return u(e,t),e.prototype.onEnter=function(t){return this.config.entryActions.push(t),this},e.prototype.onExit=function(t){return this.config.exitActions.push(t),this},e.prototype.on=function(t){return this.config.events[t]||(this.config.events[t]=new f.default(this)),this.config.events[t]},e.prototype.onAny=function(){return this.config.anyEventTrigger||(this.config.anyEventTrigger=new f.default(this)),this.config.anyEventTrigger},e.prototype.onTimeout=function(t){var e=new h.default(this,t);return this.config.timers.push(e),e},e.prototype.do=function(t){var e=new y.default(this,t);return this.config.asyncActions.push(e),e},e.prototype.submachine=function(t){return this.config.submachine=t,this},e}(a.default);e.default=d},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},a=n(0),c=o(a),f=function(t){function e(n,o){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r(this,e);var a=i(this,t.call(this,n));return a.config=s({targetState:o},u,{actions:[],condition:null}),a}return u(e,t),e.prototype.withAction=function(t){return this.config.actions.push(t),this},e.prototype.withCondition=function(t){return this.config.condition=t,this},e}(c.default);e.default=f},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var i=n(13),u=o(i),s=n(14),a=o(s),c=function(){function t(e,n,o){r(this,t),this.rootStateMachine=e,this.currentStateMachine=n,this.taskScheduler=o}return t.start=function(e){var n=new a.default,o=void 0,r=function(e){return{stateMachine:new t(o,e,n)}};return o=new u.default(e,n,r),n.execute(function(){return o.start()}),new t(o,o,n)},t.prototype.getCurrentState=function(){return this.currentStateMachine.getCurrentState()},t.prototype.getSubmachine=function(){var e=this.currentStateMachine.getSubmachine();return e?new t(this.rootStateMachine,e,this.taskScheduler):null},t.prototype.getStateHierarchy=function(){return this.getStateMachines().map(function(t){return t.getCurrentState()})},t.prototype.canHandle=function(t,e){for(var n=this.getStateMachines(),o=n.length-1;o>=0;o--)if(n[o].canHandle(t,e))return!0;return!1},t.prototype.handle=function(t,e){var n=this;return this.taskScheduler.enqueue(function(){for(var o=n.getStateMachines(),r=o.length-1;r>=0;r--)if(o[r].tryHandle(t,e))return;n.currentStateMachine.handleUnhandledEvent(t,e)}),this},t.prototype.getStateMachines=function(){var t=[],e=this.rootStateMachine;do t.push(e),e=e.getSubmachine();while(e);return t},t.prototype.toString=function(){return"StateMachine(currentState: "+this.getCurrentState()+")"},t}();e.default=c},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0;var r=n(12),i=n(7),u=o(i),s={configure:function(){return new r.StateMachineConfigurator},start:function(t){return u.default.start(t)}};e.default=s},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(0),a=o(s),c=n(4),f=o(c),l=n(5),h=o(l),p=n(7),y=o(p),d=function(t){function e(){r(this,e);var n=i(this,t.call(this));return n.config={global:new f.default(n),initialState:null,states:Object.create(null)},n}return u(e,t),e.prototype.global=function(){return this.config.global},e.prototype.initialState=function(t){return this.config.initialState=t,this.state(t)},e.prototype.state=function(t){return this.config.states[t]||(this.config.states[t]=new h.default(this)),this.config.states[t]},e.prototype.getConfig=function(){return this.buildConfig()},e.prototype.start=function(){var t=this.getConfig();return y.default.start(t)},e}(a.default);e.default=d},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}e.__esModule=!0;var s=n(1),a=o(s),c=function(t){function e(n,o){r(this,e);var u=i(this,t.call(this,n));return u.config.timeout=o,u}return u(e,t),e}(a.default);e.default=c},function(t,e,n){"use strict";function o(t,e){var n=t.prototype,o=e.prototype;Object.getOwnPropertyNames(o).filter(function(t){return!n[t]&&o[t]instanceof Function&&o[t]!==e}).forEach(function(t){n[t]=function(){for(var n=o[t],r=arguments.length,i=Array(r),u=0;u<r;u++)i[u]=arguments[u];return n.apply(this.getAncestor(e),i)}})}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0,e.StateMachineConfigurator=void 0;var r=n(9),i=o(r),u=n(4),s=o(u),a=n(5),c=o(a),f=n(1),l=o(f),h=n(6),p=o(h),y=n(3),d=o(y),g=n(11),b=o(g);e.StateMachineConfigurator=i.default,(0,b.default)(s.default,i.default),(0,b.default)(c.default,i.default),(0,b.default)(p.default,c.default),(0,b.default)(p.default,l.default),(0,b.default)(p.default,d.default)},function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=n(15),s=o(u),a=n(2),c=o(a),f=function(){},l=function(){function t(e,n,o){if(r(this,t),void 0===e||null===e)throw new Error("Configuration must be specified.");if("object"!==("undefined"==typeof e?"undefined":i(e)))throw new Error("Configuration must be an object.");if(void 0===e.initialState||null===e.initialState)throw new Error("Initial state must be specified.");this.config=e,this.taskScheduler=n,this.contextFactory=o,this.currentState=null,this.submachines=Object.create(null),this.timerIDs=null,this.asyncActionCancelers=null,this.handleAsyncActionComplete=this.handleAsyncActionComplete.bind(this),this.handleTimeout=this.handleTimeout.bind(this)}return t.prototype.getCurrentState=function(){return this.currentState},t.prototype.canHandle=function(t,e){if(!this.isStarted())return!1;var n=this.createContextWithEvent(t,e);return!!this.getFirstAllowedTransitionForEvent(n)},t.prototype.tryHandle=function(t,e){if(!this.isStarted())return!1;var n=this.createContextWithEvent(t,e),o=this.getFirstAllowedTransitionForEvent(n);return!!o&&(this.executeTransition(o,n),!0)},t.prototype.handleUnhandledEvent=function(t,e){if(!(this.config.global.unhandledEventHooks.length>0))throw new Error("Unhandled event '"+t+"' in state '"+this.currentState+"'.");(0,s.default)(this.config.global.unhandledEventHooks,t,this.currentState,this.createContextWithEvent(t,e))},t.prototype.isStarted=function(){return null!==this.currentState},t.prototype.start=function(){this.isStarted()||this.enterState(this.config.initialState,this.createContext())},t.prototype.stop=function(){this.isStarted()&&(this.exitState(this.createContext()),this.currentState=null)},t.prototype.getSubmachine=function(){return this.isStarted()?this.submachines[this.currentState]:null},t.prototype.executeTransition=function(t,e){if(!t.ignore){t.isInternal||this.exitState(e);var n=null!==t.targetState?t.targetState:this.currentState;(0,s.default)(this.config.global.transitionHooks,this.currentState,n,e),(0,s.default)(t.actions,this.currentState,n,e),t.isInternal||this.enterState(n,e)}},t.prototype.enterState=function(t,e){(0,s.default)(this.config.global.stateEnterHooks,t,e);var n=this.config.states[t];n&&(0,s.default)(n.entryActions,t,e),null!==this.currentState&&this.currentState!==t&&(0,s.default)(this.config.global.stateChangeHooks,this.currentState,t,e);try{this.startAsyncActions(t,e),this.startTimers(t),this.startSubmachines(t)}catch(t){throw this.stopTimers(),this.cancelAsyncActions(),t}this.currentState=t},t.prototype.exitState=function(t){this.stopSubmachines(),this.stopTimers(),this.cancelAsyncActions(),(0,s.default)(this.config.global.stateExitHooks,this.currentState,t);var e=this.config.states[this.currentState];e&&(0,s.default)(e.exitActions,this.currentState,t)},t.prototype.startAsyncActions=function(t,e){var n=this,o=this.config.states[t];o&&o.asyncActions.forEach(function(o){return n.startAsyncAction(o,t,e)})},t.prototype.startAsyncAction=function(t,e,n){var o=t.action,r=t.successTrigger,i=t.failureTrigger,u=this.handleAsyncActionComplete;o(e,n).then(function(t){return u(r,{result:t})},function(t){return u(i,{error:t})}),this.asyncActionCancelers=this.asyncActionCancelers||[],this.asyncActionCancelers.push(function(){u=f})},t.prototype.cancelAsyncActions=function(){this.asyncActionCancelers&&((0,s.default)(this.asyncActionCancelers),this.asyncActionCancelers=null)},t.prototype.handleAsyncActionComplete=function(t,e){var n=(0,c.default)(this.createContext(),e);this.executeTrigger(t,n)},t.prototype.startTimers=function(t){var e=this,n=this.config.states[t];n&&n.timers.length>0&&(this.timerIDs=n.timers.map(function(t){return setTimeout(e.handleTimeout,t.timeout,t)}))},t.prototype.stopTimers=function(){this.timerIDs&&(this.timerIDs.forEach(clearTimeout),this.timerIDs=null)},t.prototype.handleTimeout=function(t){this.executeTrigger(t,this.createContext())},t.prototype.startSubmachines=function(e){var n=this.config.states[e];n&&n.submachine&&(this.submachines[e]||(this.submachines[e]=new t(n.submachine,this.taskScheduler,this.contextFactory)),this.submachines[e].start())},t.prototype.stopSubmachines=function(){var t=this.submachines[this.currentState];t&&t.stop()},t.prototype.createContext=function(){return this.contextFactory(this)},t.prototype.createContextWithEvent=function(t,e){var n=this.createContext();return n.event=t,void 0!==e&&(n.eventPayload=e),n},t.getFirstAllowedTransition=function(t,e){for(var n=0;n<t.length;n++)if(!t[n].condition||t[n].condition(e))return t[n];return null},t.prototype.getFirstAllowedTransitionForEvent=function(e){var n=this.config.states[this.currentState];if(!n)return null;var o=null,r=n.events[e.event];return r&&(o=t.getFirstAllowedTransition(r.transitions,e)),!o&&n.anyEventTrigger&&(o=t.getFirstAllowedTransition(n.anyEventTrigger.transitions,e)),o},t.prototype.executeTrigger=function(e,n){var o=this;this.taskScheduler.execute(function(){var r=t.getFirstAllowedTransition(e.transitions,n);r&&o.executeTransition(r,n)})},t}();e.default=l},function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var r=function(){function t(){o(this,t),this.queue=[],this.isBusy=!1}return t.prototype.enqueue=function(t){this.isBusy?this.queue.push(t):this.execute(t)},t.prototype.execute=function(t){if(this.isBusy)throw new Error("Cannot execute task because another task is already running.");this.isBusy=!0;try{for(t();this.queue.length>0;){var e=this.queue.shift();e()}}finally{this.queue.length>0&&(this.queue=[]),this.isBusy=!1}},t}();e.default=r},function(t,e,n){"use strict";function o(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];t.forEach(function(t){return t.apply(void 0,n)})}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";function o(t,e){var n=Object.getPrototypeOf(t),o=Object.create(n);return Object.keys(t).forEach(function(n){o[n]=e(t[n])}),o}e.__esModule=!0,e.default=o},function(t,e,n){"use strict";var o=n(8).default,r=n(2).default;r(e,o),e.default=o}])}); |
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
127401
1733
548