123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _ModuleSystem = _interopRequireDefault(require("./ModuleSystem"));
- var _ServiceSystem = _interopRequireDefault(require("./ServiceSystem"));
- var _LinkManager = _interopRequireDefault(require("./LinkManager"));
- var _RoutingSystem = _interopRequireDefault(require("./RoutingSystem"));
- var _Systems = _interopRequireDefault(require("./Systems"));
- var _modules = _interopRequireDefault(require("../modules"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var CoreSystem =
- /*#__PURE__*/
- function () {
- function CoreSystem() {
- var _this = this;
- var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'core';
- _classCallCheck(this, CoreSystem);
- this.id = id;
- this.ModuleSystem = new _ModuleSystem.default(id);
- this.ServiceSystem = new _ServiceSystem.default(id);
- this.LinkManager = new _LinkManager.default(id);
- this.RoutingSystem = new _RoutingSystem.default(id);
- this.root = "root";
- this.RoutingSystem.onRouteChange("CoreSystem", function () {
- console.log("CHANGE", _this.RoutingSystem.getRoute());
- _this.refresh(true, false);
- if (_this._onUpdate) _this._onUpdate();
- });
- this.inputs = {};
- this.outputs = {};
- this.inrefs = {};
- this.outrefs = {};
- }
- _createClass(CoreSystem, [{
- key: "import",
- value: function _import(data) {
- var services = data.services,
- modules = data.modules,
- links = data.links,
- routes = data.routes,
- outputs = data.outputs,
- inputs = data.inputs,
- root = data.root;
- this.root = root || this.root;
- this.ServiceSystem.clean();
- this.ModuleSystem.clean();
- this.LinkManager.clean();
- this.RoutingSystem.clean();
- for (var i in inputs) {
- this.addInput(inputs[i]);
- }
- for (var i in outputs) {
- this.addOutput(outputs[i]);
- }
- for (var i in services) {
- this.ServiceSystem.loadService(services[i]);
- }
- for (var i in modules) {
- this.ModuleSystem.loadModule(modules[i]);
- }
- for (var i in links) {
- this.LinkManager.addLink(links[i]);
- }
- this.RoutingSystem.import(routes);
- this.refresh(true);
- }
- }, {
- key: "export",
- value: function _export() {
- var services = this.ServiceSystem.export(),
- modules = this.ModuleSystem.export(),
- links = this.LinkManager.export(),
- routes = this.RoutingSystem.export(),
- outputs = this.outputs,
- inputs = this.inputs;
- return {
- services: services,
- modules: modules,
- links: links,
- routes: routes,
- outputs: outputs,
- inputs: inputs,
- root: this.root
- };
- }
- }, {
- key: "addInput",
- value: function addInput(input) {
- input.pid = 'core';
- this.inputs[input.name] = input;
- this.inrefs[input.name] = this.LinkManager.addInputRef(input);
- this.refresh();
- }
- }, {
- key: "addOutput",
- value: function addOutput(output) {
- output.pid = 'core';
- this.outputs[output.name] = output;
- this.outrefs[output.name] = this.LinkManager.addOutputRef(output);
- this.refresh();
- }
- }, {
- key: "updateInput",
- value: function updateInput(input) {
- input.pid = 'core';
- this.inputs[input.name] = input;
- this.refresh();
- }
- }, {
- key: "updateOutput",
- value: function updateOutput(output) {
- output.pid = 'core';
- this.outputs[output.name] = output;
- this.refresh();
- }
- }, {
- key: "removeInput",
- value: function removeInput(name) {
- delete this.inputs[name];
- this.refresh(true);
- }
- }, {
- key: "removeOutput",
- value: function removeOutput(name) {
- delete this.outputs[name];
- this.refresh(true);
- }
- }, {
- key: "getInput",
- value: function getInput(name) {
- return this.inrefs[name];
- }
- }, {
- key: "getOutput",
- value: function getOutput(name) {
- return this.outrefs[name];
- }
- }, {
- key: "getLoadedModules",
- value: function getLoadedModules() {
- return _objectSpread({}, this.ModuleSystem.availableModules);
- }
- }, {
- key: "loadModule",
- value: function loadModule(mod) {
- this.ModuleSystem.loadModule(mod);
- this.refresh();
- }
- }, {
- key: "loadService",
- value: function loadService(mod) {
- this.ServiceSystem.loadService(mod);
- this.refresh();
- }
- }, {
- key: "refresh",
- value: function refresh() {
- var hard = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
- var suppresedCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- this.ModuleSystem.refresh(hard, true);
- this.ServiceSystem.refresh(hard, true);
- this.LinkManager.clearLinks(_objectSpread({}, this.ModuleSystem.modules, this.ServiceSystem.modules));
- if (this._onUpdate && !suppresedCallback) this._onUpdate();
- }
- }, {
- key: "onUpdate",
- value: function onUpdate(fn) {
- this.ServiceSystem.onUpdate(fn);
- this.ModuleSystem.onUpdate(fn);
- this._onUpdate = fn;
- }
- }, {
- key: "clean",
- value: function clean() {
- this.ModuleSystem.clean();
- this.ServiceSystem.clean();
- this.LinkManager.clean();
- this.RoutingSystem.clean();
- }
- }, {
- key: "getRandom",
- value: function getRandom() {
- var r = parseInt(Math.random() * 1234567890) % 7654321; // check modules
- // check services
- return r;
- }
- }, {
- key: "go",
- value: function go(url, state) {
- var replace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
- if (!this.RoutingSystem.goName(url)) {
- this.RoutingSystem.go(url, state, replace);
- if (replace) this.refresh();
- }
- this._routerState = state; //this.refresh(true);
- }
- }, {
- key: "render",
- value: function render() {
- this.RoutingSystem.resolve();
- this.root = this.RoutingSystem.getCurrentView();
- return [this.ServiceSystem.render(), this.ModuleSystem.render(this.root)];
- }
- }, {
- key: "renderModules",
- value: function renderModules() {
- this.RoutingSystem.resolve();
- this.root = this.RoutingSystem.getCurrentView(); // maybe i should take Routing System out of here beacause of subSystems
- return this.ModuleSystem.render(this.root);
- }
- }, {
- key: "renderServices",
- value: function renderServices() {
- return this.ServiceSystem.render();
- }
- }]);
- return CoreSystem;
- }();
- var _default = CoreSystem;
- exports.default = _default;
|