Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

finity

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

finity - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

8

lib/configuration/AsyncActionConfigurator.js

@@ -56,7 +56,7 @@ 'use strict';

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
var config = (0, _deepCopy2.default)(this.config);
config.onSuccess = this.successConfigurator.getConfig();
config.onFailure = this.failureConfigurator.getConfig();
config.onSuccess = this.successConfigurator.internalGetConfig();
config.onFailure = this.failureConfigurator.internalGetConfig();
return config;

@@ -63,0 +63,0 @@ }

@@ -31,8 +31,8 @@ 'use strict';

var getConfig = function getConfig(configurator) {
return configurator.getConfig();
var internalGetConfig = function internalGetConfig(configurator) {
return configurator.internalGetConfig();
};
function mapToConfig(configurators) {
return Array.isArray(configurators) ? configurators.map(getConfig) : (0, _mapValues2.default)(configurators, getConfig);
return Array.isArray(configurators) ? configurators.map(internalGetConfig) : (0, _mapValues2.default)(configurators, internalGetConfig);
}

@@ -74,4 +74,4 @@ 'use strict';

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
return (0, _deepCopy2.default)(this.config);

@@ -78,0 +78,0 @@ }

@@ -92,4 +92,4 @@ 'use strict';

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
var config = (0, _deepCopy2.default)(this.config);

@@ -96,0 +96,0 @@ config.events = (0, _ConfiguratorHelper.mapToConfig)(this.eventConfigurators);

@@ -83,3 +83,3 @@ 'use strict';

config.states = (0, _ConfiguratorHelper.mapToConfig)(this.stateConfigurators);
return (0, _merge2.default)(config, this.globalConfigurator.getConfig());
return (0, _merge2.default)(config, this.globalConfigurator.internalGetConfig());
}

@@ -86,0 +86,0 @@ }, {

@@ -42,5 +42,5 @@ 'use strict';

_createClass(TrimerConfigurator, [{
key: 'getConfig',
value: function getConfig() {
return (0, _merge2.default)(_get(Object.getPrototypeOf(TrimerConfigurator.prototype), 'getConfig', this).call(this), this.config);
key: 'internalGetConfig',
value: function internalGetConfig() {
return (0, _merge2.default)(_get(Object.getPrototypeOf(TrimerConfigurator.prototype), 'internalGetConfig', this).call(this), this.config);
}

@@ -47,0 +47,0 @@ }]);

@@ -55,4 +55,4 @@ 'use strict';

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
return (0, _deepCopy2.default)(this.config);

@@ -59,0 +59,0 @@ }

@@ -62,4 +62,4 @@ 'use strict';

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
return {

@@ -66,0 +66,0 @@ transitions: (0, _ConfiguratorHelper.mapToConfig)(this.transitionConfigurators)

{
"name": "finity",
"version": "0.4.3",
"description": "A finite state machine library for Node.js and the browser with a friendly configuration DSL",
"keywords": [
"state",
"machine",
"state machine",
"finite state machine",
"fsm"
],
"bugs": {
"url": "https://github.com/nickuraltsev/finity/issues"
},
"license": "MIT",
"author": {
"name": "Nick Uraltsev",
"email": "nick.uraltsev@gmail.com"
},
"files": [
"*.md",
"lib",
"umd",
"index.d.ts"
],
"main": "lib/index.js",
"typings": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/nickuraltsev/finity.git"
},
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-register": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"babel-loader": "^6.2.4",
"jasmine": "^2.4.1",
"jasmine-spec-reporter": "^2.4.0",
"eslint": "^2.10.2",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-react": "^5.1.1",
"eslint-plugin-jsx-a11y": "^1.2.0",
"babel-eslint": "^6.0.4",
"isparta": "^4.0.0",
"coveralls": "^2.11.9",
"rimraf": "^2.5.2",
"webpack": "^1.13.1",
"cross-env": "^1.0.8",
"typings": "^1.0.4",
"typescript": "^1.8.10"
},
"scripts": {
"clean": "rimraf lib && rimraf umd",
"build:commonjs": "babel src --out-dir lib",
"build:umd": "cross-env NODE_ENV=development webpack src/index.js umd/Finity.js",
"build:umd:min": "cross-env NODE_ENV=production webpack -p src/index.js umd/Finity.min.js",
"build": "npm run clean && npm run build:commonjs && npm run build:umd && npm run build:umd:min",
"test:typings": "typings install && tsc",
"test": "babel-node test/support/jasmineRunner && npm run test:typings",
"coverage": "babel-node node_modules/isparta/bin/isparta cover --root src --report lcovonly test/support/jasmineRunner.js",
"lint": "eslint src test examples"
}
"name": "finity",
"version": "0.4.4",
"description": "A finite state machine library for Node.js and the browser with a friendly configuration DSL",
"keywords": [
"state",
"machine",
"state machine",
"finite state machine",
"fsm"
],
"author": {
"name": "Nick Uraltsev",
"email": "nick.uraltsev@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/nickuraltsev/finity.git"
},
"bugs": {
"url": "https://github.com/nickuraltsev/finity/issues"
},
"license": "MIT",
"files": [
"*.md",
"lib",
"umd",
"index.d.ts"
],
"main": "lib/index.js",
"typings": "index.d.ts",
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-register": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"babel-loader": "^6.2.4",
"jasmine": "^2.4.1",
"jasmine-spec-reporter": "^2.4.0",
"eslint": "^2.10.2",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-react": "^5.1.1",
"eslint-plugin-jsx-a11y": "^1.2.0",
"babel-eslint": "^6.0.4",
"isparta": "^4.0.0",
"coveralls": "^2.11.9",
"rimraf": "^2.5.2",
"webpack": "^1.13.1",
"cross-env": "^1.0.8",
"typings": "^1.0.4",
"typescript": "^1.8.10"
},
"scripts": {
"clean": "rimraf lib && rimraf umd",
"build:commonjs": "babel src --out-dir lib",
"build:umd": "cross-env NODE_ENV=development webpack src/index.js umd/Finity.js",
"build:umd:min": "cross-env NODE_ENV=production webpack -p src/index.js umd/Finity.min.js",
"build": "npm run clean && npm run build:commonjs && npm run build:umd && npm run build:umd:min",
"test:typings": "typings install && tsc",
"test": "babel-node test/support/jasmineRunner && npm run test:typings",
"coverage": "babel-node node_modules/isparta/bin/isparta cover --root src --report lcovonly test/support/jasmineRunner.js",
"lint": "eslint src test examples"
}
}

