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.5.3 to 0.5.4

1

index.d.ts

@@ -75,2 +75,3 @@ declare const Finity: {

getCurrentState(): S;
getStateHierarchy(): S[];
canHandle(event: E, eventPayload?: any): boolean;

@@ -77,0 +78,0 @@ handle(event: E, eventPayload?: any): StateMachine<S, E>;

47

package.json
{
"name": "finity",
"version": "0.5.3",
"version": "0.5.4",
"description": "A finite state machine library for Node.js and the browser with a friendly configuration DSL",

@@ -33,24 +33,25 @@ "keywords": [

"devDependencies": {
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-register": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-0": "^6.22.0",
"babel-loader": "^6.3.2",
"jasmine": "^2.5.3",
"jasmine-spec-reporter": "^3.2.0",
"eslint": "^3.16.1",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-react": "^6.10.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"babel-eslint": "^7.1.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-register": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-loader": "^7.1.4",
"jasmine": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"eslint": "^4.18.2",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-react": "^7.7.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"babel-eslint": "^8.2.2",
"isparta": "^4.0.0",
"coveralls": "^2.11.16",
"rimraf": "^2.6.0",
"webpack": "^2.2.1",
"cross-env": "^3.2.3",
"typescript": "^2.2.1",
"coveralls": "^3.0.0",
"rimraf": "^2.6.2",
"webpack": "^4.1.0",
"webpack-cli": "^2.0.10",
"cross-env": "^5.1.3",
"typescript": "^2.7.2",
"shx": "^0.2.2",
"gzip-size-cli": "^2.0.0"
"gzip-size-cli": "^2.1.0"
},

@@ -60,4 +61,4 @@ "scripts": {

"build:commonjs": "babel src --out-dir lib && shx cp src/index.commonjs.js lib/index.js",
"build:umd": "webpack src/index.commonjs.js umd/Finity.js",
"build:umd:min": "webpack -p src/index.commonjs.js umd/Finity.min.js",
"build:umd": "webpack src/index.commonjs.js -o umd/Finity.js --mode development",
"build:umd:min": "webpack src/index.commonjs.js -o umd/Finity.min.js --mode production",
"build": "npm run clean && npm run build:commonjs && npm run build:umd && npm run build:umd:min && gzip-size umd/Finity.min.js",

@@ -64,0 +65,0 @@ "test:typings": "tsc",

@@ -10,14 +10,14 @@ (function webpackUniversalModuleDefinition(root, factory) {

root["Finity"] = factory();
})(this, function() {
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)

@@ -29,23 +29,20 @@ /******/ var module = installedModules[moduleId] = {

/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports

@@ -61,3 +58,8 @@ /******/ __webpack_require__.d = function(exports, name, getter) {

/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules

@@ -71,1166 +73,233 @@ /******/ __webpack_require__.n = function(module) {

/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 17);
/******/ return __webpack_require__(__webpack_require__.s = "./src/index.commonjs.js");
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/******/ ({
/***/ "./src/Finity.js":
/*!***********************!*\
!*** ./src/Finity.js ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _configuration = __webpack_require__(/*! ./configuration */ \"./src/configuration/index.js\");\n\nvar _HierarchicalStateMachine = __webpack_require__(/*! ./core/HierarchicalStateMachine */ \"./src/core/HierarchicalStateMachine.js\");\n\nvar _HierarchicalStateMachine2 = _interopRequireDefault(_HierarchicalStateMachine);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar Finity = {\n configure: function configure() {\n return new _configuration.StateMachineConfigurator();\n },\n start: function start(config) {\n return _HierarchicalStateMachine2.default.start(config);\n }\n};\n\nexports.default = Finity;\n\n//# sourceURL=webpack://Finity/./src/Finity.js?");
/***/ }),
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _mapValues = __webpack_require__(16);
var _mapValues2 = _interopRequireDefault(_mapValues);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var BaseConfigurator = function () {
function BaseConfigurator(parent) {
_classCallCheck(this, BaseConfigurator);
this.parent = parent;
}
BaseConfigurator.prototype.getAncestor = function getAncestor(type) {
if (this.parent) {
return this.parent instanceof type ? this.parent : this.parent.getAncestor(type);
}
return null;
};
BaseConfigurator.prototype.buildConfig = function buildConfig() {
var mapper = function mapper(value) {
if (!value) {
return value;
}
if (value instanceof BaseConfigurator) {
return value.buildConfig();
}
if (Array.isArray(value)) {
return value.map(mapper);
}
if (value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
return (0, _mapValues2.default)(value, mapper);
}
return value;
};
return (0, _mapValues2.default)(this.config, mapper);
};
return BaseConfigurator;
}();
exports.default = BaseConfigurator;
/***/ }),
/* 1 */
/***/ "./src/configuration/AsyncActionConfigurator.js":
/*!******************************************************!*\
!*** ./src/configuration/AsyncActionConfigurator.js ***!
\******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _BaseConfigurator2 = __webpack_require__(/*! ./BaseConfigurator */ \"./src/configuration/BaseConfigurator.js\");\n\nvar _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);\n\nvar _TriggerConfigurator = __webpack_require__(/*! ./TriggerConfigurator */ \"./src/configuration/TriggerConfigurator.js\");\n\nvar _TriggerConfigurator2 = _interopRequireDefault(_TriggerConfigurator);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar AsyncActionConfigurator = function (_BaseConfigurator) {\n _inherits(AsyncActionConfigurator, _BaseConfigurator);\n\n function AsyncActionConfigurator(parent, action) {\n _classCallCheck(this, AsyncActionConfigurator);\n\n var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));\n\n _this.config = {\n action: action,\n successTrigger: new _TriggerConfigurator2.default(_this),\n failureTrigger: new _TriggerConfigurator2.default(_this)\n };\n return _this;\n }\n\n AsyncActionConfigurator.prototype.onSuccess = function onSuccess() {\n return this.config.successTrigger;\n };\n\n AsyncActionConfigurator.prototype.onFailure = function onFailure() {\n return this.config.failureTrigger;\n };\n\n return AsyncActionConfigurator;\n}(_BaseConfigurator3.default);\n\nexports.default = AsyncActionConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/AsyncActionConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _BaseConfigurator2 = __webpack_require__(0);
var _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);
var _TransitionConfigurator = __webpack_require__(6);
var _TransitionConfigurator2 = _interopRequireDefault(_TransitionConfigurator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var TriggerConfigurator = function (_BaseConfigurator) {
_inherits(TriggerConfigurator, _BaseConfigurator);
function TriggerConfigurator(parent) {
_classCallCheck(this, TriggerConfigurator);
var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));
_this.config = {
transitions: []
};
return _this;
}
TriggerConfigurator.prototype.transitionTo = function transitionTo(targetState) {
return this.transition(targetState);
};
TriggerConfigurator.prototype.selfTransition = function selfTransition() {
return this.transition(null);
};
TriggerConfigurator.prototype.internalTransition = function internalTransition() {
return this.transition(null, { isInternal: true });
};
TriggerConfigurator.prototype.ignore = function ignore() {
return this.transition(null, { ignore: true });
};
TriggerConfigurator.prototype.transition = function transition(targetState, options) {
var transitionConfigurator = new _TransitionConfigurator2.default(this, targetState, options);
this.config.transitions.push(transitionConfigurator);
return transitionConfigurator;
};
return TriggerConfigurator;
}(_BaseConfigurator3.default);
exports.default = TriggerConfigurator;
/***/ }),
/* 2 */
/***/ "./src/configuration/BaseConfigurator.js":
/*!***********************************************!*\
!*** ./src/configuration/BaseConfigurator.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _mapValues = __webpack_require__(/*! ../utils/mapValues */ \"./src/utils/mapValues.js\");\n\nvar _mapValues2 = _interopRequireDefault(_mapValues);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar BaseConfigurator = function () {\n function BaseConfigurator(parent) {\n _classCallCheck(this, BaseConfigurator);\n\n this.parent = parent;\n }\n\n BaseConfigurator.prototype.getAncestor = function getAncestor(type) {\n if (this.parent) {\n return this.parent instanceof type ? this.parent : this.parent.getAncestor(type);\n }\n return null;\n };\n\n BaseConfigurator.prototype.buildConfig = function buildConfig() {\n var mapper = function mapper(value) {\n if (!value) {\n return value;\n }\n if (value instanceof BaseConfigurator) {\n return value.buildConfig();\n }\n if (Array.isArray(value)) {\n return value.map(mapper);\n }\n if (value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {\n return (0, _mapValues2.default)(value, mapper);\n }\n return value;\n };\n return (0, _mapValues2.default)(this.config, mapper);\n };\n\n return BaseConfigurator;\n}();\n\nexports.default = BaseConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/BaseConfigurator.js?");
/***/ }),
exports.__esModule = true;
exports.default = merge;
function merge(target, source) {
Object.keys(source).forEach(function (key) {
target[key] = source[key];
});
return target;
}
/***/ }),
/* 3 */
/***/ "./src/configuration/GlobalConfigurator.js":
/*!*************************************************!*\
!*** ./src/configuration/GlobalConfigurator.js ***!
\*************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _BaseConfigurator2 = __webpack_require__(/*! ./BaseConfigurator */ \"./src/configuration/BaseConfigurator.js\");\n\nvar _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar GlobalConfigurator = function (_BaseConfigurator) {\n _inherits(GlobalConfigurator, _BaseConfigurator);\n\n function GlobalConfigurator(parent) {\n _classCallCheck(this, GlobalConfigurator);\n\n var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));\n\n _this.config = {\n stateEnterHooks: [],\n stateExitHooks: [],\n stateChangeHooks: [],\n transitionHooks: [],\n unhandledEventHooks: []\n };\n return _this;\n }\n\n GlobalConfigurator.prototype.onStateEnter = function onStateEnter(hook) {\n this.config.stateEnterHooks.push(hook);\n return this;\n };\n\n GlobalConfigurator.prototype.onStateExit = function onStateExit(hook) {\n this.config.stateExitHooks.push(hook);\n return this;\n };\n\n GlobalConfigurator.prototype.onStateChange = function onStateChange(hook) {\n this.config.stateChangeHooks.push(hook);\n return this;\n };\n\n GlobalConfigurator.prototype.onTransition = function onTransition(hook) {\n this.config.transitionHooks.push(hook);\n return this;\n };\n\n GlobalConfigurator.prototype.onUnhandledEvent = function onUnhandledEvent(hook) {\n this.config.unhandledEventHooks.push(hook);\n return this;\n };\n\n return GlobalConfigurator;\n}(_BaseConfigurator3.default);\n\nexports.default = GlobalConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/GlobalConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _BaseConfigurator2 = __webpack_require__(0);
var _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);
var _TriggerConfigurator = __webpack_require__(1);
var _TriggerConfigurator2 = _interopRequireDefault(_TriggerConfigurator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var AsyncActionConfigurator = function (_BaseConfigurator) {
_inherits(AsyncActionConfigurator, _BaseConfigurator);
function AsyncActionConfigurator(parent, action) {
_classCallCheck(this, AsyncActionConfigurator);
var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));
_this.config = {
action: action,
successTrigger: new _TriggerConfigurator2.default(_this),
failureTrigger: new _TriggerConfigurator2.default(_this)
};
return _this;
}
AsyncActionConfigurator.prototype.onSuccess = function onSuccess() {
return this.config.successTrigger;
};
AsyncActionConfigurator.prototype.onFailure = function onFailure() {
return this.config.failureTrigger;
};
return AsyncActionConfigurator;
}(_BaseConfigurator3.default);
exports.default = AsyncActionConfigurator;
/***/ }),
/* 4 */
/***/ "./src/configuration/StateConfigurator.js":
/*!************************************************!*\
!*** ./src/configuration/StateConfigurator.js ***!
\************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _BaseConfigurator2 = __webpack_require__(/*! ./BaseConfigurator */ \"./src/configuration/BaseConfigurator.js\");\n\nvar _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);\n\nvar _TriggerConfigurator = __webpack_require__(/*! ./TriggerConfigurator */ \"./src/configuration/TriggerConfigurator.js\");\n\nvar _TriggerConfigurator2 = _interopRequireDefault(_TriggerConfigurator);\n\nvar _TimerConfigurator = __webpack_require__(/*! ./TimerConfigurator */ \"./src/configuration/TimerConfigurator.js\");\n\nvar _TimerConfigurator2 = _interopRequireDefault(_TimerConfigurator);\n\nvar _AsyncActionConfigurator = __webpack_require__(/*! ./AsyncActionConfigurator */ \"./src/configuration/AsyncActionConfigurator.js\");\n\nvar _AsyncActionConfigurator2 = _interopRequireDefault(_AsyncActionConfigurator);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar StateConfigurator = function (_BaseConfigurator) {\n _inherits(StateConfigurator, _BaseConfigurator);\n\n function StateConfigurator(parent) {\n _classCallCheck(this, StateConfigurator);\n\n var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));\n\n _this.config = {\n entryActions: [],\n exitActions: [],\n events: Object.create(null),\n anyEventTrigger: null,\n timers: [],\n asyncActions: [],\n submachine: null\n };\n return _this;\n }\n\n StateConfigurator.prototype.onEnter = function onEnter(action) {\n this.config.entryActions.push(action);\n return this;\n };\n\n StateConfigurator.prototype.onExit = function onExit(action) {\n this.config.exitActions.push(action);\n return this;\n };\n\n StateConfigurator.prototype.on = function on(event) {\n if (!this.config.events[event]) {\n this.config.events[event] = new _TriggerConfigurator2.default(this);\n }\n return this.config.events[event];\n };\n\n StateConfigurator.prototype.onAny = function onAny() {\n if (!this.config.anyEventTrigger) {\n this.config.anyEventTrigger = new _TriggerConfigurator2.default(this);\n }\n return this.config.anyEventTrigger;\n };\n\n StateConfigurator.prototype.onTimeout = function onTimeout(timeout) {\n var timerConfigurator = new _TimerConfigurator2.default(this, timeout);\n this.config.timers.push(timerConfigurator);\n return timerConfigurator;\n };\n\n StateConfigurator.prototype.do = function _do(asyncAction) {\n var asyncActionConfigurator = new _AsyncActionConfigurator2.default(this, asyncAction);\n this.config.asyncActions.push(asyncActionConfigurator);\n return asyncActionConfigurator;\n };\n\n StateConfigurator.prototype.submachine = function submachine(submachineConfig) {\n this.config.submachine = submachineConfig;\n return this;\n };\n\n return StateConfigurator;\n}(_BaseConfigurator3.default);\n\nexports.default = StateConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/StateConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _BaseConfigurator2 = __webpack_require__(0);
var _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var GlobalConfigurator = function (_BaseConfigurator) {
_inherits(GlobalConfigurator, _BaseConfigurator);
function GlobalConfigurator(parent) {
_classCallCheck(this, GlobalConfigurator);
var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));
_this.config = {
stateEnterHooks: [],
stateExitHooks: [],
stateChangeHooks: [],
transitionHooks: [],
unhandledEventHooks: []
};
return _this;
}
GlobalConfigurator.prototype.onStateEnter = function onStateEnter(hook) {
this.config.stateEnterHooks.push(hook);
return this;
};
GlobalConfigurator.prototype.onStateExit = function onStateExit(hook) {
this.config.stateExitHooks.push(hook);
return this;
};
GlobalConfigurator.prototype.onStateChange = function onStateChange(hook) {
this.config.stateChangeHooks.push(hook);
return this;
};
GlobalConfigurator.prototype.onTransition = function onTransition(hook) {
this.config.transitionHooks.push(hook);
return this;
};
GlobalConfigurator.prototype.onUnhandledEvent = function onUnhandledEvent(hook) {
this.config.unhandledEventHooks.push(hook);
return this;
};
return GlobalConfigurator;
}(_BaseConfigurator3.default);
exports.default = GlobalConfigurator;
/***/ }),
/* 5 */
/***/ "./src/configuration/StateMachineConfigurator.js":
/*!*******************************************************!*\
!*** ./src/configuration/StateMachineConfigurator.js ***!
\*******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _BaseConfigurator2 = __webpack_require__(/*! ./BaseConfigurator */ \"./src/configuration/BaseConfigurator.js\");\n\nvar _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);\n\nvar _GlobalConfigurator = __webpack_require__(/*! ./GlobalConfigurator */ \"./src/configuration/GlobalConfigurator.js\");\n\nvar _GlobalConfigurator2 = _interopRequireDefault(_GlobalConfigurator);\n\nvar _StateConfigurator = __webpack_require__(/*! ./StateConfigurator */ \"./src/configuration/StateConfigurator.js\");\n\nvar _StateConfigurator2 = _interopRequireDefault(_StateConfigurator);\n\nvar _HierarchicalStateMachine = __webpack_require__(/*! ../core/HierarchicalStateMachine */ \"./src/core/HierarchicalStateMachine.js\");\n\nvar _HierarchicalStateMachine2 = _interopRequireDefault(_HierarchicalStateMachine);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar StateMachineConfigurator = function (_BaseConfigurator) {\n _inherits(StateMachineConfigurator, _BaseConfigurator);\n\n function StateMachineConfigurator() {\n _classCallCheck(this, StateMachineConfigurator);\n\n var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this));\n\n _this.config = {\n global: new _GlobalConfigurator2.default(_this),\n initialState: null,\n states: Object.create(null)\n };\n return _this;\n }\n\n StateMachineConfigurator.prototype.global = function global() {\n return this.config.global;\n };\n\n StateMachineConfigurator.prototype.initialState = function initialState(state) {\n this.config.initialState = state;\n return this.state(state);\n };\n\n StateMachineConfigurator.prototype.state = function state(_state) {\n if (!this.config.states[_state]) {\n this.config.states[_state] = new _StateConfigurator2.default(this);\n }\n return this.config.states[_state];\n };\n\n StateMachineConfigurator.prototype.getConfig = function getConfig() {\n return this.buildConfig();\n };\n\n StateMachineConfigurator.prototype.start = function start() {\n var config = this.getConfig();\n return _HierarchicalStateMachine2.default.start(config);\n };\n\n return StateMachineConfigurator;\n}(_BaseConfigurator3.default);\n\nexports.default = StateMachineConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/StateMachineConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _BaseConfigurator2 = __webpack_require__(0);
var _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);
var _TriggerConfigurator = __webpack_require__(1);
var _TriggerConfigurator2 = _interopRequireDefault(_TriggerConfigurator);
var _TimerConfigurator = __webpack_require__(10);
var _TimerConfigurator2 = _interopRequireDefault(_TimerConfigurator);
var _AsyncActionConfigurator = __webpack_require__(3);
var _AsyncActionConfigurator2 = _interopRequireDefault(_AsyncActionConfigurator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var StateConfigurator = function (_BaseConfigurator) {
_inherits(StateConfigurator, _BaseConfigurator);
function StateConfigurator(parent) {
_classCallCheck(this, StateConfigurator);
var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));
_this.config = {
entryActions: [],
exitActions: [],
events: Object.create(null),
anyEventTrigger: null,
timers: [],
asyncActions: [],
submachine: null
};
return _this;
}
StateConfigurator.prototype.onEnter = function onEnter(action) {
this.config.entryActions.push(action);
return this;
};
StateConfigurator.prototype.onExit = function onExit(action) {
this.config.exitActions.push(action);
return this;
};
StateConfigurator.prototype.on = function on(event) {
if (!this.config.events[event]) {
this.config.events[event] = new _TriggerConfigurator2.default(this);
}
return this.config.events[event];
};
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) {
var timerConfigurator = new _TimerConfigurator2.default(this, timeout);
this.config.timers.push(timerConfigurator);
return timerConfigurator;
};
StateConfigurator.prototype.do = function _do(asyncAction) {
var asyncActionConfigurator = new _AsyncActionConfigurator2.default(this, asyncAction);
this.config.asyncActions.push(asyncActionConfigurator);
return asyncActionConfigurator;
};
StateConfigurator.prototype.submachine = function submachine(submachineConfig) {
this.config.submachine = submachineConfig;
return this;
};
return StateConfigurator;
}(_BaseConfigurator3.default);
exports.default = StateConfigurator;
/***/ }),
/* 6 */
/***/ "./src/configuration/TimerConfigurator.js":
/*!************************************************!*\
!*** ./src/configuration/TimerConfigurator.js ***!
\************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _TriggerConfigurator2 = __webpack_require__(/*! ./TriggerConfigurator */ \"./src/configuration/TriggerConfigurator.js\");\n\nvar _TriggerConfigurator3 = _interopRequireDefault(_TriggerConfigurator2);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar TrimerConfigurator = function (_TriggerConfigurator) {\n _inherits(TrimerConfigurator, _TriggerConfigurator);\n\n function TrimerConfigurator(parent, timeout) {\n _classCallCheck(this, TrimerConfigurator);\n\n var _this = _possibleConstructorReturn(this, _TriggerConfigurator.call(this, parent));\n\n _this.config.timeout = timeout;\n return _this;\n }\n\n return TrimerConfigurator;\n}(_TriggerConfigurator3.default);\n\nexports.default = TrimerConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/TimerConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _BaseConfigurator2 = __webpack_require__(0);
var _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var TransitionConfigurator = function (_BaseConfigurator) {
_inherits(TransitionConfigurator, _BaseConfigurator);
function TransitionConfigurator(parent, targetState) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
_classCallCheck(this, TransitionConfigurator);
var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));
_this.config = _extends({
targetState: targetState
}, options, {
actions: [],
condition: null
});
return _this;
}
TransitionConfigurator.prototype.withAction = function withAction(action) {
this.config.actions.push(action);
return this;
};
TransitionConfigurator.prototype.withCondition = function withCondition(condition) {
this.config.condition = condition;
return this;
};
return TransitionConfigurator;
}(_BaseConfigurator3.default);
exports.default = TransitionConfigurator;
/***/ }),
/* 7 */
/***/ "./src/configuration/TransitionConfigurator.js":
/*!*****************************************************!*\
!*** ./src/configuration/TransitionConfigurator.js ***!
\*****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };\n\nvar _BaseConfigurator2 = __webpack_require__(/*! ./BaseConfigurator */ \"./src/configuration/BaseConfigurator.js\");\n\nvar _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar TransitionConfigurator = function (_BaseConfigurator) {\n _inherits(TransitionConfigurator, _BaseConfigurator);\n\n function TransitionConfigurator(parent, targetState) {\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n\n _classCallCheck(this, TransitionConfigurator);\n\n var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));\n\n _this.config = _extends({\n targetState: targetState\n }, options, {\n actions: [],\n condition: null\n });\n return _this;\n }\n\n TransitionConfigurator.prototype.withAction = function withAction(action) {\n this.config.actions.push(action);\n return this;\n };\n\n TransitionConfigurator.prototype.withCondition = function withCondition(condition) {\n this.config.condition = condition;\n return this;\n };\n\n return TransitionConfigurator;\n}(_BaseConfigurator3.default);\n\nexports.default = TransitionConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/TransitionConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _StateMachine = __webpack_require__(13);
var _StateMachine2 = _interopRequireDefault(_StateMachine);
var _TaskScheduler = __webpack_require__(14);
var _TaskScheduler2 = _interopRequireDefault(_TaskScheduler);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var HierarchicalStateMachine = function () {
function HierarchicalStateMachine(rootStateMachine, currentStateMachine, taskScheduler) {
_classCallCheck(this, HierarchicalStateMachine);
this.rootStateMachine = rootStateMachine;
this.currentStateMachine = currentStateMachine;
this.taskScheduler = taskScheduler;
}
HierarchicalStateMachine.start = function start(config) {
var taskScheduler = new _TaskScheduler2.default();
var rootStateMachine = void 0;
var createContext = function createContext(stateMachine) {
return {
stateMachine: new HierarchicalStateMachine(rootStateMachine, stateMachine, taskScheduler)
};
};
rootStateMachine = new _StateMachine2.default(config, taskScheduler, createContext);
taskScheduler.execute(function () {
return rootStateMachine.start();
});
return new HierarchicalStateMachine(rootStateMachine, rootStateMachine, taskScheduler);
};
HierarchicalStateMachine.prototype.getCurrentState = function getCurrentState() {
return this.currentStateMachine.getCurrentState();
};
HierarchicalStateMachine.prototype.getSubmachine = function getSubmachine() {
var submachine = this.currentStateMachine.getSubmachine();
if (submachine) {
return new HierarchicalStateMachine(this.rootStateMachine, submachine, this.taskScheduler);
}
return null;
};
HierarchicalStateMachine.prototype.getStateHierarchy = function getStateHierarchy() {
return this.getStateMachines().map(function (stateMachine) {
return stateMachine.getCurrentState();
});
};
HierarchicalStateMachine.prototype.canHandle = function canHandle(event, eventPayload) {
var stateMachines = this.getStateMachines();
for (var i = stateMachines.length - 1; i >= 0; i--) {
if (stateMachines[i].canHandle(event, eventPayload)) {
return true;
}
}
return false;
};
HierarchicalStateMachine.prototype.handle = function handle(event, eventPayload) {
var _this = this;
this.taskScheduler.enqueue(function () {
var stateMachines = _this.getStateMachines();
for (var i = stateMachines.length - 1; i >= 0; i--) {
if (stateMachines[i].tryHandle(event, eventPayload)) {
return;
}
}
_this.currentStateMachine.handleUnhandledEvent(event, eventPayload);
});
return this;
};
HierarchicalStateMachine.prototype.getStateMachines = function getStateMachines() {
var stateMachines = [];
var stateMachine = this.rootStateMachine;
do {
stateMachines.push(stateMachine);
stateMachine = stateMachine.getSubmachine();
} while (stateMachine);
return stateMachines;
};
HierarchicalStateMachine.prototype.toString = function toString() {
return 'StateMachine(currentState: ' + this.getCurrentState() + ')';
};
return HierarchicalStateMachine;
}();
exports.default = HierarchicalStateMachine;
/***/ }),
/* 8 */
/***/ "./src/configuration/TriggerConfigurator.js":
/*!**************************************************!*\
!*** ./src/configuration/TriggerConfigurator.js ***!
\**************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _BaseConfigurator2 = __webpack_require__(/*! ./BaseConfigurator */ \"./src/configuration/BaseConfigurator.js\");\n\nvar _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);\n\nvar _TransitionConfigurator = __webpack_require__(/*! ./TransitionConfigurator */ \"./src/configuration/TransitionConfigurator.js\");\n\nvar _TransitionConfigurator2 = _interopRequireDefault(_TransitionConfigurator);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar TriggerConfigurator = function (_BaseConfigurator) {\n _inherits(TriggerConfigurator, _BaseConfigurator);\n\n function TriggerConfigurator(parent) {\n _classCallCheck(this, TriggerConfigurator);\n\n var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this, parent));\n\n _this.config = {\n transitions: []\n };\n return _this;\n }\n\n TriggerConfigurator.prototype.transitionTo = function transitionTo(targetState) {\n return this.transition(targetState);\n };\n\n TriggerConfigurator.prototype.selfTransition = function selfTransition() {\n return this.transition(null);\n };\n\n TriggerConfigurator.prototype.internalTransition = function internalTransition() {\n return this.transition(null, { isInternal: true });\n };\n\n TriggerConfigurator.prototype.ignore = function ignore() {\n return this.transition(null, { ignore: true });\n };\n\n TriggerConfigurator.prototype.transition = function transition(targetState, options) {\n var transitionConfigurator = new _TransitionConfigurator2.default(this, targetState, options);\n this.config.transitions.push(transitionConfigurator);\n return transitionConfigurator;\n };\n\n return TriggerConfigurator;\n}(_BaseConfigurator3.default);\n\nexports.default = TriggerConfigurator;\n\n//# sourceURL=webpack://Finity/./src/configuration/TriggerConfigurator.js?");
/***/ }),
exports.__esModule = true;
var _configuration = __webpack_require__(12);
var _HierarchicalStateMachine = __webpack_require__(7);
var _HierarchicalStateMachine2 = _interopRequireDefault(_HierarchicalStateMachine);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Finity = {
configure: function configure() {
return new _configuration.StateMachineConfigurator();
},
start: function start(config) {
return _HierarchicalStateMachine2.default.start(config);
}
};
exports.default = Finity;
/***/ }),
/* 9 */
/***/ "./src/configuration/delegateToAncestor.js":
/*!*************************************************!*\
!*** ./src/configuration/delegateToAncestor.js ***!
\*************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\nexports.default = delegateToAncestor;\nfunction delegateToAncestor(constructor, ancestorConstructor) {\n var prototype = constructor.prototype;\n var ancestorPrototype = ancestorConstructor.prototype;\n Object.getOwnPropertyNames(ancestorPrototype).filter(function (name) {\n return !prototype[name] && ancestorPrototype[name] instanceof Function && ancestorPrototype[name] !== ancestorConstructor;\n }).forEach(function (name) {\n // eslint-disable-next-line func-names\n prototype[name] = function () {\n var method = ancestorPrototype[name];\n\n for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n return method.apply(this.getAncestor(ancestorConstructor), args);\n };\n });\n}\n\n//# sourceURL=webpack://Finity/./src/configuration/delegateToAncestor.js?");
/***/ }),
exports.__esModule = true;
var _BaseConfigurator2 = __webpack_require__(0);
var _BaseConfigurator3 = _interopRequireDefault(_BaseConfigurator2);
var _GlobalConfigurator = __webpack_require__(4);
var _GlobalConfigurator2 = _interopRequireDefault(_GlobalConfigurator);
var _StateConfigurator = __webpack_require__(5);
var _StateConfigurator2 = _interopRequireDefault(_StateConfigurator);
var _HierarchicalStateMachine = __webpack_require__(7);
var _HierarchicalStateMachine2 = _interopRequireDefault(_HierarchicalStateMachine);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var StateMachineConfigurator = function (_BaseConfigurator) {
_inherits(StateMachineConfigurator, _BaseConfigurator);
function StateMachineConfigurator() {
_classCallCheck(this, StateMachineConfigurator);
var _this = _possibleConstructorReturn(this, _BaseConfigurator.call(this));
_this.config = {
global: new _GlobalConfigurator2.default(_this),
initialState: null,
states: Object.create(null)
};
return _this;
}
StateMachineConfigurator.prototype.global = function global() {
return this.config.global;
};
StateMachineConfigurator.prototype.initialState = function initialState(state) {
this.config.initialState = state;
return this.state(state);
};
StateMachineConfigurator.prototype.state = function state(_state) {
if (!this.config.states[_state]) {
this.config.states[_state] = new _StateConfigurator2.default(this);
}
return this.config.states[_state];
};
StateMachineConfigurator.prototype.getConfig = function getConfig() {
return this.buildConfig();
};
StateMachineConfigurator.prototype.start = function start() {
var config = this.getConfig();
return _HierarchicalStateMachine2.default.start(config);
};
return StateMachineConfigurator;
}(_BaseConfigurator3.default);
exports.default = StateMachineConfigurator;
/***/ }),
/* 10 */
/***/ "./src/configuration/index.js":
/*!************************************!*\
!*** ./src/configuration/index.js ***!
\************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\nexports.StateMachineConfigurator = undefined;\n\nvar _StateMachineConfigurator = __webpack_require__(/*! ./StateMachineConfigurator */ \"./src/configuration/StateMachineConfigurator.js\");\n\nvar _StateMachineConfigurator2 = _interopRequireDefault(_StateMachineConfigurator);\n\nvar _GlobalConfigurator = __webpack_require__(/*! ./GlobalConfigurator */ \"./src/configuration/GlobalConfigurator.js\");\n\nvar _GlobalConfigurator2 = _interopRequireDefault(_GlobalConfigurator);\n\nvar _StateConfigurator = __webpack_require__(/*! ./StateConfigurator */ \"./src/configuration/StateConfigurator.js\");\n\nvar _StateConfigurator2 = _interopRequireDefault(_StateConfigurator);\n\nvar _TriggerConfigurator = __webpack_require__(/*! ./TriggerConfigurator */ \"./src/configuration/TriggerConfigurator.js\");\n\nvar _TriggerConfigurator2 = _interopRequireDefault(_TriggerConfigurator);\n\nvar _TransitionConfigurator = __webpack_require__(/*! ./TransitionConfigurator */ \"./src/configuration/TransitionConfigurator.js\");\n\nvar _TransitionConfigurator2 = _interopRequireDefault(_TransitionConfigurator);\n\nvar _AsyncActionConfigurator = __webpack_require__(/*! ./AsyncActionConfigurator */ \"./src/configuration/AsyncActionConfigurator.js\");\n\nvar _AsyncActionConfigurator2 = _interopRequireDefault(_AsyncActionConfigurator);\n\nvar _delegateToAncestor = __webpack_require__(/*! ./delegateToAncestor */ \"./src/configuration/delegateToAncestor.js\");\n\nvar _delegateToAncestor2 = _interopRequireDefault(_delegateToAncestor);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.StateMachineConfigurator = _StateMachineConfigurator2.default; /* eslint-disable import/prefer-default-export */\n\n(0, _delegateToAncestor2.default)(_GlobalConfigurator2.default, _StateMachineConfigurator2.default);\n(0, _delegateToAncestor2.default)(_StateConfigurator2.default, _StateMachineConfigurator2.default);\n(0, _delegateToAncestor2.default)(_TransitionConfigurator2.default, _StateConfigurator2.default);\n(0, _delegateToAncestor2.default)(_TransitionConfigurator2.default, _TriggerConfigurator2.default);\n(0, _delegateToAncestor2.default)(_TransitionConfigurator2.default, _AsyncActionConfigurator2.default);\n\n//# sourceURL=webpack://Finity/./src/configuration/index.js?");
/***/ }),
exports.__esModule = true;
var _TriggerConfigurator2 = __webpack_require__(1);
var _TriggerConfigurator3 = _interopRequireDefault(_TriggerConfigurator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var TrimerConfigurator = function (_TriggerConfigurator) {
_inherits(TrimerConfigurator, _TriggerConfigurator);
function TrimerConfigurator(parent, timeout) {
_classCallCheck(this, TrimerConfigurator);
var _this = _possibleConstructorReturn(this, _TriggerConfigurator.call(this, parent));
_this.config.timeout = timeout;
return _this;
}
return TrimerConfigurator;
}(_TriggerConfigurator3.default);
exports.default = TrimerConfigurator;
/***/ }),
/* 11 */
/***/ "./src/core/HierarchicalStateMachine.js":
/*!**********************************************!*\
!*** ./src/core/HierarchicalStateMachine.js ***!
\**********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _StateMachine = __webpack_require__(/*! ./StateMachine */ \"./src/core/StateMachine.js\");\n\nvar _StateMachine2 = _interopRequireDefault(_StateMachine);\n\nvar _TaskScheduler = __webpack_require__(/*! ./TaskScheduler */ \"./src/core/TaskScheduler.js\");\n\nvar _TaskScheduler2 = _interopRequireDefault(_TaskScheduler);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar HierarchicalStateMachine = function () {\n function HierarchicalStateMachine(rootStateMachine, currentStateMachine, taskScheduler) {\n _classCallCheck(this, HierarchicalStateMachine);\n\n this.rootStateMachine = rootStateMachine;\n this.currentStateMachine = currentStateMachine;\n this.taskScheduler = taskScheduler;\n }\n\n HierarchicalStateMachine.start = function start(config) {\n var taskScheduler = new _TaskScheduler2.default();\n var rootStateMachine = void 0;\n var createContext = function createContext(stateMachine) {\n return {\n stateMachine: new HierarchicalStateMachine(rootStateMachine, stateMachine, taskScheduler)\n };\n };\n rootStateMachine = new _StateMachine2.default(config, taskScheduler, createContext);\n taskScheduler.execute(function () {\n return rootStateMachine.start();\n });\n return new HierarchicalStateMachine(rootStateMachine, rootStateMachine, taskScheduler);\n };\n\n HierarchicalStateMachine.prototype.getCurrentState = function getCurrentState() {\n return this.currentStateMachine.getCurrentState();\n };\n\n HierarchicalStateMachine.prototype.getSubmachine = function getSubmachine() {\n var submachine = this.currentStateMachine.getSubmachine();\n if (submachine) {\n return new HierarchicalStateMachine(this.rootStateMachine, submachine, this.taskScheduler);\n }\n return null;\n };\n\n HierarchicalStateMachine.prototype.getStateHierarchy = function getStateHierarchy() {\n return this.getStateMachines().map(function (stateMachine) {\n return stateMachine.getCurrentState();\n });\n };\n\n HierarchicalStateMachine.prototype.canHandle = function canHandle(event, eventPayload) {\n var stateMachines = this.getStateMachines();\n for (var i = stateMachines.length - 1; i >= 0; i--) {\n if (stateMachines[i].canHandle(event, eventPayload)) {\n return true;\n }\n }\n return false;\n };\n\n HierarchicalStateMachine.prototype.handle = function handle(event, eventPayload) {\n var _this = this;\n\n this.taskScheduler.enqueue(function () {\n var stateMachines = _this.getStateMachines();\n for (var i = stateMachines.length - 1; i >= 0; i--) {\n if (stateMachines[i].tryHandle(event, eventPayload)) {\n return;\n }\n }\n _this.currentStateMachine.handleUnhandledEvent(event, eventPayload);\n });\n return this;\n };\n\n HierarchicalStateMachine.prototype.getStateMachines = function getStateMachines() {\n var stateMachines = [];\n var stateMachine = this.rootStateMachine;\n do {\n stateMachines.push(stateMachine);\n stateMachine = stateMachine.getSubmachine();\n } while (stateMachine);\n return stateMachines;\n };\n\n HierarchicalStateMachine.prototype.toString = function toString() {\n return 'StateMachine(currentState: ' + this.getCurrentState() + ')';\n };\n\n return HierarchicalStateMachine;\n}();\n\nexports.default = HierarchicalStateMachine;\n\n//# sourceURL=webpack://Finity/./src/core/HierarchicalStateMachine.js?");
/***/ }),
exports.__esModule = true;
exports.default = delegateToAncestor;
function delegateToAncestor(constructor, ancestorConstructor) {
var prototype = constructor.prototype;
var ancestorPrototype = ancestorConstructor.prototype;
Object.getOwnPropertyNames(ancestorPrototype).filter(function (name) {
return !prototype[name] && ancestorPrototype[name] instanceof Function && ancestorPrototype[name] !== ancestorConstructor;
}).forEach(function (name) {
// eslint-disable-next-line func-names
prototype[name] = function () {
var method = ancestorPrototype[name];
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return method.apply(this.getAncestor(ancestorConstructor), args);
};
});
}
/***/ }),
/* 12 */
/***/ "./src/core/StateMachine.js":
/*!**********************************!*\
!*** ./src/core/StateMachine.js ***!
\**********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _invokeEach = __webpack_require__(/*! ../utils/invokeEach */ \"./src/utils/invokeEach.js\");\n\nvar _invokeEach2 = _interopRequireDefault(_invokeEach);\n\nvar _merge = __webpack_require__(/*! ../utils/merge */ \"./src/utils/merge.js\");\n\nvar _merge2 = _interopRequireDefault(_merge);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar noop = function noop() {};\n\nvar StateMachine = function () {\n function StateMachine(config, taskScheduler, contextFactory) {\n _classCallCheck(this, StateMachine);\n\n if (config === undefined || config === null) {\n throw new Error('Configuration must be specified.');\n }\n if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) !== 'object') {\n throw new Error('Configuration must be an object.');\n }\n if (config.initialState === undefined || config.initialState === null) {\n throw new Error('Initial state must be specified.');\n }\n this.config = config;\n this.taskScheduler = taskScheduler;\n this.contextFactory = contextFactory;\n this.currentState = null;\n this.submachines = Object.create(null);\n this.timerIDs = null;\n this.asyncActionCancelers = null;\n this.handleAsyncActionComplete = this.handleAsyncActionComplete.bind(this);\n this.handleTimeout = this.handleTimeout.bind(this);\n }\n\n StateMachine.prototype.getCurrentState = function getCurrentState() {\n return this.currentState;\n };\n\n StateMachine.prototype.canHandle = function canHandle(event, eventPayload) {\n if (!this.isStarted()) {\n return false;\n }\n\n var context = this.createContextWithEvent(event, eventPayload);\n return !!this.getFirstAllowedTransitionForEvent(context);\n };\n\n StateMachine.prototype.tryHandle = function tryHandle(event, eventPayload) {\n if (!this.isStarted()) {\n return false;\n }\n\n var context = this.createContextWithEvent(event, eventPayload);\n var transitionConfig = this.getFirstAllowedTransitionForEvent(context);\n if (transitionConfig) {\n this.executeTransition(transitionConfig, context);\n return true;\n }\n return false;\n };\n\n StateMachine.prototype.handleUnhandledEvent = function handleUnhandledEvent(event, eventPayload) {\n if (this.config.global.unhandledEventHooks.length > 0) {\n (0, _invokeEach2.default)(this.config.global.unhandledEventHooks, event, this.currentState, this.createContextWithEvent(event, eventPayload));\n } else {\n throw new Error('Unhandled event \\'' + event + '\\' in state \\'' + this.currentState + '\\'.');\n }\n };\n\n StateMachine.prototype.isStarted = function isStarted() {\n return this.currentState !== null;\n };\n\n StateMachine.prototype.start = function start() {\n if (!this.isStarted()) {\n this.enterState(this.config.initialState, this.createContext());\n }\n };\n\n StateMachine.prototype.stop = function stop() {\n if (this.isStarted()) {\n this.exitState(this.createContext());\n this.currentState = null;\n }\n };\n\n StateMachine.prototype.getSubmachine = function getSubmachine() {\n return this.isStarted() ? this.submachines[this.currentState] : null;\n };\n\n StateMachine.prototype.executeTransition = function executeTransition(transitionConfig, context) {\n if (transitionConfig.ignore) {\n return;\n }\n\n if (!transitionConfig.isInternal) {\n this.exitState(context);\n }\n\n var nextState = transitionConfig.targetState !== null ? transitionConfig.targetState : this.currentState;\n\n (0, _invokeEach2.default)(this.config.global.transitionHooks, this.currentState, nextState, context);\n (0, _invokeEach2.default)(transitionConfig.actions, this.currentState, nextState, context);\n\n if (!transitionConfig.isInternal) {\n this.enterState(nextState, context);\n }\n };\n\n StateMachine.prototype.enterState = function enterState(state, context) {\n (0, _invokeEach2.default)(this.config.global.stateEnterHooks, state, context);\n\n var stateConfig = this.config.states[state];\n if (stateConfig) {\n (0, _invokeEach2.default)(stateConfig.entryActions, state, context);\n }\n\n if (this.currentState !== null && this.currentState !== state) {\n (0, _invokeEach2.default)(this.config.global.stateChangeHooks, this.currentState, state, context);\n }\n\n try {\n this.startAsyncActions(state, context);\n this.startTimers(state);\n this.startSubmachines(state);\n } catch (error) {\n this.stopTimers();\n this.cancelAsyncActions();\n throw error;\n }\n\n this.currentState = state;\n };\n\n StateMachine.prototype.exitState = function exitState(context) {\n this.stopSubmachines();\n this.stopTimers();\n this.cancelAsyncActions();\n\n (0, _invokeEach2.default)(this.config.global.stateExitHooks, this.currentState, context);\n\n var stateConfig = this.config.states[this.currentState];\n if (stateConfig) {\n (0, _invokeEach2.default)(stateConfig.exitActions, this.currentState, context);\n }\n };\n\n StateMachine.prototype.startAsyncActions = function startAsyncActions(state, context) {\n var _this = this;\n\n var stateConfig = this.config.states[state];\n if (stateConfig) {\n stateConfig.asyncActions.forEach(function (asyncActionConfig) {\n return _this.startAsyncAction(asyncActionConfig, state, context);\n });\n }\n };\n\n StateMachine.prototype.startAsyncAction = function startAsyncAction(asyncActionConfig, state, context) {\n var action = asyncActionConfig.action,\n successTrigger = asyncActionConfig.successTrigger,\n failureTrigger = asyncActionConfig.failureTrigger;\n\n var handleComplete = this.handleAsyncActionComplete;\n action(state, context).then(function (result) {\n return handleComplete(successTrigger, { result: result });\n }, function (error) {\n return handleComplete(failureTrigger, { error: error });\n });\n this.asyncActionCancelers = this.asyncActionCancelers || [];\n this.asyncActionCancelers.push(function () {\n handleComplete = noop;\n });\n };\n\n StateMachine.prototype.cancelAsyncActions = function cancelAsyncActions() {\n if (this.asyncActionCancelers) {\n (0, _invokeEach2.default)(this.asyncActionCancelers);\n this.asyncActionCancelers = null;\n }\n };\n\n StateMachine.prototype.handleAsyncActionComplete = function handleAsyncActionComplete(triggerConfig, additionalContext) {\n var context = (0, _merge2.default)(this.createContext(), additionalContext);\n this.executeTrigger(triggerConfig, context);\n };\n\n StateMachine.prototype.startTimers = function startTimers(state) {\n var _this2 = this;\n\n var stateConfig = this.config.states[state];\n if (stateConfig && stateConfig.timers.length > 0) {\n this.timerIDs = stateConfig.timers.map(function (timerConfig) {\n return setTimeout(_this2.handleTimeout, timerConfig.timeout, timerConfig);\n });\n }\n };\n\n StateMachine.prototype.stopTimers = function stopTimers() {\n if (this.timerIDs) {\n this.timerIDs.forEach(clearTimeout);\n this.timerIDs = null;\n }\n };\n\n StateMachine.prototype.handleTimeout = function handleTimeout(timerConfig) {\n this.executeTrigger(timerConfig, this.createContext());\n };\n\n StateMachine.prototype.startSubmachines = function startSubmachines(state) {\n var stateConfig = this.config.states[state];\n if (stateConfig && stateConfig.submachine) {\n if (!this.submachines[state]) {\n this.submachines[state] = new StateMachine(stateConfig.submachine, this.taskScheduler, this.contextFactory);\n }\n this.submachines[state].start();\n }\n };\n\n StateMachine.prototype.stopSubmachines = function stopSubmachines() {\n var submachine = this.submachines[this.currentState];\n if (submachine) {\n submachine.stop();\n }\n };\n\n StateMachine.prototype.createContext = function createContext() {\n return this.contextFactory(this);\n };\n\n StateMachine.prototype.createContextWithEvent = function createContextWithEvent(event, eventPayload) {\n var context = this.createContext();\n context.event = event;\n if (eventPayload !== undefined) {\n context.eventPayload = eventPayload;\n }\n return context;\n };\n\n StateMachine.getFirstAllowedTransition = function getFirstAllowedTransition(transitions, context) {\n for (var i = 0; i < transitions.length; i++) {\n if (!transitions[i].condition || transitions[i].condition(context)) {\n return transitions[i];\n }\n }\n return null;\n };\n\n StateMachine.prototype.getFirstAllowedTransitionForEvent = function getFirstAllowedTransitionForEvent(context) {\n var stateConfig = this.config.states[this.currentState];\n if (!stateConfig) {\n return null;\n }\n\n var transitionConfig = null;\n\n var eventConfig = stateConfig.events[context.event];\n if (eventConfig) {\n transitionConfig = StateMachine.getFirstAllowedTransition(eventConfig.transitions, context);\n }\n\n if (!transitionConfig && stateConfig.anyEventTrigger) {\n transitionConfig = StateMachine.getFirstAllowedTransition(stateConfig.anyEventTrigger.transitions, context);\n }\n\n return transitionConfig;\n };\n\n StateMachine.prototype.executeTrigger = function executeTrigger(triggerConfig, context) {\n var _this3 = this;\n\n this.taskScheduler.execute(function () {\n var transitionConfig = StateMachine.getFirstAllowedTransition(triggerConfig.transitions, context);\n if (transitionConfig) {\n _this3.executeTransition(transitionConfig, context);\n }\n });\n };\n\n return StateMachine;\n}();\n\nexports.default = StateMachine;\n\n//# sourceURL=webpack://Finity/./src/core/StateMachine.js?");
/***/ }),
exports.__esModule = true;
exports.StateMachineConfigurator = undefined;
var _StateMachineConfigurator = __webpack_require__(9);
var _StateMachineConfigurator2 = _interopRequireDefault(_StateMachineConfigurator);
var _GlobalConfigurator = __webpack_require__(4);
var _GlobalConfigurator2 = _interopRequireDefault(_GlobalConfigurator);
var _StateConfigurator = __webpack_require__(5);
var _StateConfigurator2 = _interopRequireDefault(_StateConfigurator);
var _TriggerConfigurator = __webpack_require__(1);
var _TriggerConfigurator2 = _interopRequireDefault(_TriggerConfigurator);
var _TransitionConfigurator = __webpack_require__(6);
var _TransitionConfigurator2 = _interopRequireDefault(_TransitionConfigurator);
var _AsyncActionConfigurator = __webpack_require__(3);
var _AsyncActionConfigurator2 = _interopRequireDefault(_AsyncActionConfigurator);
var _delegateToAncestor = __webpack_require__(11);
var _delegateToAncestor2 = _interopRequireDefault(_delegateToAncestor);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.StateMachineConfigurator = _StateMachineConfigurator2.default; /* eslint-disable import/prefer-default-export */
(0, _delegateToAncestor2.default)(_GlobalConfigurator2.default, _StateMachineConfigurator2.default);
(0, _delegateToAncestor2.default)(_StateConfigurator2.default, _StateMachineConfigurator2.default);
(0, _delegateToAncestor2.default)(_TransitionConfigurator2.default, _StateConfigurator2.default);
(0, _delegateToAncestor2.default)(_TransitionConfigurator2.default, _TriggerConfigurator2.default);
(0, _delegateToAncestor2.default)(_TransitionConfigurator2.default, _AsyncActionConfigurator2.default);
/***/ }),
/* 13 */
/***/ "./src/core/TaskScheduler.js":
/*!***********************************!*\
!*** ./src/core/TaskScheduler.js ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar TaskScheduler = function () {\n function TaskScheduler() {\n _classCallCheck(this, TaskScheduler);\n\n this.queue = [];\n this.isBusy = false;\n }\n\n TaskScheduler.prototype.enqueue = function enqueue(task) {\n if (this.isBusy) {\n this.queue.push(task);\n } else {\n this.execute(task);\n }\n };\n\n TaskScheduler.prototype.execute = function execute(task) {\n if (this.isBusy) {\n throw new Error('Cannot execute task because another task is already running.');\n }\n this.isBusy = true;\n try {\n task();\n while (this.queue.length > 0) {\n var nextTask = this.queue.shift();\n nextTask();\n }\n } finally {\n // Clean up\n if (this.queue.length > 0) {\n this.queue = [];\n }\n this.isBusy = false;\n }\n };\n\n return TaskScheduler;\n}();\n\nexports.default = TaskScheduler;\n\n//# sourceURL=webpack://Finity/./src/core/TaskScheduler.js?");
/***/ }),
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _invokeEach = __webpack_require__(15);
var _invokeEach2 = _interopRequireDefault(_invokeEach);
var _merge = __webpack_require__(2);
var _merge2 = _interopRequireDefault(_merge);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var noop = function noop() {};
var StateMachine = function () {
function StateMachine(config, taskScheduler, contextFactory) {
_classCallCheck(this, StateMachine);
if (config === undefined || config === null) {
throw new Error('Configuration must be specified.');
}
if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) !== 'object') {
throw new Error('Configuration must be an object.');
}
if (config.initialState === undefined || config.initialState === null) {
throw new Error('Initial state must be specified.');
}
this.config = config;
this.taskScheduler = taskScheduler;
this.contextFactory = contextFactory;
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);
}
StateMachine.prototype.getCurrentState = function getCurrentState() {
return this.currentState;
};
StateMachine.prototype.canHandle = function canHandle(event, eventPayload) {
if (!this.isStarted()) {
return false;
}
var context = this.createContextWithEvent(event, eventPayload);
return !!this.getFirstAllowedTransitionForEvent(context);
};
StateMachine.prototype.tryHandle = function tryHandle(event, eventPayload) {
if (!this.isStarted()) {
return false;
}
var context = this.createContextWithEvent(event, eventPayload);
var transitionConfig = this.getFirstAllowedTransitionForEvent(context);
if (transitionConfig) {
this.executeTransition(transitionConfig, context);
return true;
}
return false;
};
StateMachine.prototype.handleUnhandledEvent = function handleUnhandledEvent(event, eventPayload) {
if (this.config.global.unhandledEventHooks.length > 0) {
(0, _invokeEach2.default)(this.config.global.unhandledEventHooks, event, this.currentState, this.createContextWithEvent(event, eventPayload));
} else {
throw new Error('Unhandled event \'' + event + '\' in state \'' + this.currentState + '\'.');
}
};
StateMachine.prototype.isStarted = function isStarted() {
return this.currentState !== null;
};
StateMachine.prototype.start = function start() {
if (!this.isStarted()) {
this.enterState(this.config.initialState, this.createContext());
}
};
StateMachine.prototype.stop = function stop() {
if (this.isStarted()) {
this.exitState(this.createContext());
this.currentState = null;
}
};
StateMachine.prototype.getSubmachine = function getSubmachine() {
return this.isStarted() ? this.submachines[this.currentState] : null;
};
StateMachine.prototype.executeTransition = function executeTransition(transitionConfig, context) {
if (transitionConfig.ignore) {
return;
}
if (!transitionConfig.isInternal) {
this.exitState(context);
}
var nextState = transitionConfig.targetState !== null ? transitionConfig.targetState : this.currentState;
(0, _invokeEach2.default)(this.config.global.transitionHooks, this.currentState, nextState, context);
(0, _invokeEach2.default)(transitionConfig.actions, this.currentState, nextState, context);
if (!transitionConfig.isInternal) {
this.enterState(nextState, context);
}
};
StateMachine.prototype.enterState = function enterState(state, context) {
(0, _invokeEach2.default)(this.config.global.stateEnterHooks, state, context);
var stateConfig = this.config.states[state];
if (stateConfig) {
(0, _invokeEach2.default)(stateConfig.entryActions, state, context);
}
if (this.currentState !== null && this.currentState !== state) {
(0, _invokeEach2.default)(this.config.global.stateChangeHooks, this.currentState, state, context);
}
try {
this.startAsyncActions(state, context);
this.startTimers(state);
this.startSubmachines(state);
} catch (error) {
this.stopTimers();
this.cancelAsyncActions();
throw error;
}
this.currentState = state;
};
StateMachine.prototype.exitState = function exitState(context) {
this.stopSubmachines();
this.stopTimers();
this.cancelAsyncActions();
(0, _invokeEach2.default)(this.config.global.stateExitHooks, this.currentState, context);
var stateConfig = this.config.states[this.currentState];
if (stateConfig) {
(0, _invokeEach2.default)(stateConfig.exitActions, this.currentState, context);
}
};
StateMachine.prototype.startAsyncActions = function startAsyncActions(state, context) {
var _this = this;
var stateConfig = this.config.states[state];
if (stateConfig) {
stateConfig.asyncActions.forEach(function (asyncActionConfig) {
return _this.startAsyncAction(asyncActionConfig, state, context);
});
}
};
StateMachine.prototype.startAsyncAction = function startAsyncAction(asyncActionConfig, state, context) {
var action = asyncActionConfig.action,
successTrigger = asyncActionConfig.successTrigger,
failureTrigger = asyncActionConfig.failureTrigger;
var handleComplete = this.handleAsyncActionComplete;
action(state, context).then(function (result) {
return handleComplete(successTrigger, { result: result });
}, function (error) {
return handleComplete(failureTrigger, { error: error });
});
this.asyncActionCancelers = this.asyncActionCancelers || [];
this.asyncActionCancelers.push(function () {
handleComplete = noop;
});
};
StateMachine.prototype.cancelAsyncActions = function cancelAsyncActions() {
if (this.asyncActionCancelers) {
(0, _invokeEach2.default)(this.asyncActionCancelers);
this.asyncActionCancelers = null;
}
};
StateMachine.prototype.handleAsyncActionComplete = function handleAsyncActionComplete(triggerConfig, additionalContext) {
var context = (0, _merge2.default)(this.createContext(), additionalContext);
this.executeTrigger(triggerConfig, context);
};
StateMachine.prototype.startTimers = function startTimers(state) {
var _this2 = this;
var stateConfig = this.config.states[state];
if (stateConfig && stateConfig.timers.length > 0) {
this.timerIDs = stateConfig.timers.map(function (timerConfig) {
return setTimeout(_this2.handleTimeout, timerConfig.timeout, timerConfig);
});
}
};
StateMachine.prototype.stopTimers = function stopTimers() {
if (this.timerIDs) {
this.timerIDs.forEach(clearTimeout);
this.timerIDs = null;
}
};
StateMachine.prototype.handleTimeout = function handleTimeout(timerConfig) {
this.executeTrigger(timerConfig, this.createContext());
};
StateMachine.prototype.startSubmachines = function startSubmachines(state) {
var stateConfig = this.config.states[state];
if (stateConfig && stateConfig.submachine) {
if (!this.submachines[state]) {
this.submachines[state] = new StateMachine(stateConfig.submachine, this.taskScheduler, this.contextFactory);
}
this.submachines[state].start();
}
};
StateMachine.prototype.stopSubmachines = function stopSubmachines() {
var submachine = this.submachines[this.currentState];
if (submachine) {
submachine.stop();
}
};
StateMachine.prototype.createContext = function createContext() {
return this.contextFactory(this);
};
StateMachine.prototype.createContextWithEvent = function createContextWithEvent(event, eventPayload) {
var context = this.createContext();
context.event = event;
if (eventPayload !== undefined) {
context.eventPayload = eventPayload;
}
return context;
};
StateMachine.getFirstAllowedTransition = function getFirstAllowedTransition(transitions, context) {
for (var i = 0; i < transitions.length; i++) {
if (!transitions[i].condition || transitions[i].condition(context)) {
return transitions[i];
}
}
return null;
};
StateMachine.prototype.getFirstAllowedTransitionForEvent = function getFirstAllowedTransitionForEvent(context) {
var stateConfig = this.config.states[this.currentState];
if (!stateConfig) {
return null;
}
var transitionConfig = null;
var eventConfig = stateConfig.events[context.event];
if (eventConfig) {
transitionConfig = StateMachine.getFirstAllowedTransition(eventConfig.transitions, context);
}
if (!transitionConfig && stateConfig.anyEventTrigger) {
transitionConfig = StateMachine.getFirstAllowedTransition(stateConfig.anyEventTrigger.transitions, context);
}
return transitionConfig;
};
StateMachine.prototype.executeTrigger = function executeTrigger(triggerConfig, context) {
var _this3 = this;
this.taskScheduler.execute(function () {
var transitionConfig = StateMachine.getFirstAllowedTransition(triggerConfig.transitions, context);
if (transitionConfig) {
_this3.executeTransition(transitionConfig, context);
}
});
};
return StateMachine;
}();
exports.default = StateMachine;
/***/ }),
/* 14 */
/***/ "./src/index.commonjs.js":
/*!*******************************!*\
!*** ./src/index.commonjs.js ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("/* eslint-disable */\n\n\nvar Finity = __webpack_require__(/*! ./Finity */ \"./src/Finity.js\").default;\nvar merge = __webpack_require__(/*! ./utils/merge */ \"./src/utils/merge.js\").default;\n\nmerge(exports, Finity);\n\n// Allow the use of the default import syntax in TypeScript (import Finity from 'finity')\nexports.default = Finity;\n\n\n//# sourceURL=webpack://Finity/./src/index.commonjs.js?");
/***/ }),
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TaskScheduler = function () {
function TaskScheduler() {
_classCallCheck(this, TaskScheduler);
this.queue = [];
this.isBusy = false;
}
TaskScheduler.prototype.enqueue = function enqueue(task) {
if (this.isBusy) {
this.queue.push(task);
} else {
this.execute(task);
}
};
TaskScheduler.prototype.execute = function execute(task) {
if (this.isBusy) {
throw new Error('Cannot execute task because another task is already running.');
}
this.isBusy = true;
try {
task();
while (this.queue.length > 0) {
var nextTask = this.queue.shift();
nextTask();
}
} finally {
// Clean up
if (this.queue.length > 0) {
this.queue = [];
}
this.isBusy = false;
}
};
return TaskScheduler;
}();
exports.default = TaskScheduler;
/***/ }),
/* 15 */
/***/ "./src/utils/invokeEach.js":
/*!*********************************!*\
!*** ./src/utils/invokeEach.js ***!
\*********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\nexports.default = invokeEach;\nfunction invokeEach(fns) {\n for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n args[_key - 1] = arguments[_key];\n }\n\n fns.forEach(function (fn) {\n return fn.apply(undefined, args);\n });\n}\n\n//# sourceURL=webpack://Finity/./src/utils/invokeEach.js?");
/***/ }),
exports.__esModule = true;
exports.default = invokeEach;
function invokeEach(fns) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
fns.forEach(function (fn) {
return fn.apply(undefined, args);
});
}
/***/ }),
/* 16 */
/***/ "./src/utils/mapValues.js":
/*!********************************!*\
!*** ./src/utils/mapValues.js ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\nexports.__esModule = true;\nexports.default = mapValues;\nfunction mapValues(obj, callback) {\n var prototype = Object.getPrototypeOf(obj);\n var result = Object.create(prototype);\n Object.keys(obj).forEach(function (key) {\n result[key] = callback(obj[key]);\n });\n return result;\n}\n\n//# sourceURL=webpack://Finity/./src/utils/mapValues.js?");
/***/ }),
exports.__esModule = true;
exports.default = mapValues;
function mapValues(obj, callback) {
var prototype = Object.getPrototypeOf(obj);
var result = Object.create(prototype);
Object.keys(obj).forEach(function (key) {
result[key] = callback(obj[key]);
});
return result;
}
/***/ }),
/* 17 */
/***/ "./src/utils/merge.js":
/*!****************************!*\
!*** ./src/utils/merge.js ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* eslint-disable */
eval("\n\nexports.__esModule = true;\nexports.default = merge;\nfunction merge(target, source) {\n Object.keys(source).forEach(function (key) {\n target[key] = source[key];\n });\n return target;\n}\n\n//# sourceURL=webpack://Finity/./src/utils/merge.js?");
/***/ })
var Finity = __webpack_require__(8).default;
var merge = __webpack_require__(2).default;
merge(exports, Finity);
// Allow the use of the default import syntax in TypeScript (import Finity from 'finity')
exports.default = Finity;
/***/ })
/******/ ]);
/******/ });
});

