3
0

CoreSystem.js 3.1 KB

1
  1. "use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;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 CoreSystem=function(){function CoreSystem(){(0,_classCallCheck2["default"])(this,CoreSystem);this.Routing=new _RoutingSystem["default"]();this.ModuleSystem=new _ModuleSystem["default"]();this.EventSystem=new _EventSystem["default"]();this.ViewSystem=new _ViewSystem["default"](this.ModuleSystem,this.EventSystem);this.__loadModules(_modules["default"]);}(0,_createClass2["default"])(CoreSystem,[{key:"getCurrentView",value:function getCurrentView(){return this.ViewSystem.getView(this.Routing.getCurrentView());}},{key:"setHome",value:function setHome(route,View){this.Routing.setHome(route);return this;}},{key:"goto",value:function goto(route){return this.Routing.goTo(route);}},{key:"addPage",value:function addPage(route,View){var ViewID=arguments.length>2&&arguments[2]!==undefined?arguments[2]:Math.random();this.Routing.addRoute(route,route);this.Routing.setView(route,ViewID);this.ViewSystem.addView(ViewID,View);return this;}},{key:"goBack",value:function goBack(){}},{key:"__loadModules",value:function __loadModules(){this.ModuleSystem.load(_modules["default"]);}},{key:"addModule",value:function addModule(mod,namespace){this.ModuleSystem.loadModule(mod.name,mod,namespace);return this;}},{key:"render",value:function render(){var ViewID=this.Routing.getCurrentView();return this.ViewSystem.render(ViewID);}},{key:"import",value:function _import(data){var Routing=data.Routing,Views=data.Views;try{this.Routing["import"](Routing);this.ViewSystem["import"](Views);}catch(e){throw new Error("CoreSystem cannot import data : ",e);}console.log("Successful import");}},{key:"export",value:function _export(){var RS=this.Routing["export"]();var VS=this.ViewSystem["export"]();return{Routing:RS,Views:VS};}},{key:"ray",value:function ray(data){var event=data.event;var targets=event.path.map(function(item){return findReactElement(item);});var resViewNode=null;for(var i in targets){if(targets[i]&&targets[i].ID){resViewNode=targets[i].ID;break;}}var ViewID=this.Routing.getCurrentView();return this.ViewSystem.getNode(ViewID,resViewNode);}}]);return CoreSystem;}();exports["default"]=CoreSystem;var findReactElement=function findReactElement(node){for(var key in node){if(key.startsWith("__reactInternalInstance$")){return node[key]._debugOwner&&node[key]._debugOwner.stateNode.props||node[key].stateNode.memoizedProps;}}return null;};