@@ -189,8 +189,8 @@ (function webpackUniversalModuleDefinition(root, factory) {

var getConfig = function getConfig(configurator) {
return configurator.getConfig();
var internalGetConfig = function internalGetConfig(configurator) {
return configurator.internalGetConfig();
};
function mapToConfig(configurators) {
return Array.isArray(configurators) ? configurators.map(getConfig) : (0, _mapValues2.default)(configurators, getConfig);
return Array.isArray(configurators) ? configurators.map(internalGetConfig) : (0, _mapValues2.default)(configurators, internalGetConfig);
}

@@ -263,4 +263,4 @@

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
return {

@@ -336,7 +336,7 @@ transitions: (0, _ConfiguratorHelper.mapToConfig)(this.transitionConfigurators)

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
var config = (0, _deepCopy2.default)(this.config);
config.onSuccess = this.successConfigurator.getConfig();
config.onFailure = this.failureConfigurator.getConfig();
config.onSuccess = this.successConfigurator.internalGetConfig();
config.onFailure = this.failureConfigurator.internalGetConfig();
return config;

@@ -428,4 +428,4 @@ }

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
return (0, _deepCopy2.default)(this.config);

@@ -535,4 +535,4 @@ }

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
var config = (0, _deepCopy2.default)(this.config);

@@ -637,3 +637,3 @@ config.events = (0, _ConfiguratorHelper.mapToConfig)(this.eventConfigurators);

config.states = (0, _ConfiguratorHelper.mapToConfig)(this.stateConfigurators);
return (0, _merge2.default)(config, this.globalConfigurator.getConfig());
return (0, _merge2.default)(config, this.globalConfigurator.internalGetConfig());
}

@@ -711,4 +711,4 @@ }, {

}, {
key: 'getConfig',
value: function getConfig() {
key: 'internalGetConfig',
value: function internalGetConfig() {
return (0, _deepCopy2.default)(this.config);

@@ -1127,5 +1127,5 @@ }

_createClass(TrimerConfigurator, [{
key: 'getConfig',
value: function getConfig() {
return (0, _merge2.default)(_get(Object.getPrototypeOf(TrimerConfigurator.prototype), 'getConfig', this).call(this), this.config);
key: 'internalGetConfig',
value: function internalGetConfig() {
return (0, _merge2.default)(_get(Object.getPrototypeOf(TrimerConfigurator.prototype), 'internalGetConfig', this).call(this), this.config);
}

@@ -1132,0 +1132,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(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(){return new u.StateMachineConfigurator}function i(t){return s["default"].start(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.configure=o,e.start=i;var u=n(14),a=n(10),s=r(a);e["default"]={configure:o,start:i}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=function(){function t(e){n(this,t),this.parent=e}return r(t,[{key:"getAncestor",value:function(t){return this.parent?this.parent instanceof t?this.parent:this.parent.getAncestor(t):null}}]),t}();e["default"]=o},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return t?Array.isArray(t)?t.map(o):"object"===("undefined"==typeof t?"undefined":i(t))?(0,a["default"])(t,o):t:t}Object.defineProperty(e,"__esModule",{value:!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?"symbol":typeof t};e["default"]=o;var u=n(11),a=r(u)},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){Object.getOwnPropertyNames(e.prototype).filter(function(n){return!t.prototype[n]&&e.prototype[n]instanceof Function&&e.prototype[n]!==e.prototype.constructor}).forEach(function(n){t.prototype[n]=function(){for(var t=e.prototype[n],r=arguments.length,o=Array(r),i=0;r>i;i++)o[i]=arguments[i];return t.apply(this.getAncestor(e),o)}})}function i(t){return Array.isArray(t)?t.map(s):(0,a["default"])(t,s)}Object.defineProperty(e,"__esModule",{value:!0}),e.delegateToAncestor=o,e.mapToConfig=i;var u=n(11),a=r(u),s=function(t){return t.getConfig()}},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(9),l=r(f),h=n(3),y=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t));return n.transitionConfigurators=[],n}return u(e,t),a(e,[{key:"transitionTo",value:function(t){return this.transition(t)}},{key:"selfTransition",value:function(){return this.transition(null)}},{key:"internalTransition",value:function(){return this.transition(null,!0)}},{key:"transition",value:function(t,e){var n=new l["default"](this,t,e);return this.transitionConfigurators.push(n),n}},{key:"getConfig",value:function(){return{transitions:(0,h.mapToConfig)(this.transitionConfigurators)}}}]),e}(c["default"]);e["default"]=y},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(4),l=r(f),h=n(2),y=r(h),p=function(t){function e(t,n){o(this,e);var r=i(this,Object.getPrototypeOf(e).call(this,t));return r.config={action:n},r.successConfigurator=new l["default"](r),r.failureConfigurator=new l["default"](r),r}return u(e,t),a(e,[{key:"onSuccess",value:function(){return this.successConfigurator}},{key:"onFailure",value:function(){return this.failureConfigurator}},{key:"getConfig",value:function(){var t=(0,y["default"])(this.config);return t.onSuccess=this.successConfigurator.getConfig(),t.onFailure=this.failureConfigurator.getConfig(),t}}]),e}(c["default"]);e["default"]=p},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(2),l=r(f),h=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t));return n.config={stateEnterHooks:[],stateExitHooks:[],stateChangeHooks:[],transitionHooks:[],unhandledEventHooks:[]},n}return u(e,t),a(e,[{key:"onStateEnter",value:function(t){return this.config.stateEnterHooks.push(t),this}},{key:"onStateExit",value:function(t){return this.config.stateExitHooks.push(t),this}},{key:"onStateChange",value:function(t){return this.config.stateChangeHooks.push(t),this}},{key:"onTransition",value:function(t){return this.config.transitionHooks.push(t),this}},{key:"onUnhandledEvent",value:function(t){return this.config.unhandledEventHooks.push(t),this}},{key:"getConfig",value:function(){return(0,l["default"])(this.config)}}]),e}(c["default"]);e["default"]=h},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(4),l=r(f),h=n(13),y=r(h),p=n(5),d=r(p),v=n(3),b=n(2),g=r(b),O=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t));return n.config={entryActions:[],exitActions:[]},n.eventConfigurators=Object.create(null),n.timerConfigurators=[],n.asyncActionConfigurators=[],n}return u(e,t),a(e,[{key:"onEnter",value:function(t){return this.config.entryActions.push(t),this}},{key:"onExit",value:function(t){return this.config.exitActions.push(t),this}},{key:"on",value:function(t){return this.eventConfigurators[t]||(this.eventConfigurators[t]=new l["default"](this)),this.eventConfigurators[t]}},{key:"onTimeout",value:function(t){var e=new y["default"](this,t);return this.timerConfigurators.push(e),e}},{key:"do",value:function(t){var e=new d["default"](this,t);return this.asyncActionConfigurators.push(e),e}},{key:"getConfig",value:function(){var t=(0,g["default"])(this.config);return t.events=(0,v.mapToConfig)(this.eventConfigurators),t.timers=(0,v.mapToConfig)(this.timerConfigurators),t.asyncActions=(0,v.mapToConfig)(this.asyncActionConfigurators),t}}]),e}(c["default"]);e["default"]=O},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(6),l=r(f),h=n(7),y=r(h),p=n(10),d=r(p),v=n(3),b=n(2),g=r(b),O=n(12),w=r(O),_=function(t){function e(){o(this,e);var t=i(this,Object.getPrototypeOf(e).call(this));return t.config={initialState:null},t.globalConfigurator=new l["default"](t),t.stateConfigurators=Object.create(null),t}return u(e,t),a(e,[{key:"global",value:function(){return this.globalConfigurator}},{key:"initialState",value:function(t){return this.config.initialState=t,this.state(t)}},{key:"state",value:function(t){return this.stateConfigurators[t]||(this.stateConfigurators[t]=new y["default"](this)),this.stateConfigurators[t]}},{key:"getConfig",value:function(){var t=(0,g["default"])(this.config);return t.states=(0,v.mapToConfig)(this.stateConfigurators),(0,w["default"])(t,this.globalConfigurator.getConfig())}},{key:"start",value:function(){var t=this.getConfig();return d["default"].start(t)}}]),e}(c["default"]);e["default"]=_},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(2),l=r(f),h=function(t){function e(t,n,r){o(this,e);var u=i(this,Object.getPrototypeOf(e).call(this,t));return u.config={targetState:n,isInternal:null===n&&r,actions:[],condition:null},u}return u(e,t),a(e,[{key:"withAction",value:function(t){return this.config.actions.push(t),this}},{key:"withCondition",value:function(t){return this.config.condition=t,this}},{key:"getConfig",value:function(){return(0,l["default"])(this.config)}}]),e}(c["default"]);e["default"]=h},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!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?"symbol":typeof t},u=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),a=n(16),s=r(a),c=n(17),f=r(c),l=function(){function t(e){if(o(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.currentState=null,this.isBusy=!1,this.eventQueue=[],this.timerIDs=null,this.asyncActionSubscriptions=null,this.handleTimeout=this.handleTimeout.bind(this)}return u(t,[{key:"start",value:function(){var t=this;return this.isStarted()||this.execute(function(){return t.enterState(t.config.initialState,t.createContext())}),this}},{key:"isStarted",value:function(){return null!==this.currentState}},{key:"getCurrentState",value:function(){return this.currentState}},{key:"canHandle",value:function(t,e){if(!this.isStarted())return!1;var n=this.createContext(t,e);return!!this.getTransitionForEvent(n)}},{key:"handle",value:function(t,e){var n=this;return this.isBusy?this.eventQueue.push({event:t,eventPayload:e}):this.execute(function(){return n.processEvent(t,e)}),this}},{key:"execute",value:function(t){if(this.isBusy)throw new Error("Operation cannot be executed because another operation is in progress.");this.isBusy=!0;try{for(t();this.eventQueue.length>0;){var e=this.eventQueue.shift(),n=e.event,r=e.eventPayload;this.processEvent(n,r)}}finally{this.eventQueue.length>0&&(this.eventQueue=[]),this.isBusy=!1}}},{key:"processEvent",value:function(t,e){var n=this.createContext(t,e),r=this.getTransitionForEvent(n);r?this.executeTransition(r,n):this.handleUnhandledEvent(n)}},{key:"createContext",value:function(t,e){var n={stateMachine:this};return void 0!==t&&(n.event=t),void 0!==e&&(n.eventPayload=e),n}},{key:"getTransitionForEvent",value:function(t){var e=this.config.states[this.currentState];if(!e)return null;var n=e.events[t.event];return n?this.selectTransition(n.transitions,t):null}},{key:"executeTransition",value:function(t,e){t.isInternal||this.exitState(e);var n=null!==t.targetState?t.targetState:this.currentState;(0,f["default"])(this.config.transitionHooks,this.currentState,n,e),(0,f["default"])(t.actions,this.currentState,n,e),t.isInternal||this.enterState(n,e)}},{key:"handleUnhandledEvent",value:function(t){if(!(this.config.unhandledEventHooks.length>0))throw new Error("Unhandled event '"+t.event+"' in state '"+this.currentState+"'.");(0,f["default"])(this.config.unhandledEventHooks,t.event,this.currentState,t)}},{key:"enterState",value:function(t,e){(0,f["default"])(this.config.stateEnterHooks,t,e);var n=this.config.states[t];n&&(0,f["default"])(n.entryActions,t,e),null!==this.currentState&&this.currentState!==t&&(0,f["default"])(this.config.stateChangeHooks,this.currentState,t,e),this.currentState=t,this.startAsyncActions(e),this.startTimers()}},{key:"exitState",value:function(t){this.stopTimers(),this.cancelAsyncActionSubscriptions(),(0,f["default"])(this.config.stateExitHooks,this.currentState,t);var e=this.config.states[this.currentState];e&&(0,f["default"])(e.exitActions,this.currentState,t)}},{key:"startAsyncActions",value:function(t){var e=this,n=this.config.states[this.currentState];n&&n.asyncActions.forEach(function(n){return e.startAsyncAction(n,t)})}},{key:"startAsyncAction",value:function(t,e){var n=this,r=t.action,o=new s["default"](function(e){return n.handleAsyncActionSuccess(t.onSuccess,e)},function(e){return n.handleAsyncActionFailure(t.onFailure,e)});r(this.currentState,e).then(o.onSuccess,o.onFailure),this.asyncActionSubscriptions=this.asyncActionSubscriptions||[],this.asyncActionSubscriptions.push(o)}},{key:"cancelAsyncActionSubscriptions",value:function(){this.asyncActionSubscriptions&&(this.asyncActionSubscriptions.forEach(function(t){return t.cancel()}),this.asyncActionSubscriptions=null)}},{key:"handleAsyncActionSuccess",value:function(t,e){var n=this.createContext();n.result=e,this.executeTrigger(t,n)}},{key:"handleAsyncActionFailure",value:function(t,e){var n=this.createContext();n.error=e,this.executeTrigger(t,n)}},{key:"startTimers",value:function(){var t=this,e=this.config.states[this.currentState];e&&e.timers.length>0&&(this.timerIDs=e.timers.map(function(e){return setTimeout(t.handleTimeout,e.timeout,e)}))}},{key:"stopTimers",value:function(){this.timerIDs&&(this.timerIDs.forEach(clearTimeout),this.timerIDs=null)}},{key:"handleTimeout",value:function(t){this.executeTrigger(t,this.createContext())}},{key:"executeTrigger",value:function(t,e){var n=this;this.execute(function(){var r=n.selectTransition(t.transitions,e);r&&n.executeTransition(r,e)})}},{key:"selectTransition",value:function(t,e){return t.find(function(t){return!t.condition||t.condition(e)})}}],[{key:"start",value:function(e){return new t(e).start()}}]),t}();e["default"]=l},function(t,e){"use strict";function n(t,e){var n=Object.getPrototypeOf(t),r=Object.create(n);return Object.keys(t).forEach(function(n){r[n]=e(t[n])}),r}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e){"use strict";function n(t,e){return Object.keys(e).forEach(function(n){t[n]=e[n]}),t}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=function p(t,e,n){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,e);if(void 0===r){var o=Object.getPrototypeOf(t);return null===o?void 0:p(o,e,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)},c=n(4),f=r(c),l=n(12),h=r(l),y=function(t){function e(t,n){o(this,e);var r=i(this,Object.getPrototypeOf(e).call(this,t));return r.config={timeout:n},r}return u(e,t),a(e,[{key:"getConfig",value:function(){return(0,h["default"])(s(Object.getPrototypeOf(e.prototype),"getConfig",this).call(this),this.config)}}]),e}(f["default"]);e["default"]=y},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0}),e.StateMachineConfigurator=void 0;var o=n(8),i=r(o),u=n(15),a=r(u);e.StateMachineConfigurator=i["default"],(0,a["default"])()},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(){(0,b.delegateToAncestor)(s["default"],u["default"]),(0,b.delegateToAncestor)(f["default"],u["default"]),(0,b.delegateToAncestor)(p["default"],f["default"]),(0,b.delegateToAncestor)(p["default"],h["default"]),(0,b.delegateToAncestor)(p["default"],v["default"])}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=n(8),u=r(i),a=n(6),s=r(a),c=n(7),f=r(c),l=n(4),h=r(l),y=n(9),p=r(y),d=n(5),v=r(d),b=n(3)},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=function(){function t(e,r){n(this,t),this.successListener=e,this.failureListener=r,this.onSuccess=this.onSuccess.bind(this),this.onFailure=this.onFailure.bind(this)}return r(t,[{key:"onSuccess",value:function(t){this.successListener&&this.successListener(t)}},{key:"onFailure",value:function(t){this.failureListener&&this.failureListener(t)}},{key:"cancel",value:function(){this.successListener=null,this.failureListener=null}}]),t}();e["default"]=o},function(t,e){"use strict";function n(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];t.forEach(function(t){return t.apply(void 0,n)})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n}])});
!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(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(){return new u.StateMachineConfigurator}function i(t){return s["default"].start(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.configure=o,e.start=i;var u=n(14),a=n(10),s=r(a);e["default"]={configure:o,start:i}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=function(){function t(e){n(this,t),this.parent=e}return r(t,[{key:"getAncestor",value:function(t){return this.parent?this.parent instanceof t?this.parent:this.parent.getAncestor(t):null}}]),t}();e["default"]=o},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return t?Array.isArray(t)?t.map(o):"object"===("undefined"==typeof t?"undefined":i(t))?(0,a["default"])(t,o):t:t}Object.defineProperty(e,"__esModule",{value:!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?"symbol":typeof t};e["default"]=o;var u=n(11),a=r(u)},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){Object.getOwnPropertyNames(e.prototype).filter(function(n){return!t.prototype[n]&&e.prototype[n]instanceof Function&&e.prototype[n]!==e.prototype.constructor}).forEach(function(n){t.prototype[n]=function(){for(var t=e.prototype[n],r=arguments.length,o=Array(r),i=0;r>i;i++)o[i]=arguments[i];return t.apply(this.getAncestor(e),o)}})}function i(t){return Array.isArray(t)?t.map(s):(0,a["default"])(t,s)}Object.defineProperty(e,"__esModule",{value:!0}),e.delegateToAncestor=o,e.mapToConfig=i;var u=n(11),a=r(u),s=function(t){return t.internalGetConfig()}},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(9),l=r(f),h=n(3),y=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t));return n.transitionConfigurators=[],n}return u(e,t),a(e,[{key:"transitionTo",value:function(t){return this.transition(t)}},{key:"selfTransition",value:function(){return this.transition(null)}},{key:"internalTransition",value:function(){return this.transition(null,!0)}},{key:"transition",value:function(t,e){var n=new l["default"](this,t,e);return this.transitionConfigurators.push(n),n}},{key:"internalGetConfig",value:function(){return{transitions:(0,h.mapToConfig)(this.transitionConfigurators)}}}]),e}(c["default"]);e["default"]=y},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(4),l=r(f),h=n(2),y=r(h),p=function(t){function e(t,n){o(this,e);var r=i(this,Object.getPrototypeOf(e).call(this,t));return r.config={action:n},r.successConfigurator=new l["default"](r),r.failureConfigurator=new l["default"](r),r}return u(e,t),a(e,[{key:"onSuccess",value:function(){return this.successConfigurator}},{key:"onFailure",value:function(){return this.failureConfigurator}},{key:"internalGetConfig",value:function(){var t=(0,y["default"])(this.config);return t.onSuccess=this.successConfigurator.internalGetConfig(),t.onFailure=this.failureConfigurator.internalGetConfig(),t}}]),e}(c["default"]);e["default"]=p},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(2),l=r(f),h=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t));return n.config={stateEnterHooks:[],stateExitHooks:[],stateChangeHooks:[],transitionHooks:[],unhandledEventHooks:[]},n}return u(e,t),a(e,[{key:"onStateEnter",value:function(t){return this.config.stateEnterHooks.push(t),this}},{key:"onStateExit",value:function(t){return this.config.stateExitHooks.push(t),this}},{key:"onStateChange",value:function(t){return this.config.stateChangeHooks.push(t),this}},{key:"onTransition",value:function(t){return this.config.transitionHooks.push(t),this}},{key:"onUnhandledEvent",value:function(t){return this.config.unhandledEventHooks.push(t),this}},{key:"internalGetConfig",value:function(){return(0,l["default"])(this.config)}}]),e}(c["default"]);e["default"]=h},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(4),l=r(f),h=n(13),y=r(h),p=n(5),d=r(p),v=n(3),b=n(2),g=r(b),O=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t));return n.config={entryActions:[],exitActions:[]},n.eventConfigurators=Object.create(null),n.timerConfigurators=[],n.asyncActionConfigurators=[],n}return u(e,t),a(e,[{key:"onEnter",value:function(t){return this.config.entryActions.push(t),this}},{key:"onExit",value:function(t){return this.config.exitActions.push(t),this}},{key:"on",value:function(t){return this.eventConfigurators[t]||(this.eventConfigurators[t]=new l["default"](this)),this.eventConfigurators[t]}},{key:"onTimeout",value:function(t){var e=new y["default"](this,t);return this.timerConfigurators.push(e),e}},{key:"do",value:function(t){var e=new d["default"](this,t);return this.asyncActionConfigurators.push(e),e}},{key:"internalGetConfig",value:function(){var t=(0,g["default"])(this.config);return t.events=(0,v.mapToConfig)(this.eventConfigurators),t.timers=(0,v.mapToConfig)(this.timerConfigurators),t.asyncActions=(0,v.mapToConfig)(this.asyncActionConfigurators),t}}]),e}(c["default"]);e["default"]=O},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(6),l=r(f),h=n(7),y=r(h),p=n(10),d=r(p),v=n(3),b=n(2),g=r(b),O=n(12),w=r(O),_=function(t){function e(){o(this,e);var t=i(this,Object.getPrototypeOf(e).call(this));return t.config={initialState:null},t.globalConfigurator=new l["default"](t),t.stateConfigurators=Object.create(null),t}return u(e,t),a(e,[{key:"global",value:function(){return this.globalConfigurator}},{key:"initialState",value:function(t){return this.config.initialState=t,this.state(t)}},{key:"state",value:function(t){return this.stateConfigurators[t]||(this.stateConfigurators[t]=new y["default"](this)),this.stateConfigurators[t]}},{key:"getConfig",value:function(){var t=(0,g["default"])(this.config);return t.states=(0,v.mapToConfig)(this.stateConfigurators),(0,w["default"])(t,this.globalConfigurator.internalGetConfig())}},{key:"start",value:function(){var t=this.getConfig();return d["default"].start(t)}}]),e}(c["default"]);e["default"]=_},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=r(s),f=n(2),l=r(f),h=function(t){function e(t,n,r){o(this,e);var u=i(this,Object.getPrototypeOf(e).call(this,t));return u.config={targetState:n,isInternal:null===n&&r,actions:[],condition:null},u}return u(e,t),a(e,[{key:"withAction",value:function(t){return this.config.actions.push(t),this}},{key:"withCondition",value:function(t){return this.config.condition=t,this}},{key:"internalGetConfig",value:function(){return(0,l["default"])(this.config)}}]),e}(c["default"]);e["default"]=h},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!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?"symbol":typeof t},u=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),a=n(16),s=r(a),c=n(17),f=r(c),l=function(){function t(e){if(o(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.currentState=null,this.isBusy=!1,this.eventQueue=[],this.timerIDs=null,this.asyncActionSubscriptions=null,this.handleTimeout=this.handleTimeout.bind(this)}return u(t,[{key:"start",value:function(){var t=this;return this.isStarted()||this.execute(function(){return t.enterState(t.config.initialState,t.createContext())}),this}},{key:"isStarted",value:function(){return null!==this.currentState}},{key:"getCurrentState",value:function(){return this.currentState}},{key:"canHandle",value:function(t,e){if(!this.isStarted())return!1;var n=this.createContext(t,e);return!!this.getTransitionForEvent(n)}},{key:"handle",value:function(t,e){var n=this;return this.isBusy?this.eventQueue.push({event:t,eventPayload:e}):this.execute(function(){return n.processEvent(t,e)}),this}},{key:"execute",value:function(t){if(this.isBusy)throw new Error("Operation cannot be executed because another operation is in progress.");this.isBusy=!0;try{for(t();this.eventQueue.length>0;){var e=this.eventQueue.shift(),n=e.event,r=e.eventPayload;this.processEvent(n,r)}}finally{this.eventQueue.length>0&&(this.eventQueue=[]),this.isBusy=!1}}},{key:"processEvent",value:function(t,e){var n=this.createContext(t,e),r=this.getTransitionForEvent(n);r?this.executeTransition(r,n):this.handleUnhandledEvent(n)}},{key:"createContext",value:function(t,e){var n={stateMachine:this};return void 0!==t&&(n.event=t),void 0!==e&&(n.eventPayload=e),n}},{key:"getTransitionForEvent",value:function(t){var e=this.config.states[this.currentState];if(!e)return null;var n=e.events[t.event];return n?this.selectTransition(n.transitions,t):null}},{key:"executeTransition",value:function(t,e){t.isInternal||this.exitState(e);var n=null!==t.targetState?t.targetState:this.currentState;(0,f["default"])(this.config.transitionHooks,this.currentState,n,e),(0,f["default"])(t.actions,this.currentState,n,e),t.isInternal||this.enterState(n,e)}},{key:"handleUnhandledEvent",value:function(t){if(!(this.config.unhandledEventHooks.length>0))throw new Error("Unhandled event '"+t.event+"' in state '"+this.currentState+"'.");(0,f["default"])(this.config.unhandledEventHooks,t.event,this.currentState,t)}},{key:"enterState",value:function(t,e){(0,f["default"])(this.config.stateEnterHooks,t,e);var n=this.config.states[t];n&&(0,f["default"])(n.entryActions,t,e),null!==this.currentState&&this.currentState!==t&&(0,f["default"])(this.config.stateChangeHooks,this.currentState,t,e),this.currentState=t,this.startAsyncActions(e),this.startTimers()}},{key:"exitState",value:function(t){this.stopTimers(),this.cancelAsyncActionSubscriptions(),(0,f["default"])(this.config.stateExitHooks,this.currentState,t);var e=this.config.states[this.currentState];e&&(0,f["default"])(e.exitActions,this.currentState,t)}},{key:"startAsyncActions",value:function(t){var e=this,n=this.config.states[this.currentState];n&&n.asyncActions.forEach(function(n){return e.startAsyncAction(n,t)})}},{key:"startAsyncAction",value:function(t,e){var n=this,r=t.action,o=new s["default"](function(e){return n.handleAsyncActionSuccess(t.onSuccess,e)},function(e){return n.handleAsyncActionFailure(t.onFailure,e)});r(this.currentState,e).then(o.onSuccess,o.onFailure),this.asyncActionSubscriptions=this.asyncActionSubscriptions||[],this.asyncActionSubscriptions.push(o)}},{key:"cancelAsyncActionSubscriptions",value:function(){this.asyncActionSubscriptions&&(this.asyncActionSubscriptions.forEach(function(t){return t.cancel()}),this.asyncActionSubscriptions=null)}},{key:"handleAsyncActionSuccess",value:function(t,e){var n=this.createContext();n.result=e,this.executeTrigger(t,n)}},{key:"handleAsyncActionFailure",value:function(t,e){var n=this.createContext();n.error=e,this.executeTrigger(t,n)}},{key:"startTimers",value:function(){var t=this,e=this.config.states[this.currentState];e&&e.timers.length>0&&(this.timerIDs=e.timers.map(function(e){return setTimeout(t.handleTimeout,e.timeout,e)}))}},{key:"stopTimers",value:function(){this.timerIDs&&(this.timerIDs.forEach(clearTimeout),this.timerIDs=null)}},{key:"handleTimeout",value:function(t){this.executeTrigger(t,this.createContext())}},{key:"executeTrigger",value:function(t,e){var n=this;this.execute(function(){var r=n.selectTransition(t.transitions,e);r&&n.executeTransition(r,e)})}},{key:"selectTransition",value:function(t,e){return t.find(function(t){return!t.condition||t.condition(e)})}}],[{key:"start",value:function(e){return new t(e).start()}}]),t}();e["default"]=l},function(t,e){"use strict";function n(t,e){var n=Object.getPrototypeOf(t),r=Object.create(n);return Object.keys(t).forEach(function(n){r[n]=e(t[n])}),r}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e){"use strict";function n(t,e){return Object.keys(e).forEach(function(n){t[n]=e[n]}),t}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(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)}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=function p(t,e,n){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,e);if(void 0===r){var o=Object.getPrototypeOf(t);return null===o?void 0:p(o,e,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)},c=n(4),f=r(c),l=n(12),h=r(l),y=function(t){function e(t,n){o(this,e);var r=i(this,Object.getPrototypeOf(e).call(this,t));return r.config={timeout:n},r}return u(e,t),a(e,[{key:"internalGetConfig",value:function(){return(0,h["default"])(s(Object.getPrototypeOf(e.prototype),"internalGetConfig",this).call(this),this.config)}}]),e}(f["default"]);e["default"]=y},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0}),e.StateMachineConfigurator=void 0;var o=n(8),i=r(o),u=n(15),a=r(u);e.StateMachineConfigurator=i["default"],(0,a["default"])()},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(){(0,b.delegateToAncestor)(s["default"],u["default"]),(0,b.delegateToAncestor)(f["default"],u["default"]),(0,b.delegateToAncestor)(p["default"],f["default"]),(0,b.delegateToAncestor)(p["default"],h["default"]),(0,b.delegateToAncestor)(p["default"],v["default"])}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=n(8),u=r(i),a=n(6),s=r(a),c=n(7),f=r(c),l=n(4),h=r(l),y=n(9),p=r(y),d=n(5),v=r(d),b=n(3)},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=function(){function t(e,r){n(this,t),this.successListener=e,this.failureListener=r,this.onSuccess=this.onSuccess.bind(this),this.onFailure=this.onFailure.bind(this)}return r(t,[{key:"onSuccess",value:function(t){this.successListener&&this.successListener(t)}},{key:"onFailure",value:function(t){this.failureListener&&this.failureListener(t)}},{key:"cancel",value:function(){this.successListener=null,this.failureListener=null}}]),t}();e["default"]=o},function(t,e){"use strict";function n(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];t.forEach(function(t){return t.apply(void 0,n)})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n}])});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc