-
Notifications
You must be signed in to change notification settings - Fork 3
/
flow.sea.min.js
16 lines (16 loc) · 12.2 KB
/
flow.sea.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
define("./index",["./util/class","./flow","./step","./condition","./input"],function(a,b,c){window.Flowjs={V:"0.4.2",Class:a("./util/class"),Flow:a("./flow"),Step:a("./step"),Condition:a("./condition"),Input:a("./input")}});
define("./util/class",["./baseobject"],function(a,b,c){var d=a("./baseobject"),e=function(a){var b=a.extend||d,c=function(){},f=a.plugins||[];c.prototype=b.prototype;var g=a.construct||function(){},h=a.properties||{},i=a.methods||{},j=a.statics||{},k=a.isAbstract===!0,l=new c,m;for(m in l)l.hasOwnProperty(m)&&delete l[m];for(m in h)l[m]=h[m];for(m in i)l[m]=i[m];for(var n=0;n<f.length;n++){var o=f[n];for(m in o)l[m]=o[m]}if(!k)for(var p in l)if(l[p]==e.abstractMethod)throw new Error("Abstract method ["+p+"] is not implement.");l.constructor=g,l.superclass=b,g.prototype=l;for(m in j)g[m]=j[m];return g};e.abstractMethod=function(){throw new Error("Not implement.")},c.exports=e});
define("./util/baseobject",[],function(a,b,c){var d=function(){},e={};e.superclass=Object,e.callsuper=function(a){var b=this,c;this._realsuper?this._realsuper=this._realsuper.prototype.superclass:this._realsuper=this.superclass,typeof a=="string"?(c=Array.prototype.slice.call(arguments,1),b._realsuper.prototype[a].apply(b,c)):(c=Array.prototype.slice.call(arguments,0),b._realsuper.apply(b,c)),this._realsuper=null},d.prototype=e,c.exports=d});
define("./flow",["./util/class","./util/eventPlugin","./util/deepExtend","./begin","./step","./input","./condition","./util/queue","./util/flowData","./util/tool"],function(a,b,c){var d=a("./util/class"),e=a("./util/eventPlugin"),f=a("./util/deepExtend"),g=a("./begin"),h=a("./step"),i=a("./input"),j=a("./condition"),k=a("./util/queue"),l=a("./util/flowData"),m=a("./util/tool"),n=[],o=d({plugins:[new e],construct:function(a){a=a||{},this.__begin=new g({description:"Begin",struct:{}}),this.__steps=a.steps||{},this.__stepInstances={},this.__queue=new k,this.__timer=null,this.__data=new l,this.__interfaces={},this.__pausing={},this.__working={},this.__stepCount=0,this.__subs={};for(var b in this)n.push(b)},isAbstract:!0,methods:{init:d.abstractMethod,implement:function(a,b){var c=d({extend:this.__steps[a],construct:b.construct||function(a){this.callsuper(a)},methods:b.methods});this.__stepInstances[a]=new c({description:a})},destroy:function(){var a=this.__stepInstances;for(var b in a)if(a.hasOwnProperty(b)){var c=a[b],d=this.__getStepData(c);try{c.destroy(d)}catch(e){}}},_go:function(a,b,c){var d=this;this.__timer&&this.__prev&&clearTimeout(this.__timer);if(typeof a=="string"){if(this.__subs[a]){this.__subs[a].apply(this,arguments);return}var e=a;a=this.__stepInstances[a]}if(a){c&&(a instanceof j&&!(a instanceof i)&&(c.newflow=this.__newflow.bind(this),a.cases(c),a.end()),a instanceof i&&(c.newflow=this.__newflow.bind(this),a.inputs(c))),a.__paramData=b,this.__prev||this.__queue.enqueue({step:a}),this.__prev&&this.__prev.next(a),this.__prev=a;if(this.__sync){var g=this.__getStepData(a);f(g,a.__paramData);try{this.__process(a,g)}catch(h){throw h}this.__timer=setTimeout(function(){a.end()},0)}else this.__timer=setTimeout(function(){a.end(),d.__start()},0)}else this.__timer=setTimeout(function(){d.__prev&&d.__prev.end(),d.__start()},0)},_sync:function(a){this.__sync=!0,a(),this.__sync=!1},_sub:function(a,b){this.__subs[a]=b},_addStep:function(a,b){this.__steps[a]=b},_addInterface:function(a,b){if(n.indexOf(a)!=-1)throw new Error("Reserve property : "+a);this[a]=function(){return this.__newflow(),b.apply(this,arguments)},this.__interfaces[a]=b},_getData:function(a){return this.__data.getData(a)},__newflow:function(){this.__prev=null},__start:function(){var a=this.__queue.dequeue();if(a){var b=this.__getStepData(a.step);f(b,a.step.__paramData),this.__process(a.step,b)}},__process:function(a,b){m.log("步骤开始:"+a.data().description),this.__working[a.data().__id]=a,this.__enter(a,b,function(b){m.log("步骤结束:"+a.data().description),delete this.__working[a.data().__id],b&&this.__saveData(b);if(!this.__sync){var c=this.__getNext(a);if(c){m.log("即将开始下一步:"+c.step.data().description),this.__stepCount++;if(this.__stepCount<20)this.__process(c.step,c.data);else{this.__stepCount=0;var d=this;setTimeout(function(){d.__process(c.step,c.data)},0)}}}})},__saveData:function(a){for(var b in a)a.hasOwnProperty(b)&&this.__data.setData(b,a[b])},__getNext:function(a){var b=a.__result,c=null,d=a.next();if(d){var e=this.__getStepData(d);f(e,d.__paramData),c={step:d,data:e}}return c},__getStepData:function(a){var b=a.getStruct(),c=[];if(b&&b.input)for(var d in b.input)b.input.hasOwnProperty(d)&&c.push(d);return f({},this.__data.getData(c))},__enter:function(a,b,c){var d=this,e={};f(e,b);var g=!1;a.enter(e,function(b,h){if(g)return;g=!0;var i=f({},h);for(var j in e)delete e[j];a.__result=i,c.call(d,i)})}}});c.exports=o});
define("./util/eventPlugin",["./class"],function(a,b,c){var d=a("./class"),e=d({methods:{on:function(a,b){this._ep_createList();var c=function(a){b(a)};return a=a.toLowerCase(),this._ep_lists[a]=this._ep_lists[a]||[],this._ep_lists[a].push({type:a,listener:b,realListener:c}),this},un:function(a,b){this._ep_createList();if(a){a=a.toLowerCase();var c=this._ep_lists[a];if(c){var d=c.length,e=!b;c&&c.length>0&&(e===!0?this._ep_lists[a]=[]:c.forEach(function(a,d){a.listener===b&&c.splice(d,1)}))}}else this._ep_clearList();return this},fire:function(a){this._ep_createList();var b=a.type.toLowerCase(),c=a.data,d=this._ep_lists[b];return d&&d.length>0&&d.forEach(function(a,d){a.listener({type:b,data:c})}),this},_ep_clearList:function(){this._ep_lists=null},_ep_createList:function(){this._ep_lists||(this._ep_lists={})}}});c.exports=e});
define("./util/deepExtend",["./isPlainObject"],function(a,b,c){var d=Array.isArray||function(a){return Object.prototype.toString.call(a)=="[object Array]"},e=function(a){return Object.prototype.toString.call(a)=="[object Object]"},f=a("./isPlainObject"),g=function(a,b){var c,h,i,j,k,l=1,m=arguments.length,n=a,o,p;if(!f(b))return b;h=b;if(e(h)||d(h))for(i in h){j=n[i],k=h[i];if(j===k)continue;k&&(e(k)||(o=d(k)))?(o?(o=!1,p=j&&d(j)?j:[]):p=j&&e(j)?j:{},n[i]=g(p,k)):k!==undefined&&(n[i]=k)}return n};c.exports=g});
define("./util/isPlainObject",[],function(a,b,c){var d=function(a){var b,c=Object.prototype.hasOwnProperty;if(typeof a!="object"||a==null)return!1;if(a.constructor&&!c.call(a,"constructor")&&!c.call(a.constructor.prototype,"isPrototypeOf"))return!1;for(b in a);return b===undefined||c.call(a,b)};c.exports=d});
define("./begin",["./util/class","./step"],function(a,b,c){var d=a("./util/class"),e=a("./step"),f=d({extend:e,construct:function(a){this.callsuper(a)},isAbstract:!0});c.exports=f});
define("./step",["./util/class","./util/eventPlugin","./util/checkData","./util/extend","./util/tool"],function(a,b,c){var d=a("./util/class"),e=a("./util/eventPlugin"),f=a("./util/checkData"),g=a("./util/extend"),h=a("./util/tool"),i=d({plugins:[new e],isAbstract:!0,construct:function(a){a=a||{},this._data={__id:(new Date).getTime(),description:a.description},this.__struct=this._describeData(),this.__next=null,this.__end=!1,this.__pausing=!1,this.__callback=null},methods:{enter:function(a,b){this.__pausing=!1;if(!this.__checkInput(a))throw new Error("Data error.");var c=this;this._process(a,function(a,d){if(!c.__checkOutput(d))throw new Error("Result error.");var e=function(){b(a,d)};c.__pausing?c.__callback=e:e()})},destroy:function(){},_process:d.abstractMethod,_describeData:function(){return{}},next:function(a){if(!a)return this.__next;this.isEnd()||(this.__next=a,this.end())},end:function(){this.__end=!0},isEnd:function(){return this.__end},data:function(a){if(arguments.length===0)return this._data;g(this._data,a)},getStruct:function(){return this.__struct},pause:function(){this.__pausing=!0},resume:function(){this.__pausing=!1,this.__callback&&this.__callback()},__checkInput:function(a){return h.log("Check","input data for",this._data.description),f.check(this.__struct.input,a)},__checkOutput:function(a){return h.log("Check","output data for",this._data.description),f.check(this.__struct.output,a)}}});c.exports=i});
define("./util/checkData",["./tool"],function(a,b,c){var d=a("./tool");c.exports={check:function(a,b){var c=this;if(!a)return!0;var e=!0,f,g;for(g in b)if(!a.hasOwnProperty(g)){delete b[g];continue}for(g in a){var h=a[g];if(a[g].empty!==!0&&c.isEmpty(a[g],b[g]))throw f="字段["+g+"]值为空",d.error(f),new Error(f);if(a[g].empty===!0&&c.isEmpty(a[g],b[g]))continue;if(a[g].type=="number"&&typeof b[g]!="number")throw f="字段["+g+"]不是数字",d.error(f),new Error(f);if(a[g].type=="string"&&typeof b[g]!="string")throw f="字段["+g+"]不是字符串",d.error(f),new Error(f);if(a[g].type=="array"){if(!c.checkArray(a[g],b[g]))throw f="字段["+g+"]值与定义不符",d.error(f),new Error(f)}else if(a[g].type=="object"&&!c.checkObject(a[g].struct,b[g]))throw f="字段["+g+"]值与定义不符",d.error(f),new Error(f)}return e},checkArray:function(a,b){var c=this;if(d.isArray(b)){for(var e=0;e<b.length;e++){var f=b[e];if(a.item&&!c.checkData(a.item,f))return!1}return!0}return!1},checkObject:function(a,b){return this.check(a,b)},isEmpty:function(a,b){return b===undefined?!0:a.type=="object"?b===null:a.type=="array"?b.length===0:b===""||b===undefined||b===null},checkData:function(a,b){return a.type=="number"&&typeof b=="number"?!0:a.type=="string"&&typeof b=="string"?!0:a.type=="boolean"&&typeof b=="boolean"?!0:a.type=="array"?this.checkArray(a.item,b):a.type=="object"?this.checkObject(a.struct,b):!1}}});
define("./util/tool",[],function(a,b,c){c.exports={isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)=="[object Array]"},log:function(){if(window.console)if(console.log.apply)console.log.apply(console,arguments);else{var a=Array.prototype.slice.call(arguments,0),b=a.join(" ");console.log(b)}},error:function(){if(window.console)if(console.error.apply)console.error.apply(console,arguments);else{var a=Array.prototype.slice.call(arguments,0),b=a.join(" ");console.error(b)}}}});
define("./util/extend",[],function(a,b,c){var d=function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a};c.exports=d});
define("./input",["./util/class","./condition","./util/extend"],function(a,b,c){var d=a("./util/class"),e=a("./condition"),f=a("./util/extend"),g=d({extend:e,construct:function(a){a=a||{},this.callsuper(a),this._inputs=a.inputs||{},this._binded=!1},isAbstract:!0,methods:{_once:function(a){this._binded||(this._binded=!0,a())},inputs:function(a){var b={};return b.cases=a.inputs,a.newflow&&(this._newflow=a.newflow),this.cases(b)}}});c.exports=g});
define("./condition",["./util/class","./step","./util/extend"],function(a,b,c){var d=a("./util/class"),e=a("./step"),f=a("./util/extend"),g=d({extend:e,construct:function(a){a=a||{},this.callsuper(a),this._cases=a.cases||{},this._default=a.defaultCase},isAbstract:!0,methods:{_select:function(a,b){var c=this._cases[a]||this._default,d=this;setTimeout(function(){d._newflow&&d._newflow(),c(b)},0)},cases:function(a){if(!a)return{defaultCase:this._default,cases:this._cases};a.cases&&f(this._cases,a.cases),a.defaultCase&&(this._default=a.defaultCase),a.newflow&&(this._newflow=a.newflow)}}});c.exports=g});
define("./util/queue",["./class"],function(a,b,c){var d=a("./class");c.exports=d({construct:function(){this._queue=[],this._event={}},methods:{enqueue:function(a){this._queue.push(a)},dequeue:function(){var a=this;return this._queue.length===0?(this.end(),null):this._queue.splice(0,1)[0]},isEmpty:function(){return this._queue.length===0},end:function(a){this.fire("end",a)},on:function(a,b){this._event[a]||(this._event[a]=[]),this._event[a].push(b)},fire:function(a,b){if(this._event[a])for(var c=0;c<this._event[a].length;c++)this._event[a][c](b)},clear:function(){this._queue=[]}}})});
define("./util/flowData",["./class","./tool","./deepExtend"],function(a,b,c){var d=a("./class"),e=a("./tool"),f=a("./deepExtend"),g=Array.isArray||function(a){return Object.prototype.toString.call(a)=="[object Array]"},h=function(a){return Object.prototype.toString.call(a)=="[object Object]"},i=d({construct:function(a){this._data={}},methods:{getData:function(a){var b={},c=(new Date).getTime();if(e.isArray(a)){var d=a.length;for(var f=0;f<d;f++){var g=a[f];this._data.hasOwnProperty(g)&&(b[g]=this._data[g])}return b}return this._data[a.toString()]},setData:function(a,b){return h(b)||g(b)?this._data[a]=f(this._data[a]||{},b):this._data[a]=b,!1}}});c.exports=i});