ActionSystem.js 2.5 KB

1
  1. var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.RouteAction=exports.default=void 0;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _RoutingSystem=_interopRequireDefault(require("./RoutingSystem.js"));var _ViewSystem=_interopRequireWildcard(require("./ViewSystem.js"));var _ModuleSystem=_interopRequireDefault(require("./ModuleSystem.js"));var _modules=_interopRequireDefault(require("../../modules"));var _EventSystem=_interopRequireDefault(require("./EventSystem"));var Font=_interopRequireWildcard(require("expo-font"));var ActionSystem=function(){function ActionSystem(CS){(0,_classCallCheck2.default)(this,ActionSystem);this.CoreSystem=CS;this.EventSystem=new _EventSystem.default();this.events=(0,_toConsumableArray2.default)(ActionSystem.Actions);this._disabled=false;this.setupEvents();}(0,_createClass2.default)(ActionSystem,[{key:"setupEvents",value:function setupEvents(){var _this=this;this.events.map(function(Action){_this.EventSystem.on(Action.id,function(d){return _this.dispatch(Action,d);});});}},{key:"dispatch",value:function dispatch(Action,data){return!this._disabled&&new Action(this.CoreSystem).run(data);}},{key:"disable",value:function disable(){this._disabled=true;}},{key:"enable",value:function enable(){this._disabled=false;}},{key:"toggle",value:function toggle(value){this._disabled=value||!this._disabled;}},{key:"createAction",value:function createAction(action){if(!action.type)return;this.EventSystem.emit(action.type,action.data);}},{key:"onUpdate",value:function onUpdate(fn){this._onUpdate=fn;}},{key:"forceUpdate",value:function forceUpdate(){this._onUpdate&&this._onUpdate();}}]);return ActionSystem;}();exports.default=ActionSystem;var RouteAction=function(){function RouteAction(CS){(0,_classCallCheck2.default)(this,RouteAction);this.CoreSystem=CS;}(0,_createClass2.default)(RouteAction,[{key:"run",value:function run(data){var route=data.route;if(route)this.CoreSystem.goto(route);}}]);return RouteAction;}();exports.RouteAction=RouteAction;RouteAction.id="changeRoute";ActionSystem.RouteAction=RouteAction;ActionSystem.Actions=[RouteAction];