CoreSystem.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _ModuleSystem = _interopRequireDefault(require("./ModuleSystem"));
  7. var _ServiceSystem = _interopRequireDefault(require("./ServiceSystem"));
  8. var _LinkManager = _interopRequireDefault(require("./LinkManager"));
  9. var _RoutingSystem = _interopRequireDefault(require("./RoutingSystem"));
  10. var _Systems = _interopRequireDefault(require("./Systems"));
  11. var _modules = _interopRequireDefault(require("../modules"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. 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; }
  14. 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; }
  15. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16. 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); } }
  17. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18. var CoreSystem =
  19. /*#__PURE__*/
  20. function () {
  21. function CoreSystem() {
  22. var _this = this;
  23. var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'core';
  24. _classCallCheck(this, CoreSystem);
  25. this.id = id;
  26. this.ModuleSystem = new _ModuleSystem.default(id);
  27. this.ServiceSystem = new _ServiceSystem.default(id);
  28. this.LinkManager = new _LinkManager.default(id);
  29. this.RoutingSystem = new _RoutingSystem.default(id);
  30. this.root = "root";
  31. this.RoutingSystem.onRouteChange("CoreSystem", function () {
  32. console.log("CHANGE", _this.RoutingSystem.getRoute());
  33. _this.refresh(true, false);
  34. if (_this._onUpdate) _this._onUpdate();
  35. });
  36. this.inputs = {};
  37. this.outputs = {};
  38. this.inrefs = {};
  39. this.outrefs = {};
  40. }
  41. _createClass(CoreSystem, [{
  42. key: "import",
  43. value: function _import(data) {
  44. var services = data.services,
  45. modules = data.modules,
  46. links = data.links,
  47. routes = data.routes,
  48. outputs = data.outputs,
  49. inputs = data.inputs,
  50. root = data.root;
  51. this.root = root || this.root;
  52. this.ServiceSystem.clean();
  53. this.ModuleSystem.clean();
  54. this.LinkManager.clean();
  55. this.RoutingSystem.clean();
  56. for (var i in inputs) {
  57. this.addInput(inputs[i]);
  58. }
  59. for (var i in outputs) {
  60. this.addOutput(outputs[i]);
  61. }
  62. for (var i in services) {
  63. this.ServiceSystem.loadService(services[i]);
  64. }
  65. for (var i in modules) {
  66. this.ModuleSystem.loadModule(modules[i]);
  67. }
  68. for (var i in links) {
  69. this.LinkManager.addLink(links[i]);
  70. }
  71. this.RoutingSystem.import(routes);
  72. this.refresh(true);
  73. }
  74. }, {
  75. key: "export",
  76. value: function _export() {
  77. var services = this.ServiceSystem.export(),
  78. modules = this.ModuleSystem.export(),
  79. links = this.LinkManager.export(),
  80. routes = this.RoutingSystem.export(),
  81. outputs = this.outputs,
  82. inputs = this.inputs;
  83. return {
  84. services: services,
  85. modules: modules,
  86. links: links,
  87. routes: routes,
  88. outputs: outputs,
  89. inputs: inputs,
  90. root: this.root
  91. };
  92. }
  93. }, {
  94. key: "addInput",
  95. value: function addInput(input) {
  96. input.pid = 'core';
  97. this.inputs[input.name] = input;
  98. this.inrefs[input.name] = this.LinkManager.addInputRef(input);
  99. this.refresh();
  100. }
  101. }, {
  102. key: "addOutput",
  103. value: function addOutput(output) {
  104. output.pid = 'core';
  105. this.outputs[output.name] = output;
  106. this.outrefs[output.name] = this.LinkManager.addOutputRef(output);
  107. this.refresh();
  108. }
  109. }, {
  110. key: "updateInput",
  111. value: function updateInput(input) {
  112. input.pid = 'core';
  113. this.inputs[input.name] = input;
  114. this.refresh();
  115. }
  116. }, {
  117. key: "updateOutput",
  118. value: function updateOutput(output) {
  119. output.pid = 'core';
  120. this.outputs[output.name] = output;
  121. this.refresh();
  122. }
  123. }, {
  124. key: "removeInput",
  125. value: function removeInput(name) {
  126. delete this.inputs[name];
  127. this.refresh(true);
  128. }
  129. }, {
  130. key: "removeOutput",
  131. value: function removeOutput(name) {
  132. delete this.outputs[name];
  133. this.refresh(true);
  134. }
  135. }, {
  136. key: "getInput",
  137. value: function getInput(name) {
  138. return this.inrefs[name];
  139. }
  140. }, {
  141. key: "getOutput",
  142. value: function getOutput(name) {
  143. return this.outrefs[name];
  144. }
  145. }, {
  146. key: "getLoadedModules",
  147. value: function getLoadedModules() {
  148. return _objectSpread({}, this.ModuleSystem.availableModules);
  149. }
  150. }, {
  151. key: "loadModule",
  152. value: function loadModule(mod) {
  153. this.ModuleSystem.loadModule(mod);
  154. this.refresh();
  155. }
  156. }, {
  157. key: "loadService",
  158. value: function loadService(mod) {
  159. this.ServiceSystem.loadService(mod);
  160. this.refresh();
  161. }
  162. }, {
  163. key: "refresh",
  164. value: function refresh() {
  165. var hard = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  166. var suppresedCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  167. this.ModuleSystem.refresh(hard, true);
  168. this.ServiceSystem.refresh(hard, true);
  169. this.LinkManager.clearLinks(_objectSpread({}, this.ModuleSystem.modules, this.ServiceSystem.modules));
  170. if (this._onUpdate && !suppresedCallback) this._onUpdate();
  171. }
  172. }, {
  173. key: "onUpdate",
  174. value: function onUpdate(fn) {
  175. this.ServiceSystem.onUpdate(fn);
  176. this.ModuleSystem.onUpdate(fn);
  177. this._onUpdate = fn;
  178. }
  179. }, {
  180. key: "clean",
  181. value: function clean() {
  182. this.ModuleSystem.clean();
  183. this.ServiceSystem.clean();
  184. this.LinkManager.clean();
  185. this.RoutingSystem.clean();
  186. }
  187. }, {
  188. key: "getRandom",
  189. value: function getRandom() {
  190. var r = parseInt(Math.random() * 1234567890) % 7654321; // check modules
  191. // check services
  192. return r;
  193. }
  194. }, {
  195. key: "go",
  196. value: function go(url, state) {
  197. var replace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  198. if (!this.RoutingSystem.goName(url)) {
  199. this.RoutingSystem.go(url, state, replace);
  200. if (replace) this.refresh();
  201. }
  202. this._routerState = state; //this.refresh(true);
  203. }
  204. }, {
  205. key: "render",
  206. value: function render() {
  207. this.RoutingSystem.resolve();
  208. this.root = this.RoutingSystem.getCurrentView();
  209. return [this.ServiceSystem.render(), this.ModuleSystem.render(this.root)];
  210. }
  211. }, {
  212. key: "renderModules",
  213. value: function renderModules() {
  214. this.RoutingSystem.resolve();
  215. this.root = this.RoutingSystem.getCurrentView(); // maybe i should take Routing System out of here beacause of subSystems
  216. return this.ModuleSystem.render(this.root);
  217. }
  218. }, {
  219. key: "renderServices",
  220. value: function renderServices() {
  221. return this.ServiceSystem.render();
  222. }
  223. }]);
  224. return CoreSystem;
  225. }();
  226. var _default = CoreSystem;
  227. exports.default = _default;