@@ -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),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}])});
!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()}(window,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=17)}([function(t,e,n){"use strict";e.__esModule=!0;var o,r="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},i=n(13),s=(o=i)&&o.__esModule?o:{default:o};var u=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(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(){return(0,s.default)(this.config,function e(n){return n?n instanceof t?n.buildConfig():Array.isArray(n)?n.map(e):n&&"object"===(void 0===n?"undefined":r(n))?(0,s.default)(n,e):n:n})},t}();e.default=u},function(t,e,n){"use strict";e.__esModule=!0;var o=i(n(0)),r=i(n(5));function i(t){return t&&t.__esModule?t:{default:t}}var s=function(t){function e(n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(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}(this,t.call(this,n));return o.config={transitions:[]},o}return function(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,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 r.default(this,t,e);return this.config.transitions.push(n),n},e}(o.default);e.default=s},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){return Object.keys(e).forEach(function(n){t[n]=e[n]}),t}},function(t,e,n){"use strict";e.__esModule=!0;var o=i(n(11)),r=i(n(9));function i(t){return t&&t.__esModule?t:{default:t}}var s=function(){function t(e,n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.rootStateMachine=e,this.currentStateMachine=n,this.taskScheduler=o}return t.start=function(e){var n=new r.default,i=void 0;return i=new o.default(e,n,function(e){return{stateMachine:new t(i,e,n)}}),n.execute(function(){return i.start()}),new t(i,i,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=s},function(t,e,n){"use strict";e.__esModule=!0;var o=i(n(0)),r=i(n(1));function i(t){return t&&t.__esModule?t:{default:t}}var s=function(t){function e(n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=function(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}(this,t.call(this,n));return i.config={action:o,successTrigger:new r.default(i),failureTrigger:new r.default(i)},i}return function(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,t),e.prototype.onSuccess=function(){return this.config.successTrigger},e.prototype.onFailure=function(){return this.config.failureTrigger},e}(o.default);e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o,r=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},i=n(0);var s=function(t){function e(n,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var s=function(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}(this,t.call(this,n));return s.config=r({targetState:o},i,{actions:[],condition:null}),s}return function(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,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}(((o=i)&&o.__esModule?o:{default:o}).default);e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o=u(n(0)),r=u(n(1)),i=u(n(12)),s=u(n(4));function u(t){return t&&t.__esModule?t:{default:t}}var a=function(t){function e(n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(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}(this,t.call(this,n));return o.config={entryActions:[],exitActions:[],events:Object.create(null),anyEventTrigger:null,timers:[],asyncActions:[],submachine:null},o}return function(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,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 r.default(this)),this.config.events[t]},e.prototype.onAny=function(){return this.config.anyEventTrigger||(this.config.anyEventTrigger=new r.default(this)),this.config.anyEventTrigger},e.prototype.onTimeout=function(t){var e=new i.default(this,t);return this.config.timers.push(e),e},e.prototype.do=function(t){var e=new s.default(this,t);return this.config.asyncActions.push(e),e},e.prototype.submachine=function(t){return this.config.submachine=t,this},e}(o.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var o,r=n(0);var i=function(t){function e(n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(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}(this,t.call(this,n));return o.config={stateEnterHooks:[],stateExitHooks:[],stateChangeHooks:[],transitionHooks:[],unhandledEventHooks:[]},o}return function(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,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}(((o=r)&&o.__esModule?o:{default:o}).default);e.default=i},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(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),s=0;s<r;s++)i[s]=arguments[s];return n.apply(this.getAncestor(e),i)}})}},function(t,e,n){"use strict";e.__esModule=!0;var o=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(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;){this.queue.shift()()}}finally{this.queue.length>0&&(this.queue=[]),this.isBusy=!1}},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(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)})}},function(t,e,n){"use strict";e.__esModule=!0;var o="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},r=s(n(10)),i=s(n(2));function s(t){return t&&t.__esModule?t:{default:t}}var u=function(){},a=function(){function t(e,n,r){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),void 0===e||null===e)throw new Error("Configuration must be specified.");if("object"!==(void 0===e?"undefined":o(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=r,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,r.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,r.default)(this.config.global.transitionHooks,this.currentState,n,e),(0,r.default)(t.actions,this.currentState,n,e),t.isInternal||this.enterState(n,e)}},t.prototype.enterState=function(t,e){(0,r.default)(this.config.global.stateEnterHooks,t,e);var n=this.config.states[t];n&&(0,r.default)(n.entryActions,t,e),null!==this.currentState&&this.currentState!==t&&(0,r.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,r.default)(this.config.global.stateExitHooks,this.currentState,t);var e=this.config.states[this.currentState];e&&(0,r.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,s=this.handleAsyncActionComplete;o(e,n).then(function(t){return s(r,{result:t})},function(t){return s(i,{error:t})}),this.asyncActionCancelers=this.asyncActionCancelers||[],this.asyncActionCancelers.push(function(){s=u})},t.prototype.cancelAsyncActions=function(){this.asyncActionCancelers&&((0,r.default)(this.asyncActionCancelers),this.asyncActionCancelers=null)},t.prototype.handleAsyncActionComplete=function(t,e){var n=(0,i.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=a},function(t,e,n){"use strict";e.__esModule=!0;var o,r=n(1);var i=function(t){function e(n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=function(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}(this,t.call(this,n));return r.config.timeout=o,r}return function(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,t),e}(((o=r)&&o.__esModule?o:{default:o}).default);e.default=i},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){var n=Object.getPrototypeOf(t),o=Object.create(n);return Object.keys(t).forEach(function(n){o[n]=e(t[n])}),o}},function(t,e,n){"use strict";e.__esModule=!0;var o=u(n(0)),r=u(n(7)),i=u(n(6)),s=u(n(3));function u(t){return t&&t.__esModule?t:{default:t}}var a=function(t){function e(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var n=function(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}(this,t.call(this));return n.config={global:new r.default(n),initialState:null,states:Object.create(null)},n}return function(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,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 i.default(this)),this.config.states[t]},e.prototype.getConfig=function(){return this.buildConfig()},e.prototype.start=function(){var t=this.getConfig();return s.default.start(t)},e}(o.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0,e.StateMachineConfigurator=void 0;var o=f(n(14)),r=f(n(7)),i=f(n(6)),s=f(n(1)),u=f(n(5)),a=f(n(4)),c=f(n(8));function f(t){return t&&t.__esModule?t:{default:t}}e.StateMachineConfigurator=o.default,(0,c.default)(r.default,o.default),(0,c.default)(i.default,o.default),(0,c.default)(u.default,i.default),(0,c.default)(u.default,s.default),(0,c.default)(u.default,a.default)},function(t,e,n){"use strict";e.__esModule=!0;var o,r=n(15),i=n(3),s=(o=i)&&o.__esModule?o:{default:o};var u={configure:function(){return new r.StateMachineConfigurator},start:function(t){return s.default.start(t)}};e.default=u},function(t,e,n){"use strict";var o=n(16).default;(0,n(2).default)(e,o),e.default=o}])});
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