UNPKG

@chief-editor/flow

Version:

Old核心数据流

1 lines 2.83 kB
var __extends=this&&this.__extends||function(){var t=function(o,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var e in o)o.hasOwnProperty(e)&&(t[e]=o[e])})(o,e)};return function(o,e){function r(){this.constructor=o}t(o,e),o.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var o,e=1,r=arguments.length;e<r;e++)for(var n in o=arguments[e])Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n]);return t}).apply(this,arguments)};import{NestWatcher}from"@co-hooks/nest-watcher";import{deepClone}from"@co-hooks/util";import{Emitter}from"@co-hooks/emitter";import{bindDatasourceLoader}from"../datasource/bind";import{funcDatasourceLoader}from"../datasource/func";import{localDatasourceLoader}from"../datasource/local";import{FlowModel}from"./FlowModel";var FlowContext=function(t){function o(o){var e=o.context,r=void 0===e?{}:e,n=o.hooks,i=void 0===n?{}:n,s=o.loaders,c=void 0===s?{}:s,a=o.brickConfigs,p=void 0===a?{}:a,u=t.call(this)||this;return u.modelMap={},u.watcher=new NestWatcher,u.loaders={},u.context=r,u.hooks=i,u.brickConfigs=p,u.loaders=__assign({local:localDatasourceLoader,bind:bindDatasourceLoader,func:funcDatasourceLoader},c),u}return __extends(o,t),o.prototype.setContext=function(t,o){var e,r=this,n="string"==typeof t?o===this.context[t]?[]:[t]:Object.keys(t).filter((function(o){return r.context[o]!==t[o]}));"string"==typeof t?Object.assign(this.context,((e={})[t]=o,e)):Object.assign(this.context,t),n.length&&(this.watcher.notify(n.map((function(t){return NestWatcher.combineKeys(["context",t])}))),this.emit("context-change",n))},o.prototype.getContext=function(t,o){void 0===t&&(t=!1),void 0===o&&(o=!1),"boolean"==typeof t&&(o=t);var e="string"==typeof t?this.context[t]:this.context;return o?e:deepClone(e)},o.prototype.getHook=function(t){var o=this.hooks[t];return o||null},o.prototype.getHooks=function(){return this.hooks},o.prototype.getLoader=function(t,o){if(!this.loaders[t.type])throw new Error("loader name = "+t.type+" is not found");return this.loaders[t.type](o,t)},o.prototype.getBrickConfig=function(t){if(null==this.brickConfigs[t])throw new Error("Brick: "+t+" is not found");return this.brickConfigs[t]},o.prototype.getBrickConfigs=function(){return this.brickConfigs},o.prototype.getWatcher=function(){return this.watcher},o.prototype.createModel=function(t){return"string"==typeof t&&(t={name:t}),this.modelMap[t.name]&&console.error("duplicate model name:"+t.name),this.modelMap[t.name]=new FlowModel(__assign({context:this},t))},o.prototype.removeModel=function(t){this.modelMap[t].dispose(),delete this.modelMap[t]},o.prototype.getModel=function(t){return this.modelMap[t]},o}(Emitter);export{FlowContext};