react 0.5.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.travis.yml +5 -0
  2. package/Jakefile.js +39 -0
  3. package/README.md +15 -23
  4. package/browser-test/dist.html +90 -0
  5. package/browser-test/index.html +86 -0
  6. package/browser-test/min.html +90 -0
  7. package/dist/react.js +3107 -0
  8. package/dist/react.min.js +22 -0
  9. package/doc/advanced.md +10 -2
  10. package/examples/using-events1.js +1 -1
  11. package/lib/base-task.js +116 -110
  12. package/lib/cb-task.js +71 -67
  13. package/lib/core.js +116 -117
  14. package/lib/dsl.js +120 -115
  15. package/lib/error.js +44 -36
  16. package/lib/event-collector.js +69 -56
  17. package/lib/event-manager.js +81 -67
  18. package/lib/eventemitter.js +20 -0
  19. package/lib/finalcb-first-task.js +56 -53
  20. package/lib/finalcb-task.js +55 -51
  21. package/lib/id.js +18 -7
  22. package/lib/input-parser.js +49 -41
  23. package/lib/log-events.js +88 -73
  24. package/lib/parse.js +34 -25
  25. package/lib/promise-resolve.js +42 -27
  26. package/lib/promise-task.js +78 -74
  27. package/lib/react.js +59 -0
  28. package/lib/ret-task.js +59 -55
  29. package/lib/sprintf.js +18 -0
  30. package/lib/status.js +11 -2
  31. package/lib/task.js +215 -217
  32. package/lib/track-tasks.js +72 -58
  33. package/lib/validate.js +136 -136
  34. package/lib/vcon.js +78 -69
  35. package/lib/when-task.js +69 -65
  36. package/package.json +10 -9
  37. package/src/dist.build.requirejs +20 -0
  38. package/test/ast.mocha.js +136 -0
  39. package/test/cb-task.mocha.js +220 -0
  40. package/test/core-deferred.mocha.js +143 -0
  41. package/test/core-when.mocha.js +96 -0
  42. package/test/core.mocha.js +589 -0
  43. package/test/dsl.mocha.js +350 -0
  44. package/test/event-manager.mocha.js +119 -0
  45. package/test/exec-options.mocha.js +48 -0
  46. package/test/finalcb-task.mocha.js +58 -0
  47. package/test/input-parser.mocha.js +86 -0
  48. package/test/log-events.mocha.js +88 -0
  49. package/test/mocha.opts +2 -0
  50. package/test/module-use.mocha.js +147 -0
  51. package/test/promise-auto-resolve.mocha.js +68 -0
  52. package/test/ret-task.mocha.js +220 -0
  53. package/test/task.mocha.js +42 -0
  54. package/test/validate-cb-task.mocha.js +100 -0
  55. package/test/validate-ret-task.mocha.js +110 -0
  56. package/test/validate.mocha.js +324 -0
  57. package/test/vcon.mocha.js +193 -0
  58. package/vendor/chai/chai.js +2038 -0
  59. package/vendor/jquery/jquery-1.7.1.js +9266 -0
  60. package/vendor/jquery/jquery-1.7.1.min.js +4 -0
  61. package/vendor/mocha/mocha.css +135 -0
  62. package/vendor/mocha/mocha.js +3589 -0
  63. package/vendor/node/util.js +531 -0
  64. package/vendor/requirejs/require.js +2053 -0
  65. package/vendor/requirejs/require.min.js +33 -0
  66. package/react.js +0 -40
  67. package/test/ast.test.js +0 -118
  68. package/test/cb-task.test.js +0 -197
  69. package/test/core-deferred.test.js +0 -134
  70. package/test/core-promised.test.js +0 -132
  71. package/test/core-when.test.js +0 -84
  72. package/test/core.test.js +0 -593
  73. package/test/dsl.test.js +0 -330
  74. package/test/event-manager.test.js +0 -102
  75. package/test/exec-options.test.js +0 -33
  76. package/test/finalcb-task.test.js +0 -38
  77. package/test/input-parser.test.js +0 -66
  78. package/test/module-use.test.js +0 -134
  79. package/test/promise-auto-resolve.test.js +0 -52
  80. package/test/ret-task.test.js +0 -199
  81. package/test/task.test.js +0 -21
  82. package/test/validate-cb-task.test.js +0 -74
  83. package/test/validate-ret-task.test.js +0 -83
  84. package/test/validate.test.js +0 -295
  85. package/test/vcon.test.js +0 -173
@@ -0,0 +1,22 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ !function(e,t){function i(){this._events=new Object}function s(e){e&&(e.delimiter&&(this.delimiter=e.delimiter),e.wildcard&&(this.wildcard=e.wildcard),this.wildcard&&(this.listenerTree=new Object))}function o(e){this._events=new Object,s.call(this,e)}function u(e,t,n,r){if(!n)return[];var i=[],s,o,a,f,l,c,h,p=t.length,d=t[r],v=t[r+1];if(r===p&&n._listeners){if(typeof n._listeners=="function")return e&&e.push(n._listeners),[n];for(s=0,o=n._listeners.length;s<o;s++)e&&e.push(n._listeners[s]);return[n]}if(d==="*"||d==="**"||n[d]){if(d==="*"){for(a in n)a!=="_listeners"&&n.hasOwnProperty(a)&&(i=i.concat(u(e,t,n[a],r+1)));return i}if(d==="**"){h=r+1===p||r+2===p&&v==="*",h&&n._listeners&&(i=i.concat(u(e,t,n,p)));for(a in n)a!=="_listeners"&&n.hasOwnProperty(a)&&(a==="*"||a==="**"?(n[a]._listeners&&!h&&(i=i.concat(u(e,t,n[a],p))),i=i.concat(u(e,t,n[a],r))):a===v?i=i.concat(u(e,t,n[a],r+2)):i=i.concat(u(e,t,n[a],r)));return i}i=i.concat(u(e,t,n[d],r+1))}f=n["*"],f&&u(e,t,f,r+1),l=n["**"];if(l)if(r<p){l._listeners&&u(e,t,l,p);for(a in l)a!=="_listeners"&&l.hasOwnProperty(a)&&(a===v?u(e,t,l[a],r+2):a===d?u(e,t,l[a],r+1):(c={},c[a]=l[a],u(e,t,{"**":c},r+1)))}else l._listeners?u(e,t,l,p):l["*"]&&l["*"]._listeners&&u(e,t,l["*"],p);return i}function a(e,t){e=typeof e=="string"?e.split(this.delimiter):e.slice();for(var i=0,s=e.length;i+1<s;i++)if(e[i]==="**"&&e[i+1]==="**")return;var o=this.listenerTree,u=e.shift();while(u){o[u]||(o[u]=new Object),o=o[u];if(e.length===0){if(!o._listeners)o._listeners=t;else if(typeof o._listeners=="function")o._listeners=[o._listeners,t];else if(n(o._listeners)){o._listeners.push(t);if(!o._listeners.warned){var a=r;typeof this._events.maxListeners!="undefined"&&(a=this._events.maxListeners),a>0&&o._listeners.length>a&&(o._listeners.warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",o._listeners.length),console.trace())}}return!0}u=e.shift()}return!0}var n=Array.isArray?Array.isArray:function(t){return Object.prototype.toString.call(t)==="[object Array]"},r=10;o.prototype.delimiter=".",o.prototype.setMaxListeners=function(e){this._events||i.call(this),this._events.maxListeners=e},o.prototype.event="",o.prototype.once=function(e,t){return this.many(e,1,t),this},o.prototype.many=function(e,t,n){function i(){--t===0&&r.off(e,i),n.apply(this,arguments)}var r=this;if(typeof n!="function")throw new Error("many only accepts instances of Function");return i._origin=n,this.on(e,i),r},o.prototype.emit=function(){this._events||i.call(this);var e=arguments[0];if(e==="newListener"&&!this._events.newListener)return!1;if(this._all){var t=arguments.length,n=new Array(t-1);for(var r=1;r<t;r++)n[r-1]=arguments[r];for(r=0,t=this._all.length;r<t;r++)this.event=e,this._all[r].apply(this,n)}if(e==="error"&&!this._all&&!this._events.error&&(!this.wildcard||!this.listenerTree.error))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");var s;if(this.wildcard){s=[];var o=typeof e=="string"?e.split(this.delimiter):e.slice();u.call(this,s,o,this.listenerTree,0)}else s=this._events[e];if(typeof s=="function"){this.event=e;if(arguments.length===1)s.call(this);else if(arguments.length>1)switch(arguments.length){case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:var t=arguments.length,n=new Array(t-1);for(var r=1;r<t;r++)n[r-1]=arguments[r];s.apply(this,n)}return!0}if(s){var t=arguments.length,n=new Array(t-1);for(var r=1;r<t;r++)n[r-1]=arguments[r];var a=s.slice();for(var r=0,t=a.length;r<t;r++)this.event=e,a[r].apply(this,n);return a.length>0||this._all}return this._all},o.prototype.on=function(e,t){if(typeof e=="function")return this.onAny(e),this;if(typeof t!="function")throw new Error("on only accepts instances of Function");this._events||i.call(this),this.emit("newListener",e,t);if(this.wildcard)return a.call(this,e,t),this;if(!this._events[e])this._events[e]=t;else if(typeof this._events[e]=="function")this._events[e]=[this._events[e],t];else if(n(this._events[e])){this._events[e].push(t);if(!this._events[e].warned){var s=r;typeof this._events.maxListeners!="undefined"&&(s=this._events.maxListeners),s>0&&this._events[e].length>s&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),console.trace())}}return this},o.prototype.onAny=function(e){this._all||(this._all=[]);if(typeof e!="function")throw new Error("onAny only accepts instances of Function");return this._all.push(e),this},o.prototype.addListener=o.prototype.on,o.prototype.off=function(e,t){if(typeof t!="function")throw new Error("removeListener only takes instances of Function");var r,i=[];if(this.wildcard){var s=typeof e=="string"?e.split(this.delimiter):e.slice();i=u.call(this,null,s,this.listenerTree,0)}else{if(!this._events[e])return this;r=this._events[e],i.push({_listeners:r})}for(var o=0;o<i.length;o++){var a=i[o];r=a._listeners;if(n(r)){var f=-1;for(var l=0,c=r.length;l<c;l++)if(r[l]===t||r[l].listener&&r[l].listener===t||r[l]._origin&&r[l]._origin===t){f=l;break}if(f<0)return this;this.wildcard?a._listeners.splice(f,1):this._events[e].splice(f,1),r.length===0&&(this.wildcard?delete a._listeners:delete this._events[e])}else if(r===t||r.listener&&r.listener===t||r._origin&&r._origin===t)this.wildcard?delete a._listeners:delete this._events[e]}return this},o.prototype.offAny=function(e){var t=0,n=0,r;if(e&&this._all&&this._all.length>0){r=this._all;for(t=0,n=r.length;t<n;t++)if(e===r[t])return r.splice(t,1),this}else this._all=[];return this},o.prototype.removeListener=o.prototype.off,o.prototype.removeAllListeners=function(e){if(arguments.length===0)return!this._events||i.call(this),this;if(this.wildcard){var t=typeof e=="string"?e.split(this.delimiter):e.slice(),n=u.call(this,null,t,this.listenerTree,0);for(var r=0;r<n.length;r++){var s=n[r];s._listeners=null}}else{if(!this._events[e])return this;this._events[e]=null}return this},o.prototype.listeners=function(e){if(this.wildcard){var t=[],r=typeof e=="string"?e.split(this.delimiter):e.slice();return u.call(this,t,r,this.listenerTree,0),t}return this._events||i.call(this),this._events[e]||(this._events[e]=[]),n(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]},o.prototype.listenersAny=function(){return this._all?this._all:[]},typeof define=="function"&&define.amd?define("eventemitter2",[],function(){return o}):e.EventEmitter2=o}(typeof process!="undefined"&&typeof process.title!="undefined"&&typeof exports!="undefined"?exports:window),define("react/eventemitter",["eventemitter2"],function(e){var t=e?e.EventEmitter2?e.EventEmitter2:e:EventEmitter2;return t}),define("util",["require","exports","module"],function(e,t,n){function s(e,t,n,r){var i={showHidden:t,seen:[],stylize:r?a:f};return l(i,e,typeof n=="undefined"?2:n)}function a(e,t){var n=u[t];return n?"["+o[n][0]+"m"+e+"["+o[n][1]+"m":e}function f(e,t){return e}function l(e,n,r){if(n&&typeof n.inspect=="function"&&n.inspect!==t.inspect&&(!n.constructor||n.constructor.prototype!==n))return n.inspect(r);var i=c(e,n);if(i)return i;var s=Object.keys(n),o=e.showHidden?Object.getOwnPropertyNames(n):s;if(o.length===0){if(typeof n=="function"){var u=n.name?": "+n.name:"";return e.stylize("[Function"+u+"]","special")}if(g(n))return e.stylize(RegExp.prototype.toString.call(n),"regexp");if(y(n))return e.stylize(Date.prototype.toString.call(n),"date");if(b(n))return h(n)}var a="",f=!1,l=["{","}"];m(n)&&(f=!0,l=["[","]"]);if(typeof n=="function"){var w=n.name?": "+n.name:"";a=" [Function"+w+"]"}g(n)&&(a=" "+RegExp.prototype.toString.call(n)),y(n)&&(a=" "+Date.prototype.toUTCString.call(n)),b(n)&&(a=" "+h(n));if(o.length!==0||!!f&&n.length!==0){if(r<0)return g(n)?e.stylize(RegExp.prototype.toString.call(n),"regexp"):e.stylize("[Object]","special");e.seen.push(n);var E;return f?E=p(e,n,r,s,o):E=o.map(function(t){return d(e,n,r,s,t,f)}),e.seen.pop(),v(E,a,l)}return l[0]+a+l[1]}function c(e,t){switch(typeof t){case"undefined":return e.stylize("undefined","undefined");case"string":var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string");case"number":return e.stylize(""+t,"number");case"boolean":return e.stylize(""+t,"boolean")}if(t===null)return e.stylize("null","null")}function h(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,n,r,i){var s=[];for(var o=0,u=t.length;o<u;++o)Object.prototype.hasOwnProperty.call(t,String(o))?s.push(d(e,t,n,r,String(o),!0)):s.push("");return i.forEach(function(i){i.match(/^\d+$/)||s.push(d(e,t,n,r,i,!0))}),s}function d(e,t,n,r,i,s){var o,u,a;a=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},a.get?a.set?u=e.stylize("[Getter/Setter]","special"):u=e.stylize("[Getter]","special"):a.set&&(u=e.stylize("[Setter]","special")),r.indexOf(i)<0&&(o="["+i+"]"),u||(e.seen.indexOf(a.value)<0?(n===null?u=l(e,a.value,null):u=l(e,a.value,n-1),u.indexOf("\n")>-1&&(s?u=u.split("\n").map(function(e){return" "+e}).join("\n").substr(2):u="\n"+u.split("\n").map(function(e){return" "+e}).join("\n"))):u=e.stylize("[Circular]","special"));if(typeof o=="undefined"){if(s&&i.match(/^\d+$/))return u;o=JSON.stringify(""+i),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+u}function v(e,t,n){var r=0,i=e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.length+1},0);return i>60?n[0]+(t===""?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function m(e){return Array.isArray(e)||typeof e=="object"&&w(e)==="[object Array]"}function g(e){return typeof e=="object"&&w(e)==="[object RegExp]"}function y(e){return typeof e=="object"&&w(e)==="[object Date]"}function b(e){return typeof e=="object"&&w(e)==="[object Error]"}function w(e){return Object.prototype.toString.call(e)}function E(e){return e<10?"0"+e.toString(10):e.toString(10)}function x(){var e=new Date,t=[E(e.getHours()),E(e.getMinutes()),E(e.getSeconds())].join(":");return[e.getDate(),S[e.getMonth()],t].join(" ")}var r=/%[sdj%]/g;t.format=function(e){if(typeof e!="string"){var t=[];for(var n=0;n<arguments.length;n++)t.push(s(arguments[n]));return t.join(" ")}var i=1,o=arguments,u=o.length,a=String(e).replace(r,function(e){if(e==="%%")return"%";if(i>=u)return e;switch(e){case"%s":return String(o[i++]);case"%d":return Number(o[i++]);case"%j":return JSON.stringify(o[i++]);default:return e}});for(var f=o[i];i<u;f=o[++i])f===null||typeof f!="object"?a+=" "+f:a+=" "+s(f);return a},t.print=function(){for(var e=0,t=arguments.length;e<t;++e)process.stdout.write(String(arguments[e]))},t.puts=function(){for(var e=0,t=arguments.length;e<t;++e)process.stdout.write(arguments[e]+"\n")},t.debug=function(e){process.stderr.write("DEBUG: "+e+"\n")};var i=t.error=function(e){for(var t=0,n=arguments.length;t<n;++t)process.stderr.write(arguments[t]+"\n")};t.inspect=s;var o={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},u={special:"cyan",number:"yellow","boolean":"yellow","undefined":"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};t.isArray=m,t.isRegExp=g,t.isDate=y,t.isError=b;var S=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];t.log=function(e){t.puts(x()+" - "+e.toString())},t.pump=function(e,t,n){function i(e,t,i){n&&!r&&(n(e,t,i),r=!0)}var r=!1;e.addListener("data",function(n){t.write(n)===!1&&e.pause()}),t.addListener("drain",function(){e.resume()}),e.addListener("end",function(){t.end()}),e.addListener("close",function(){i()}),e.addListener("error",function(e){t.end(),i(e)}),t.addListener("error",function(t){e.destroy(),i(t)})},t.inherits=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},t._extend=function(e,t){if(!t)return e;var n=Object.keys(t),r=n.length;while(r--)e[n[r]]=t[n[r]];return e}}),define("react/error",["util"],function(e){function t(e){if(!Error.stackTraceLimit||Error.stackTraceLimit<e)Error.stackTraceLimit=e}function n(e){return e?e&&e.name?e.name:e:"undefined"}function r(t){if(!t.meta)return;var r=t.meta.vcon,i=t.meta.task,s="\n\n";return i&&i.f&&i.a&&(s+="Error occurs in Task function: "+n(i.f)+"("+i.a.join(",")+")\n\n"),r&&(s+="Variable Context: \n",s+=e.inspect(r),s+="\n\n"),i&&i.f&&(s+="Task Source:\n\n",s+=i.f.toString(),s+="\n\n"),s}function i(e,t){typeof e=="string"&&(e=new Error(e));var n=e.toString();return e.meta=t,e.toString=function(){return n+r(e)},e}return{ensureStackTraceLimitSet:t,augmentError:i}}),define("react/sprintf",["util"],function(e){var t=e.format;return t}),function(e,t){typeof exports=="object"?module.exports=t():typeof define=="function"&&define.amd?define("ensure-array",[],t):e.ensureArray=t()}(this,function(){function e(e,t,n){if(arguments.length===0)return[];if(arguments.length===1){if(e===undefined||e===null)return[];if(Array.isArray(e))return e}return Array.prototype.slice.call(arguments)}return e}),define("react/status",[],function(){var e={READY:"ready",RUNNING:"running",ERRORED:"errored",COMPLETE:"complete"};return e}),define("react/event-manager",["./eventemitter"],function(e){function i(){}var t={wildcard:!0,delimiter:".",maxListeners:30},n=/^ast.defined$/,r={AST_DEFINED:"ast.defined",FLOW_BEGIN:"flow.begin",TASK_BEGIN:"task.begin",TASK_COMPLETE:"task.complete",TASK_ERRORED:"task.errored",FLOW_COMPLETE:"flow.complete",FLOW_ERRORED:"flow.errored",EXEC_FLOW_START:"exec.flow.start",EXEC_INPUT_PREPROCESS:"exec.input.preprocess",EXEC_TASKS_PRECREATE:"exec.tasks.precreate",EXEC_OUTTASK_CREATE:"exec.outTask.create",EXEC_TASK_START:"exec.task.start",EXEC_TASK_COMPLETE:"exec.task.complete",EXEC_TASK_ERRORED:"exec.task.errored",EXEC_FLOW_COMPLETE:"exec.flow.complete",EXEC_FLOW_ERRORED:"exec.flow.errored"};return i.create=function(){return new i},i.TYPES=r,i.prototype.TYPES=r,i.prototype.isEnabled=function(){return!!(this.emitter||this.parent&&this.parent.isEnabled())},i.prototype.on=function(n,r){this.emitter||(this.emitter=new e(t)),n==="*"?this.emitter.onAny(r):this.emitter.on(n,r)},i.prototype.emit=function(e,t,r,i){if(e===undefined)throw new Error("event is undefined");this.emitter&&this.emitter.emit.apply(this.emitter,arguments),this.parent&&this.parent.isEnabled()&&this.parent.emit.apply(this.parent,arguments),n.test(e)&&typeof process!="undefined"&&process.emit&&process.emit.apply(process,arguments)},i.prototype.removeListener=function(e,t){this.emitter&&this.emitter.removeListener.apply(this.emitter,arguments)},i.prototype.removeAllListeners=function(e){this.emitter&&this.emitter.removeAllListeners.apply(this.emitter,arguments)},i.global=i.create(),i}),define("react/base-task",["ensure-array","./status","./event-manager"],function(e,t,n){function r(){}function i(e){return e.indexOf(".")!==-1}return r.prototype.getOutParams=function(){return e(this.out)},r.prototype.isComplete=function(){return this.status===t.COMPLETE},r.prototype.start=function(e){this.args=e,this.env.currentTask=this,this.env.flowEmitter.emit(n.TYPES.EXEC_TASK_START,this)},r.prototype.complete=function(e){this.status=t.COMPLETE,this.results=e,this.env.currentTask=this,this.env.flowEmitter.emit(n.TYPES.EXEC_TASK_COMPLETE,this)},r.prototype.functionExists=function(e){var t=this.f;if(!t)return!1;if(t instanceof Function)return!0;if(typeof t=="string"){var n=e.getVar(t);if(n&&n instanceof Function)return!0}return!1},r.prototype.areAllDepArgsDefined=function(e){return this.a.every(function(t){return e.getVar(t)!==undefined})},r.prototype.depTasksAreDone=function(e){return!this.after||!this.after.length||this.after.every(function(t){return e[t].isComplete()})},r.prototype.parentExists=function(e,t){if(!i(e))return!0;var n=e.split(".");n.pop();var r=n.reduce(function(e,t){return e===undefined||e===null?undefined:e[t]},t.values);return r!==undefined&&r!==null},r.prototype.outParentsExist=function(e){var t=this;return this.getOutParams().every(function(n){return n===null?!0:t.parentExists(n,e)})},r.prototype.isReady=function(e,t){return!this.status&&this.functionExists(e)&&this.areAllDepArgsDefined(e)&&this.depTasksAreDone(t)&&(!this.outParentsExist||this.outParentsExist(e))},r.prototype.isMethodCall=function(){return typeof this.f=="string"&&/^.*\..*$/.test(this.f)},r.prototype.getMethodObj=function(e){var t=this.f;if(!t)return undefined;var n=t.split(".");n.pop();if(!n.length)return undefined;var r=n.reduce(function(e,t){return e===undefined||e===null?undefined:e[t]},e.values);return r},r}),define("react/cb-task",["util","./sprintf","./base-task"],function(e,t,n){function r(n,r){return t("%s - %s",n,e.inspect(r))}function a(e){var t=this;Object.keys(e).forEach(function(n){t[n]=e[n]})}var i="cbTask requires f, a, out",s="cbTask requires f to be a function or string",o="cbTask requires a to be an array of string param names",u="cbTask requires out to be an array of string param names";return a.prototype=new n,a.prototype.constructor=a,a.validate=function(e){var t=[];if(!e.f||!e.a||!e.out)t.push(r(i,e));else{var n=typeof e.f;e.f instanceof Function||n==="string"||t.push(r(s,e)),(!Array.isArray(e.a)||!e.a.every(function(e){return typeof e=="string"}))&&t.push(r(o,e)),(!Array.isArray(e.out)||!e.out.every(function(e){return typeof e=="string"}))&&t.push(r(u,e))}return t},a.prototype.prepare=function(t,n,r){var i=this;this.cbFun=function(e,s,o,u){var a=Array.prototype.slice.call(arguments,1);if(e){t(i,e);return}n.saveResults(i.out,a),i.complete(a),r()}},a.prototype.exec=function(t,n,r){try{var i=this.a.map(function(e){return t.getVar(e)});this.start(i),i.push(this.cbFun);var s=this.f,o=t.getVar("this");this.isMethodCall()?(s=t.getVar(this.f),o=this.getMethodObj(t)):typeof s=="string"&&(s=t.getVar(s)),s.apply(o,i)}catch(u){n(this,u)}},a}),define("react/promise-task",["util","./sprintf","./base-task"],function(e,t,n){function r(n,r){return t("%s - %s",n,e.inspect(r))}function a(e){var t=this;Object.keys(e).forEach(function(n){t[n]=e[n]})}var i="promiseTask requires f, a, out",s="promiseTask requires f to be a function or string",o="promiseTask requires a to be an array of string param names",u="promiseTask requires out to be an array[1] of string param names";return a.prototype=new n,a.prototype.constructor=a,a.validate=function(e){var t=[];if(!e.f||!e.a||!e.out)t.push(r(i,e));else{var n=typeof e.f;e.f instanceof Function||n==="string"||t.push(r(s,e)),(!Array.isArray(e.a)||!e.a.every(function(e){return typeof e=="string"}))&&t.push(r(o,e)),Array.isArray(e.out)&&e.out.length<=1&&e.out.every(function(e){return typeof e=="string"})||t.push(r(u,e))}return t},a.prototype.prepare=function(t,n,r){var i=this;this.nextFn=function(e){var t=Array.prototype.slice.call(arguments);n.saveResults(i.out,t),i.complete(t),r()},this.failFn=function(e){t(i,e)}},a.prototype.exec=function(t,n,r){try{var i=this.a.map(function(e){return t.getVar(e)});this.start(i);var s=this.f,o=t.getVar("this");this.isMethodCall()?(s=t.getVar(this.f),o=this.getMethodObj(t)):typeof s=="string"&&(s=t.getVar(s));var u=s.apply(o,i);u&&typeof u.then=="function"?u.then(this.nextFn,this.failFn):this.nextFn(u)}catch(a){n(this,a)}},a}),define("react/ret-task",["util","./sprintf","./base-task"],function(e,t,n){function r(n,r){return t("%s - %s",n,e.inspect(r))}function a(e){var t=this;Object.keys(e).forEach(function(n){t[n]=e[n]})}var i="retTask requires f, a, out",s="retTask requires f to be a function or string",o="retTask requires a to be an array of string param names",u="retTask requires out to be an array with single string param name or []";return a.prototype=new n,a.prototype.constructor=a,a.validate=function(e){var t=[];if(!e.f||!e.a||!e.out)t.push(r(i,e));else{var n=typeof e.f;e.f instanceof Function||n==="string"||t.push(r(s,e)),(!Array.isArray(e.a)||!e.a.every(function(e){return typeof e=="string"}))&&t.push(r(o,e)),(!Array.isArray(e.out)||!(e.out.length===0||e.out.length===1&&typeof (e.out[0]==="string")))&&t.push(r(u,e))}return t},a.prototype.exec=function(t,n,r){try{var i=this.a.map(function(e){return t.getVar(e)});this.start(i);var s=this.f,o=t.getVar("this");this.isMethodCall()?(s=t.getVar(this.f),o=this.getMethodObj(t)):typeof s=="string"&&(s=t.getVar(s));var u=[s.apply(o,i)];t.saveResults(this.out,u),this.complete(u),r()}catch(a){n(this,a)}},a}),define("react/when-task",["util","./sprintf","./base-task"],function(e,t,n){function r(n,r){return t("%s - %s",n,e.inspect(r))}function u(e){var t=this;Object.keys(e).forEach(function(n){t[n]=e[n]})}var i="whenTask requires a, out",s="whenTask requires a to be an array[1] of string param names",o="whenTask requires out to be an array[1] of string param names";return u.prototype=new n,u.prototype.constructor=u,u.prototype.f=function(){},u.validate=function(e){var t=[];return!e.a||!e.out?t.push(r(i,e)):((!Array.isArray(e.a)||e.a.length!==1||!e.a.every(function(e){return typeof e=="string"}))&&t.push(r(s,e)),Array.isArray(e.out)&&e.out.length<=1&&e.out.every(function(e){return typeof e=="string"})||t.push(r(o,e))),t},u.prototype.prepare=function(t,n,r){var i=this;this.nextFn=function(e){var t=Array.prototype.slice.call(arguments);n.saveResults(i.out,t),i.complete(t),r()},this.failFn=function(e){t(i,e)}},u.prototype.exec=function(t,n,r){try{var i=this.a.map(function(e){return t.getVar(e)});this.start(i);var s=i[0];s&&typeof s.then=="function"?s.then(this.nextFn,this.failFn):this.nextFn(s)}catch(o){n(this,o)}},u}),define("react/finalcb-task",["./sprintf","util","./status","./event-manager"],function(e,t,n,r){function s(e){var t=e.taskDef;if(typeof e.cbFunc!="function")throw new Error("callback is not a function");var n=this;for(var r in t)n[r]=t[r];this.f=e.cbFunc,this.tasks=e.tasks,this.vCon=e.vCon,this.retValue=e.retValue,this.execOptions=e.execOptions,this.env=e.env}function o(n,r){return e("%s - %s",n,t.inspect(r))}var i="ast.outTask.a should be an array of string param names";return s.validate=function(e){var t=[];return(!Array.isArray(e.a)||!e.a.every(function(e){return typeof e=="string"}))&&t.push(o(i,e)),t},s.prototype.isReady=function(){return this.tasks.every(function(e){return e.status===n.COMPLETE})},s.prototype.exec=function(e){if(!this.f)return;if(e)this.env.error=e,this.env.flowEmitter.emit(r.TYPES.EXEC_FLOW_ERRORED,this.env),this.f.call(null,e);else{var t=this.vCon,n=this.a.map(function(e){return t.getVar(e)});n.unshift(null),this.env.results=n,this.env.flowEmitter.emit(r.TYPES.EXEC_FLOW_COMPLETE,this.env),this.f.apply(null,n)}this.f=null},s}),define("react/vcon",[],function(){function t(){}var e=":LAST_RESULTS";return t.prototype.getLastResults=function(){return this.getVar(e)},t.prototype.setLastResults=function(t){this.setVar(e,t)},t.prototype.getVar=function(e){var t=this.values;if(typeof e!="string")return e;e=e.trim();if(e==="true")return!0;if(e==="false")return!1;if(e==="null")return null;if(/^-?[0-9]+$/.test(e))return parseInt(e,10);if(/^-?[0-9.]+$/.test(e))return parseFloat(e);var n=/^("|')([^\1]*)\1$/.exec(e);if(n)return n[2];var r=e.split(".");return r.reduce(function(e,t){return e===undefined||e===null?undefined:e[t]},t)},t.prototype.saveResults=function(e,t){var n=this;e.forEach(function(e,r){n.setVar(e,t[r]!==undefined?t[r]:null)}),this.setLastResults(t)},t.prototype.setVar=function(e,t){if(!e)return;var n=this.values,r=e.split("."),i=r.pop(),s=r.reduce(function(e,t){var n=e[t];if(n===undefined||n===null)n=e[t]={};return n},n);s[i]=t},t.create=function(e,n,r,i){var s={};i&&(s["this"]=i),r&&Object.keys(r).forEach(function(e){s[e]=r[e]});var o=new t;return o.values=e.reduce(function(e,t,r){var i=n[r];return i&&(e[i]=t!==undefined?t:null),e},s),o},t}),define("react/finalcb-first-task",["./sprintf","util","./status","./vcon","./event-manager"],function(e,t,n,r,i){function o(e){var t=e.taskDef;if(typeof e.cbFunc!="function")throw new Error("callback is not a function");var n=this;for(var r in t)n[r]=t[r];this.f=e.cbFunc,this.tasks=e.tasks,this.vCon=e.vCon,this.retValue=e.retValue,this.env=e.env}function u(n,r){return e("%s - %s",n,t.inspect(r))}var s="ast.outTask.a should be an array of string param names";return o.validate=function(e){var t=[];return(!Array.isArray(e.a)||!e.a.every(function(e){return typeof e=="string"}))&&t.push(u(s,e)),t},o.prototype.isReady=function(){var e=this.vCon.getLastResults();return e?e.some(function(e){return e!==undefined&&e!==null}):!1},o.prototype.exec=function(e){if(!this.f)return;if(e)this.env.error=e,this.env.flowEmitter.emit(i.TYPES.EXEC_FLOW_ERRORED,this.env),this.f.call(null,e);else{var t=this.vCon,n=this.a.map(function(e){return t.getVar(e)});n.unshift(null),this.env.results=n,this.env.flowEmitter.emit(i.TYPES.EXEC_FLOW_COMPLETE,this.env),this.f.apply(null,n)}this.f=null},o}),define("react/task",["util","./sprintf","ensure-array","./cb-task","./promise-task","./ret-task","./when-task","./finalcb-task","./finalcb-first-task","./status","./error","./vcon","./event-manager"],function(e,t,n,r,i,s,o,u,a,f,l,c,h){function v(){return Object.keys(p)}function g(){return Object.keys(m)}function S(n,r){return t("%s - %s",n,e.inspect(r))}function x(e){return e.type?e:(e.type="cb",e)}function T(e){e.type||(e.type=Object.keys(m)[0])}function N(e){if(!e.after)return;var t=n(e.after);t=t.map(function(e){return typeof e=="function"?e.name:e}),e.after=t}function C(e){if(!e||typeof e!="object")return[S(b,e)];x(e),N(e);var t=[];return t=t.concat(k(e)),t=t.concat(L(e)),t}function k(e){var t=[];return Object.keys(p).some(function(t){return e.type===t})||t.push(S(E,e)),t}function L(e){var t=[],n=p[e.type];return n&&(t=t.concat(n.validate(e))),t}function A(e){var t=[];T(e);var n=m[e.type];return t=t.concat(n.validate(e)),t}function O(e,n,r){function s(){}var i=[],o=e.map(function(e){return s}),u=c.create(o,e,r),a=n.map(D),f=a.filter(function(e){return e.type!=="when"});return f.forEach(function(e,n){if(!e.functionExists(u))if(!e.isMethodCall())i.push(t(y,e.f,n));else{var r=e.getMethodObj(u);r&&r!==s&&i.push(t(y,e.f,n))}}),i}function M(e){return typeof e=="function"?e.name:e?e:""}function _(e){var n=e.reduce(function(e,t){return t.name&&(e[t.name]=t),e},{});return e.forEach(function(e,r){if(!e.name){var i=M(e.f);i||(i=t(d,r));if(!i||n[i])i=t("%s_%s",i,r);e.name=i,n[i]=e}}),n}function D(e){var t=p[e.type];return new t(e)}function P(e,t,n,r,i,s){T(e);var o={taskDef:e,cbFunc:t,tasks:n,vCon:r,execOptions:i,env:s,TaskConstructor:m[e.type]};h.global.emit(h.TYPES.EXEC_OUTTASK_CREATE,o);var u=o.TaskConstructor;return new u(o)}function H(e,t){return function(r,i){r.status=f.ERRORED,r.error=i,t.env.currentTask=r,t.env.flowEmitter.emit(h.TYPES.EXEC_TASK_ERRORED,r);var s=l.augmentError(i,{task:r,vcon:e});t.exec(s)}}function B(e,t,n){return t.filter(function(t){return t.isReady(e,n)})}function j(e,t,n,r){e.forEach(function(e){e.status=f.READY}),e.forEach(function(e){e.exec(t,n,r)})}function F(e,n,r,i){var s=n.filter(function(e){return e.status===f.RUNNING||e.status===f.READY});if(!s.length){var o=n.filter(function(e){return!e.status}),u=o.map(function(e){return e.name}),a=t(w,u.join(", ")),l={env:i};r(l,new Error(a))}}function I(e,t,n,r,i,s){var o=B(e,t,n);o.length||F(e,t,r,s),j(o,e,r,i)}function q(e){return _(e),e.forEach(function(e,t,n){t!==0&&(e.after=[n[t-1].name])}),e}var p={cb:r,ret:s,promise:i,when:o},d="task_%s",m={finalcb:u,finalcbFirst:a},y="function: %s not found in locals or input params - task[%s]",b="task must be an object",w="no tasks running, flow will not complete, remaining tasks: %s",E="task.type should match one of "+Object.keys(p).join(", ");return{serializeTasks:q,TASK_TYPES:p,taskTypeKeys:v,OUT_TASK_TYPES:m,outTaskTypeKeys:g,setMissingType:x,validate:C,validateOutTask:A,validateLocalFunctions:O,nameTasks:_,create:D,createOutTask:P,createErrorHandler:H,findReadyAndExec:I}}),define("react/validate",["util","./sprintf","ensure-array","./task"],function(e,t,n,r){function h(n,r){return t("%s - %s",n,e.inspect(r))}function p(e){return c.test(e)}function d(e){if(!e||!e.inParams||!e.tasks||!e.outTask)return[i];var t=[];return t=t.concat(v(e.inParams)),t=t.concat(m(e.tasks)),t=t.concat(g(e.tasks)),t=t.concat(r.validateOutTask(e.outTask)),t=t.concat(y(e.locals)),t.length===0&&(e.outTask.type!=="finalcbFirst"&&(t=t.concat(w(e.tasks))),t=t.concat(r.validateLocalFunctions(e.inParams,e.tasks,e.locals)),t=t.concat(E(e))),t}function v(e){return!Array.isArray(e)||!e.every(function(e){return typeof e=="string"})?[s]:[]}function m(e){if(!Array.isArray(e))return[o];var t=[];return e.forEach(function(e){t=t.concat(r.validate(e))}),t}function g(e){if(!Array.isArray(e))return[];var n=[],r=e.filter(function(e){return e.name}),i=r.map(function(e){return e.name});return i.reduce(function(e,r){return e[r]?n.push(t("%s %s",u,r)):e[r]=!0,e},{}),n}function y(e){var t=[];return e===null&&t.push(a),t}function b(e){return n(e.out)}function w(e){var n=[];return e.reduce(function(e,r){return b(r).forEach(function(r){e[r]!==undefined?n.push(t("%s: %s",f,r)):e[r]=!0}),e},{}),n}function E(e){var n=[],r={};return e.locals&&(r=Object.keys(e.locals).reduce(function(e,t){return e[t]=!0,e},r)),e.inParams.reduce(function(e,t){return e[t]=!0,e},r),e.tasks.reduce(function(e,t){return t.out.reduce(function(e,t){return e[t]=!0,e},e)},r),e.tasks.reduce(function(e,n){return n.a.reduce(function(e,n){return!p(n)&&!r[n]&&e.push(t(l,n)),e},e)},n),e.outTask.a.reduce(function(e,n){return!p(n)&&!r[n]&&e.push(t(l,n)),e},n),n}var i="ast must be an object with inParams, tasks, and outTask",s="ast.inParams must be an array of strings",o="ast.tasks must be an array of tasks",u="ast.tasks that specify name need to be unique, duplicate:",a="ast.locals should not be null",f="multiple tasks output the same param, must be unique. param",l="missing or mispelled variable referenced in flow definition: %s",c=/^(true|false|this|null|\-?[0-9\.]+)$|'|"|\./i;return d}),define("react/input-parser",["./event-manager"],function(e){function r(e){return e&&e.reactExecOptions}function i(e){return r(e)}function s(e){return!r(e)}function o(e,t){return Object.keys(t).forEach(function(n){e[n]=t[n]}),e}function u(e,t,r){var i={};return i.args=t.map(function(t){return e.shift()}),r===n.CALLBACK&&e.length&&(i.cb=e.shift()),i.extra=e,i}function a(n,r){var a={},f=n.filter(i);f.unshift(t),a.options=f.reduce(o,{});var l=n.filter(s),c=u(l,r.inParams,a.options.outputStyle);return a.args=c.args,a.cb=c.cb,c.outputStyle&&(a.options.outputStyle=c.outputStyle),c.extra&&(a.extraArgs=c.extra),e.global.emit(e.TYPES.EXEC_INPUT_PREPROCESS,a),a}var t={reactExecOptions:!0,outputStyle:"cb"},n={CALLBACK:"cb",NONE:"none"};return a.defaultExecOptions=t,a}),define("react/id",[],function(){function t(){return e+=1,e===Number.MAX_VALUE&&(e=0),e}var e=0;return{createUniqueId:t}}),define("react/core",["./eventemitter","./error","./validate","./task","./status","./vcon","./event-manager","./input-parser","./id","./sprintf"],function(e,t,n,r,i,s,o,u,a,f){function h(e){return Object.keys(l).reduce(function(e,t){return e[t]||(e[t]=l[t]),e},e)}function p(){return f("flow_%s",a.createUniqueId())}function d(){function f(t){Object.keys(t).forEach(function(e){i[e]=t[e]});var s=n(i);return s.length||(i.name||(i.name=p()),r.nameTasks(i.tasks)),Object.freeze&&(Object.keys(t).forEach(function(e){typeof t[e]=="object"&&Object.freeze(t[e])}),Object.freeze(t)),e.emit(o.TYPES.AST_DEFINED,i),s}function d(t,n,f,l){function E(){if(!b.f)return;if(b.isReady())return b.exec();r.findReadyAndExec(m,g,y,w,E,d)}var p=Array.prototype.slice.call(arguments),d={execId:a.createUniqueId(),args:p,ast:i,flowEmitter:e};d.name=i.name||d.execId,e.emit(o.TYPES.EXEC_FLOW_START,d);var v=u(p,i),m=s.create(v.args,i.inParams,i.locals,this);d.parsedInput=v,d.options=h(v.options),d.vCon=m,d.taskDefs=i.tasks.slice(),d.outTaskDef=Object.create(i.outTask),c.emit(o.TYPES.EXEC_TASKS_PRECREATE,d);var g=d.taskDefs.map(r.create),y=r.nameTasks(g),b=r.createOutTask(d.outTaskDef,v.cb,g,m,d.options,d),w=r.createErrorHandler(m,b);return g.forEach(function(t){t.id=a.createUniqueId(),t.env=d,t.prepare&&t.prepare(w,m,E,e)}),E(),b.retValue}if(arguments.length)throw new Error("react() takes no args, check API");t.ensureStackTraceLimitSet(l.stackTraceLimitMin);var e=o.create();e.parent=c;var i={name:undefined,inParams:[],tasks:[],outTask:{},locals:{}},v=d;return v.ast=i,v.setAndValidateAST=f,v.events=e,v}var l={stackTraceLimitMin:30},c=o.global;return d.options=l,d.events=c,d}),define("react/parse",["./sprintf"],function(e){function t(e){return e?e.split(",").map(function(e){return e.trim()}).filter(function(e){return e}):[]}function n(e,t){if(typeof e!="string")return e;var n=t.regex?t.regex.exec(e):e.split(t.splitStr);return n?t.fn(n,e):e}function r(t,r,i){var s=r.reduce(n,t);if(typeof s!="string")return s;throw new Error(e(i,t))}return{splitTrimFilterArgs:t,parseStr:r}}),define("react/dsl",["./sprintf","./core","./parse","./task"],function(e,t,n,r){function h(e){return e.length&&e[e.length-1].match(l)&&e.pop(),e}function p(e){return e.length&&e[0].match(c)&&e.shift(),e}function v(e){var t=n.parseStr(e,[d],s);return t.inDef=h(t.inDef),t}function m(t){var n=[],r,i,s;while(t.length>=2){i={},r=t.shift(),s=v(t.shift()),typeof t[0]=="object"&&(i=t.shift()),i.f=r,i.a=s.inDef;var o=s.type;i.out=s.outDef,i.type=o,n.push(i)}if(t.length)throw new Error(e(a,t[0]));return n}function g(e){var t=e.shift()||"",n=e.length&&typeof e[0]=="object"?e.shift():{},r=e,i={inOutParamStr:t,taskDefArr:r,options:n};return i}function y(n,r,s,o){var u=t();if(n&&f.test(n))throw new Error(e(i,n));var a=g(Array.prototype.slice.call(arguments,1)),l=v(a.inOutParamStr),c={name:n,inParams:l.inDef,tasks:m(a.taskDefArr),outTask:{a:l.outDef}};a.options&&Object.keys(a.options).forEach(function(e){c[e]=a.options[e]});var h=u.setAndValidateAST(c);if(h.length){var p=h.join("\n");throw new Error(p)}return u}function b(e,n,i,s){var o=t(),u=g(Array.prototype.slice.call(arguments,1)),a=v(u.inOutParamStr),f=r.serializeTasks(m(u.taskDefArr)),l={name:e,inParams:a.inDef,tasks:f,outTask:{type:"finalcbFirst",a:a.outDef}};u.options&&Object.keys(u.options).forEach(function(e){l[e]=u.options[e]});var c=o.setAndValidateAST(l);if(c.length){var h=c.join("\n");throw new Error(h)}return o}var i="first flow parameter should be the flow name, but found in/out def: %s",s='params in wrong format, wanted "foo, bar, cb -> err, baz" - found: %s',o='callback specified, but first out param was not "err", use for clarity. Found in/out def: %s',u="found err param, but cb/callback is not specified, is this cb-style async or sync function? Found in/out def: %s",a="extra unmatched task arg: %s",f=/\->/,l=/^cb|callback$/i,c=/^err$/i,d={splitStr:"->",fn:function(t,r){var i=n.splitTrimFilterArgs(t[0]),s=i[i.length-1],a=s&&l.test(s)?"cb":"ret",f=n.splitTrimFilterArgs(t[1]),d=f[0];if(a==="cb"&&(!d||!c.test(d)))throw new Error(e(o,r));if(a==="ret"&&d&&c.test(d))throw new Error(e(u,r));return{type:a,inDef:h(i),outDef:p(f)}}};return y.selectFirst=b,y}),define("react/track-tasks",[],function(){function t(t){if(e)return;e=!0,t.events.on(t.events.TYPES.EXEC_FLOW_START,function(e){e.startTime=Date.now(),e.flowEmitter.emit(t.events.TYPES.FLOW_BEGIN,e)}),t.events.on(t.events.TYPES.EXEC_TASK_START,function(e){e.startTime=Date.now(),e.env.flowEmitter.emit(t.events.TYPES.TASK_BEGIN,e)}),t.events.on(t.events.TYPES.EXEC_TASK_COMPLETE,function(e){e.endTime=Date.now(),e.elapsedTime=e.endTime-e.startTime,e.env.flowEmitter.emit(t.events.TYPES.TASK_COMPLETE,e)}),t.events.on(t.events.TYPES.EXEC_TASK_ERRORED,function(e){e.endTime=Date.now(),e.elapsedTime=e.endTime-e.startTime,e.env.flowEmitter.emit(t.events.TYPES.TASK_ERRORED,e)}),t.events.on(t.events.TYPES.EXEC_FLOW_COMPLETE,function(e){e.endTime=Date.now(),e.elapsedTime=e.endTime-e.startTime,e.flowEmitter.emit(t.events.TYPES.FLOW_COMPLETE,e)}),t.events.on(t.events.TYPES.EXEC_FLOW_ERRORED,function(e){e.endTime=Date.now(),e.elapsedTime=e.endTime-e.startTime,e.flowEmitter.emit(t.events.TYPES.FLOW_ERRORED,e)})}var e=!1;return t}),define("react/log-events",["util"],function(e){function s(t){var n=new Date;n.setTime(t.startTime);var r=t.args.filter(function(e){return typeof e!="function"}),i=n.toISOString();if(this.event==="flow.complete"){var s=t;console.error("%s: %s msecs: %s \n args: %s \n results: %s\n",this.event,s.name,s.elapsedTime,e.inspect(r),e.inspect(s.results))}else{var o=t.name,u=t.args;console.error("%s: %s \n args: %s\n",this.event,o,e.inspect(r))}}function o(t){var n=new Date;n.setTime(t.startTime);var r=t.args.filter(function(e){return typeof e!="function"}),i=n.toISOString();if(this.event==="task.complete"){var s=t;console.error("%s: %s:%s msecs: %s \n args: %s \n results: %s\n",this.event,s.env.name,s.name,s.elapsedTime,e.inspect(r),e.inspect(s.results))}else{var o=t.name,u=t.args;console.error("%s: %s:%s \n args: %s\n",this.event,t.env.name,t.name,e.inspect(r))}}function u(e,t){if(!e)throw new Error("flowFn is required");e.events._loggingEvents||(e.events._loggingEvents=[]);if(t===!1)e.events._loggingEvents.forEach(function(t){e.events.removeAllListeners(t)}),e.events._loggingEvents.length=0;else if(t&&t!=="*"){var u=i.test(t)?s:o;e.events.removeListener(t,u),e.events.on(t,u),e.events._loggingEvents.push(t)}else e.events.removeListener(n,s),e.events.on(n,s),e.events._loggingEvents.push(n),e.events.removeListener(r,o),e.events.on(r,o),e.events._loggingEvents.push(r)}var t={},n="flow.*",r="task.*",i=/^flow\./;return t.logEvents=u,t}),define("react/promise-resolve",[],function(){function n(n){if(t)return;t=!0,n.events.on(n.events.TYPES.EXEC_TASKS_PRECREATE,function(t){var n=t.vCon.values,r=t.ast.inParams.filter(function(e){var t=n[e];return t&&typeof t.then=="function"});r.forEach(function(r){var i=r+e;n[i]=n[r],n[r]=undefined,t.taskDefs.push({type:"when",a:[i],out:[r]})})})}var e="__promise",t=!1;return n}),define("react/event-collector",[],function(){function e(e){function i(){this.events=[]}e.trackTasks();var t=/^ast\./,n=/^task\./,r=/^flow\./;return i.prototype.capture=function(i,s){function a(e){var i={event:this.event,time:Date.now()};r.test(this.event)?i.env=e:n.test(this.event)?i.task=e:t.test(this.event)&&(i.ast=e),u.events.push(i)}!s&&typeof i=="string"?(s=i,i=e):i||(i=e),s||(s="*");var o=i.events,u=this;o.on(s,a)},i.prototype.list=function(){return this.events},i.prototype.clear=function(){this.events=[]},new i}return e}),define("react/react",["./core","./dsl","./track-tasks","./log-events","./promise-resolve","./event-collector"],function(e,t,n,r,i,s){function u(){i(o)}function a(){n(o)}function f(e,t){return typeof e!="function"&&(t=e,e=undefined),e||(e=o),a(),r.logEvents(e,t)}function l(){return s(o)}var o=t;return o.options=e.options,o.events=e.events,o.logEvents=f,o.resolvePromises=u,o.trackTasks=a,o.createEventCollector=l,o}),define("react",["react/react"],function(e){return e})
package/doc/advanced.md CHANGED
@@ -102,6 +102,14 @@ react.logEvents('flow.*'); // turn on flow logging for all react functions
102
102
  react.logEvents(myReactFn, 'task.*'); // turn on task logging for myReactFn
103
103
  ```
104
104
 
105
+ To turn off logging
106
+
107
+ ```javascript
108
+ react.logEvents(false); // turn off logging
109
+ ```
110
+
111
+
112
+
105
113
  Available Events that can be logged:
106
114
 
107
115
  - flow.begin - flow execution has started (receives a flow env)
@@ -149,8 +157,8 @@ When developing or debugging it is often useful to accumulate events and then in
149
157
  To make this easier to accomplish, this plugin provides a simple event accumulator for development use. Note that this accumulator is designed for short term debug use, as it will continue to accumulate events and does not have any size restrictions, it should not be used in production since it will just continue to grow in size unless manually cleared.
150
158
 
151
159
  ```javascript
152
- var EventCollector = require('react/lib/event-collector);
153
- var collector = new EventCollector();
160
+ var react = require('react');
161
+ var collector = react.createEventCollector();
154
162
 
155
163
  collector.capture(); // capture all flow and task events for all react flows
156
164
  collector.capture('flow.*'); // capture all flow events for all react flows
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  var react = require('../'); // require('react');
9
- require('../lib/track-tasks'); // require('react/lib/track-tasks'); // turn on tracking
9
+ react.trackTasks(); // turn on flow and task tracking events
10
10
 
11
11
  //output events as tasks start and complete
12
12
  react.events.on('flow.*', function (obj) {
package/lib/base-task.js CHANGED
@@ -1,117 +1,123 @@
1
1
  'use strict';
2
+ /*global define:true */
2
3
 
3
- var array = require('ensure-array');
4
- var STATUS = require('./status.js');
5
- var EventManager = require('./event-manager.js');
6
-
7
- function BaseTask() {
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
8
6
  }
9
7
 
10
- /**
11
- Getter Fn to retrieveAn array of the output param names for this task.
12
- */
13
- BaseTask.prototype.getOutParams = function () {
14
- return array(this.out); // ensure array
15
- };
16
-
17
- BaseTask.prototype.isComplete = function () {
18
- return (this.status === STATUS.COMPLETE);
19
- };
20
-
21
- BaseTask.prototype.start = function (args) { // mark task as started with args and note time
22
- /*jshint validthis: true */
23
- this.args = args;
24
- this.env.currentTask = this;
25
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_START, this);
26
- };
27
-
28
- BaseTask.prototype.complete = function (args) { //args that were used are available
29
- /*jshint validthis: true */
30
- this.status = STATUS.COMPLETE;
31
- this.results = args;
32
- this.env.currentTask = this;
33
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_COMPLETE, this);
34
- };
35
-
36
- BaseTask.prototype.functionExists = function (vCon) {
37
- var fn = this.f;
38
- if (!fn) return false;
39
- if (fn instanceof Function) return true;
40
- if (typeof(fn) === 'string') {
41
- var f = vCon.getVar(fn); // fn/method by string
42
- if (f && f instanceof Function) return true;
8
+ define(['ensure-array', './status', './event-manager'],
9
+ function (array, STATUS, EventManager) {
10
+
11
+ function BaseTask() {
43
12
  }
44
- return false;
45
- };
46
-
47
- BaseTask.prototype.areAllDepArgsDefined = function (vCon) {
48
- return this.a.every(function (k) { return (vCon.getVar(k) !== undefined); });
49
- };
50
-
51
- BaseTask.prototype.depTasksAreDone = function (tasksByName) {
52
- return (!this.after || !this.after.length || // no dep tasks OR
53
- this.after.every(function (n) { return tasksByName[n].isComplete(); })); //all done
54
- };
55
-
56
- function isObjProperty(str) { return (str.indexOf('.') !== -1); }
57
-
58
- /**
59
- check that obj parent is def and not null so writing to obj.prop
60
- will not fail. ex: 'b.c' checks that b is def and not null.
61
- Also returns true if not obj.prop but simple var ex: 'b'.
62
- Tasks will implement outParentsExist() passing each out str
63
- to this if they want to do this check.
13
+
14
+ /**
15
+ Getter Fn to retrieveAn array of the output param names for this task.
16
+ */
17
+ BaseTask.prototype.getOutParams = function () {
18
+ return array(this.out); // ensure array
19
+ };
20
+
21
+ BaseTask.prototype.isComplete = function () {
22
+ return (this.status === STATUS.COMPLETE);
23
+ };
24
+
25
+ BaseTask.prototype.start = function (args) { // mark task as started with args and note time
26
+ /*jshint validthis: true */
27
+ this.args = args;
28
+ this.env.currentTask = this;
29
+ this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_START, this);
30
+ };
31
+
32
+ BaseTask.prototype.complete = function (args) { //args that were used are available
33
+ /*jshint validthis: true */
34
+ this.status = STATUS.COMPLETE;
35
+ this.results = args;
36
+ this.env.currentTask = this;
37
+ this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_COMPLETE, this);
38
+ };
39
+
40
+ BaseTask.prototype.functionExists = function (vCon) {
41
+ var fn = this.f;
42
+ if (!fn) return false;
43
+ if (fn instanceof Function) return true;
44
+ if (typeof(fn) === 'string') {
45
+ var f = vCon.getVar(fn); // fn/method by string
46
+ if (f && f instanceof Function) return true;
47
+ }
48
+ return false;
49
+ };
50
+
51
+ BaseTask.prototype.areAllDepArgsDefined = function (vCon) {
52
+ return this.a.every(function (k) { return (vCon.getVar(k) !== undefined); });
53
+ };
54
+
55
+ BaseTask.prototype.depTasksAreDone = function (tasksByName) {
56
+ return (!this.after || !this.after.length || // no dep tasks OR
57
+ this.after.every(function (n) { return tasksByName[n].isComplete(); })); //all done
58
+ };
59
+
60
+ function isObjProperty(str) { return (str.indexOf('.') !== -1); }
61
+
62
+ /**
63
+ check that obj parent is def and not null so writing to obj.prop
64
+ will not fail. ex: 'b.c' checks that b is def and not null.
65
+ Also returns true if not obj.prop but simple var ex: 'b'.
66
+ Tasks will implement outParentsExist() passing each out str
67
+ to this if they want to do this check.
64
68
  */
65
- BaseTask.prototype.parentExists = function (objPropStr, vCon) {
66
- if (!isObjProperty(objPropStr)) return true; // NOT obj prop, just simple arg, ret true
67
- var nameAndProps = objPropStr.split('.');
68
- nameAndProps.pop(); // pop off final prop
69
- var parent = nameAndProps.reduce(function (accObj, prop) {
70
- if (accObj === undefined || accObj === null) return undefined; // prevent exception
71
- return accObj[prop];
72
- }, vCon.values); // vCon['foo']['bar']
73
- return (parent !== undefined && parent !== null);
74
- };
75
-
76
- /**
77
- If params are obj property writes make sure the dst objects
78
- are defined and not null. cb: ['b.c'] -> b is def and not null.
79
- If null is specified then param is valid and will be ignored.
80
- @returns true if all obj prop parents are def and non null
69
+ BaseTask.prototype.parentExists = function (objPropStr, vCon) {
70
+ if (!isObjProperty(objPropStr)) return true; // NOT obj prop, just simple arg, ret true
71
+ var nameAndProps = objPropStr.split('.');
72
+ nameAndProps.pop(); // pop off final prop
73
+ var parent = nameAndProps.reduce(function (accObj, prop) {
74
+ if (accObj === undefined || accObj === null) return undefined; // prevent exception
75
+ return accObj[prop];
76
+ }, vCon.values); // vCon['foo']['bar']
77
+ return (parent !== undefined && parent !== null);
78
+ };
79
+
80
+ /**
81
+ If params are obj property writes make sure the dst objects
82
+ are defined and not null. cb: ['b.c'] -> b is def and not null.
83
+ If null is specified then param is valid and will be ignored.
84
+ @returns true if all obj prop parents are def and non null
81
85
  */
82
- BaseTask.prototype.outParentsExist = function (vCon) {
83
- var self = this;
84
- return this.getOutParams().every(function (x) {
85
- if (x === null) return true;
86
- return self.parentExists(x, vCon);
87
- });
88
- };
89
-
90
- BaseTask.prototype.isReady = function (vCon, tasksByName) {
91
- return !this.status && // not started AND
92
- this.functionExists(vCon) && // function/method exists AND
93
- this.areAllDepArgsDefined(vCon) && // all dep vars defined AND
94
- this.depTasksAreDone(tasksByName) && // all dep tasks are done AND
95
- (!this.outParentsExist || // (task does not implement outParentsExist method OR
96
- this.outParentsExist(vCon)); // output parents exists (for obj property writes)
97
- };
98
-
99
- BaseTask.prototype.isMethodCall = function () {
100
- /*jshint regexp: false */
101
- return (typeof(this.f) === 'string' && /^.*\..*$/.test(this.f)); //str contains .
102
- };
103
-
104
- BaseTask.prototype.getMethodObj = function (vCon) { //obj.prop.prop2, returns obj.prop or undefined
105
- var name = this.f;
106
- if (!name) return undefined;
107
- var nameAndProps = name.split('.');
108
- nameAndProps.pop(); // pop off last one
109
- if (!nameAndProps.length) return undefined;
110
- var result = nameAndProps.reduce(function (accObj, prop) {
111
- if (accObj === undefined || accObj === null) return undefined; // prevent exception
112
- return accObj[prop];
113
- }, vCon.values); // vCon['foo']['bar']
114
- return result;
115
- };
116
-
117
- module.exports = BaseTask;
86
+ BaseTask.prototype.outParentsExist = function (vCon) {
87
+ var self = this;
88
+ return this.getOutParams().every(function (x) {
89
+ if (x === null) return true;
90
+ return self.parentExists(x, vCon);
91
+ });
92
+ };
93
+
94
+ BaseTask.prototype.isReady = function (vCon, tasksByName) {
95
+ return !this.status && // not started AND
96
+ this.functionExists(vCon) && // function/method exists AND
97
+ this.areAllDepArgsDefined(vCon) && // all dep vars defined AND
98
+ this.depTasksAreDone(tasksByName) && // all dep tasks are done AND
99
+ (!this.outParentsExist || // (task does not implement outParentsExist method OR
100
+ this.outParentsExist(vCon)); // output parents exists (for obj property writes)
101
+ };
102
+
103
+ BaseTask.prototype.isMethodCall = function () {
104
+ /*jshint regexp: false */
105
+ return (typeof(this.f) === 'string' && /^.*\..*$/.test(this.f)); //str contains .
106
+ };
107
+
108
+ BaseTask.prototype.getMethodObj = function (vCon) { //obj.prop.prop2, returns obj.prop or undefined
109
+ var name = this.f;
110
+ if (!name) return undefined;
111
+ var nameAndProps = name.split('.');
112
+ nameAndProps.pop(); // pop off last one
113
+ if (!nameAndProps.length) return undefined;
114
+ var result = nameAndProps.reduce(function (accObj, prop) {
115
+ if (accObj === undefined || accObj === null) return undefined; // prevent exception
116
+ return accObj[prop];
117
+ }, vCon.values); // vCon['foo']['bar']
118
+ return result;
119
+ };
120
+
121
+ return BaseTask;
122
+
123
+ });
package/lib/cb-task.js CHANGED
@@ -1,80 +1,84 @@
1
1
  'use strict';
2
+ /*global define:true */
2
3
 
3
- var util = require('util');
4
- var sprintf = require('sprintf').sprintf;
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
5
7
 
6
- var BaseTask = require('./base-task.js');
8
+ define(['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
7
9
 
8
- function format_error(errmsg, obj) {
9
- return sprintf('%s - %s', errmsg, util.inspect(obj));
10
- }
10
+ function format_error(errmsg, obj) {
11
+ return sprintf('%s - %s', errmsg, util.inspect(obj));
12
+ }
11
13
 
12
- var REQ = 'cbTask requires f, a, out';
13
- var FN_REQ = 'cbTask requires f to be a function or string';
14
- var A_REQ = 'cbTask requires a to be an array of string param names';
15
- var CB_REQ = 'cbTask requires out to be an array of string param names';
14
+ var REQ = 'cbTask requires f, a, out';
15
+ var FN_REQ = 'cbTask requires f to be a function or string';
16
+ var A_REQ = 'cbTask requires a to be an array of string param names';
17
+ var CB_REQ = 'cbTask requires out to be an array of string param names';
16
18
 
17
- function CbTask(taskDef) {
18
- var self = this;
19
- Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
20
- }
19
+ function CbTask(taskDef) {
20
+ var self = this;
21
+ Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
22
+ }
21
23
 
22
- CbTask.prototype = new BaseTask();
23
- CbTask.prototype.constructor = CbTask;
24
+ CbTask.prototype = new BaseTask();
25
+ CbTask.prototype.constructor = CbTask;
24
26
 
25
- CbTask.validate = function (taskDef) {
26
- var errors = [];
27
- if (!taskDef.f || !taskDef.a || !taskDef.out) {
28
- errors.push(format_error(REQ, taskDef));
29
- } else {
30
- var ftype = typeof(taskDef.f);
31
- if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
32
- errors.push(format_error(FN_REQ, taskDef));
27
+ CbTask.validate = function (taskDef) {
28
+ var errors = [];
29
+ if (!taskDef.f || !taskDef.a || !taskDef.out) {
30
+ errors.push(format_error(REQ, taskDef));
31
+ } else {
32
+ var ftype = typeof(taskDef.f);
33
+ if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
34
+ errors.push(format_error(FN_REQ, taskDef));
35
+ }
36
+ if (! (Array.isArray(taskDef.a) &&
37
+ taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
38
+ errors.push(format_error(A_REQ, taskDef));
39
+ }
40
+ if (! (Array.isArray(taskDef.out) &&
41
+ taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
42
+ errors.push(format_error(CB_REQ, taskDef));
43
+ }
33
44
  }
34
- if (! (Array.isArray(taskDef.a) &&
35
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
36
- errors.push(format_error(A_REQ, taskDef));
37
- }
38
- if (! (Array.isArray(taskDef.out) &&
39
- taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
40
- errors.push(format_error(CB_REQ, taskDef));
41
- }
42
- }
43
- return errors;
44
- };
45
+ return errors;
46
+ };
45
47
 
46
- CbTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
47
- var self = this;
48
- this.cbFun = function (err, arg0, arg1, argn) {
49
- var args = Array.prototype.slice.call(arguments, 1);
50
- if (err) { handleTaskError(self, err); return; } //handle error and return, we are done
48
+ CbTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
49
+ var self = this;
50
+ this.cbFun = function (err, arg0, arg1, argn) {
51
+ var args = Array.prototype.slice.call(arguments, 1);
52
+ if (err) { handleTaskError(self, err); return; } //handle error and return, we are done
51
53
 
52
- //no error, save callback args to vCon context, then continue execution
53
- vCon.saveResults(self.out, args);
54
- self.complete(args);
55
- contExec();
56
- };
57
- };
54
+ //no error, save callback args to vCon context, then continue execution
55
+ vCon.saveResults(self.out, args);
56
+ self.complete(args);
57
+ contExec();
58
+ };
59
+ };
58
60
 
59
- CbTask.prototype.exec = function exec(vCon, handleError, contExec) {
60
- try {
61
- var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
62
- //console.error('CbTask.exec.args=', args);
63
- //console.error('CbTask.exec.vCon=', vCon);
64
- this.start(args); //note the start time, args
65
- args.push(this.cbFun); // push callback fn on end
66
- var func = this.f;
67
- var bindObj = vCon.getVar('this'); //global space or the original this
68
- if (this.isMethodCall()) { //if method call then reset func and bindObj
69
- func = vCon.getVar(this.f);
70
- bindObj = this.getMethodObj(vCon);
71
- } else if (typeof(func) === 'string') {
72
- func = vCon.getVar(func); // we want the actual fn from this string
73
- }
74
- func.apply(bindObj, args);
75
- } catch (err) { //catch and handle the task error, calling final cb
76
- handleError(this, err);
77
- }
78
- };
61
+ CbTask.prototype.exec = function exec(vCon, handleError, contExec) {
62
+ try {
63
+ var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
64
+ //console.error('CbTask.exec.args=', args);
65
+ //console.error('CbTask.exec.vCon=', vCon);
66
+ this.start(args); //note the start time, args
67
+ args.push(this.cbFun); // push callback fn on end
68
+ var func = this.f;
69
+ var bindObj = vCon.getVar('this'); //global space or the original this
70
+ if (this.isMethodCall()) { //if method call then reset func and bindObj
71
+ func = vCon.getVar(this.f);
72
+ bindObj = this.getMethodObj(vCon);
73
+ } else if (typeof(func) === 'string') {
74
+ func = vCon.getVar(func); // we want the actual fn from this string
75
+ }
76
+ func.apply(bindObj, args);
77
+ } catch (err) { //catch and handle the task error, calling final cb
78
+ handleError(this, err);
79
+ }
80
+ };
81
+
82
+ return CbTask;
79
83
 
80
- module.exports = CbTask;
84
+ });
package/lib/core.js CHANGED
@@ -1,139 +1,138 @@
1
1
  'use strict';
2
+ /*global define:true */
2
3
 
3
- var EventEmitter = require('events').EventEmitter;
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
4
7
 
5
- var error = require('./error.js');
6
- var validate = require('./validate.js');
7
- var tskutil = require('./task.js');
8
- var STATUS = require('./status.js');
9
- var VContext = require('./vcon.js');
10
- var EventManager = require('./event-manager.js');
11
- var inputParser = require('./input-parser.js');
12
- var idGenerator = require('./id.js');
13
- var sprintf = require('sprintf').sprintf;
8
+ define(['./eventemitter', './error', './validate', './task', './status',
9
+ './vcon', './event-manager', './input-parser', './id', './sprintf'],
10
+ function (EventEmitter, error, validate, taskUtil, STATUS,
11
+ VContext, EventManager, inputParser, idGenerator, sprintf) {
14
12
 
15
- var reactOptions = {
16
- stackTraceLimitMin: 30
17
- };
13
+ var reactOptions = {
14
+ stackTraceLimitMin: 30
15
+ };
18
16
 
19
- var reactEmitter = EventManager.global; // the top emitter
17
+ var reactEmitter = EventManager.global; // the top emitter
20
18
 
21
- /**
22
- merge global react options with parsed options
19
+ /**
20
+ merge global react options with parsed options
23
21
  */
24
- function mergeOptions(parsedOptions) {
25
- return Object.keys(reactOptions).reduce(function (accum, k) {
26
- if (!accum[k]) accum[k] = reactOptions[k];
27
- return accum;
28
- }, parsedOptions);
29
- }
22
+ function mergeOptions(parsedOptions) {
23
+ return Object.keys(reactOptions).reduce(function (accum, k) {
24
+ if (!accum[k]) accum[k] = reactOptions[k];
25
+ return accum;
26
+ }, parsedOptions);
27
+ }
30
28
 
31
- /**
32
- generate a flow name when one is not provided
29
+ /**
30
+ generate a flow name when one is not provided
33
31
  */
34
- function generateFlowName() {
35
- return sprintf('flow_%s', idGenerator.createUniqueId());
36
- }
32
+ function generateFlowName() {
33
+ return sprintf('flow_%s', idGenerator.createUniqueId());
34
+ }
37
35
 
38
- /**
39
- Creates react function which the AST can be manipulated and then
40
- is ready to be executed. Can be used directly or a DSL can wrap this
41
- to provide the AST.
36
+ /**
37
+ Creates react function which the AST can be manipulated and then
38
+ is ready to be executed. Can be used directly or a DSL can wrap this
39
+ to provide the AST.
42
40
 
43
- @example
44
- var react = require('react');
45
- var fn = react();
46
- var valid2 = fn.setAndValidateAST({
41
+ @example
42
+ var react = require('react');
43
+ var fn = react();
44
+ var valid2 = fn.setAndValidateAST({
47
45
  name: 'optionalName',
48
46
  inParams: ['a', 'b'],
49
47
  tasks: [
50
- { type: 'cb', f: multiply, a: ['a', 'b'], out: ['c'] }
48
+ { type: 'cb', f: multiply, a: ['a', 'b'], out: ['c'] }
51
49
  ],
52
- outTask: { a: ['c'] }
53
- });
54
- console.log(fn.ast); // view
55
- fn(123, 456, cb);
56
- */
57
- function reactFactory() {
58
- if (arguments.length) throw new Error('react() takes no args, check API');
59
-
60
- error.ensureStackTraceLimitSet(reactOptions.stackTraceLimitMin);
61
- var flowEmitter = EventManager.create();
62
- flowEmitter.parent = reactEmitter;
63
-
64
- var ast = {
65
- name: undefined,
66
- inParams: [],
67
- tasks: [],
68
- outTask: {},
69
- locals: {}
70
- };
50
+ outTask: { a: ['c'] }
51
+ });
52
+ console.log(fn.ast); // view
53
+ fn(123, 456, cb);
54
+ */
55
+ function reactFactory() {
56
+ if (arguments.length) throw new Error('react() takes no args, check API');
57
+
58
+ error.ensureStackTraceLimitSet(reactOptions.stackTraceLimitMin);
59
+ var flowEmitter = EventManager.create();
60
+ flowEmitter.parent = reactEmitter;
61
+
62
+ var ast = {
63
+ name: undefined,
64
+ inParams: [],
65
+ tasks: [],
66
+ outTask: {},
67
+ locals: {}
68
+ };
71
69
 
72
- function setAndValidateAST(newAST) { //set AST then validate, ret error[]
73
- Object.keys(newAST).forEach(function (k) { ast[k] = newAST[k]; }); // copy all properties
74
- var errors = validate(ast);
75
- if (!errors.length) {
76
- if (!ast.name) ast.name = generateFlowName();
77
- tskutil.nameTasks(ast.tasks); //run this so names can be checked in ast
70
+ function setAndValidateAST(newAST) { //set AST then validate, ret error[]
71
+ Object.keys(newAST).forEach(function (k) { ast[k] = newAST[k]; }); // copy all properties
72
+ var errors = validate(ast);
73
+ if (!errors.length) {
74
+ if (!ast.name) ast.name = generateFlowName();
75
+ taskUtil.nameTasks(ast.tasks); //run this so names can be checked in ast
76
+ }
77
+ if (Object.freeze) { //lets freeze the AST so plugin writers don't accidentally manip the ast
78
+ Object.keys(newAST).forEach(function (k) {
79
+ if (typeof(newAST[k]) === 'object') Object.freeze(newAST[k]);
80
+ });
81
+ Object.freeze(newAST);
82
+ }
83
+ flowEmitter.emit(EventManager.TYPES.AST_DEFINED, ast);
84
+ return errors;
78
85
  }
79
- if (Object.freeze) { //lets freeze the AST so plugin writers don't accidentally manip the ast
80
- Object.keys(newAST).forEach(function (k) {
81
- if (typeof(newAST[k]) === 'object') Object.freeze(newAST[k]);
82
- });
83
- Object.freeze(newAST);
84
- }
85
- flowEmitter.emit(EventManager.TYPES.AST_DEFINED, ast);
86
- return errors;
87
- }
88
86
 
89
- function exec(arg1, arg2, argN, cb) { // called to execute the flow
90
- /*jshint validthis: true */
91
- var args = Array.prototype.slice.call(arguments);
92
- var env = {
93
- execId: idGenerator.createUniqueId(),
94
- args: args,
95
- ast: ast,
96
- flowEmitter: flowEmitter
97
- };
98
- env.name = ast.name || env.execId;
99
- flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_START, env); // hook
100
- var parsedInput = inputParser(args, ast);
101
- var vCon = VContext.create(parsedInput.args, ast.inParams, ast.locals, this); // create var ctx with in args & locals
102
-
103
- env.parsedInput = parsedInput;
104
- env.options = mergeOptions(parsedInput.options);
105
- env.vCon = vCon;
106
- env.taskDefs = ast.tasks.slice(); // create copy
107
- env.outTaskDef = Object.create(ast.outTask); // create copy
108
- reactEmitter.emit(EventManager.TYPES.EXEC_TASKS_PRECREATE, env); // hook
109
-
110
- var tasks = env.taskDefs.map(tskutil.create);
111
- var tasksByName = tskutil.nameTasks(tasks); // map names to working tasks
112
- var outTask = tskutil.createOutTask(env.outTaskDef, parsedInput.cb, tasks, vCon, env.options, env);
113
- var handleError = tskutil.createErrorHandler(vCon, outTask);
114
-
115
- function contExec() {
116
- if (!outTask.f) { return; } //stop execution, we already hit an error, f was cleared
117
- if (outTask.isReady()) return outTask.exec(); // all tasks done, exec cb, return
118
- tskutil.findReadyAndExec(vCon, tasks, tasksByName, handleError, contExec, env); //exec tasks that ready to run
87
+ function exec(arg1, arg2, argN, cb) { // called to execute the flow
88
+ /*jshint validthis: true */
89
+ var args = Array.prototype.slice.call(arguments);
90
+ var env = {
91
+ execId: idGenerator.createUniqueId(),
92
+ args: args,
93
+ ast: ast,
94
+ flowEmitter: flowEmitter
95
+ };
96
+ env.name = ast.name || env.execId;
97
+ flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_START, env); // hook
98
+ var parsedInput = inputParser(args, ast);
99
+ var vCon = VContext.create(parsedInput.args, ast.inParams, ast.locals, this); // create var ctx with in args & locals
100
+
101
+ env.parsedInput = parsedInput;
102
+ env.options = mergeOptions(parsedInput.options);
103
+ env.vCon = vCon;
104
+ env.taskDefs = ast.tasks.slice(); // create copy
105
+ env.outTaskDef = Object.create(ast.outTask); // create copy
106
+ reactEmitter.emit(EventManager.TYPES.EXEC_TASKS_PRECREATE, env); // hook
107
+
108
+ var tasks = env.taskDefs.map(taskUtil.create);
109
+ var tasksByName = taskUtil.nameTasks(tasks); // map names to working tasks
110
+ var outTask = taskUtil.createOutTask(env.outTaskDef, parsedInput.cb, tasks, vCon, env.options, env);
111
+ var handleError = taskUtil.createErrorHandler(vCon, outTask);
112
+
113
+ function contExec() {
114
+ if (!outTask.f) { return; } //stop execution, we already hit an error, f was cleared
115
+ if (outTask.isReady()) return outTask.exec(); // all tasks done, exec cb, return
116
+ taskUtil.findReadyAndExec(vCon, tasks, tasksByName, handleError, contExec, env); //exec tasks that ready to run
117
+ }
118
+
119
+ tasks.forEach(function (t) {
120
+ t.id = idGenerator.createUniqueId();
121
+ t.env = env;
122
+ if (t.prepare) t.prepare(handleError, vCon, contExec, flowEmitter);
123
+ }); // create callbacks
124
+ contExec(); // start things off
125
+ return outTask.retValue; // could return promise
119
126
  }
120
127
 
121
- tasks.forEach(function (t) {
122
- t.id = idGenerator.createUniqueId();
123
- t.env = env;
124
- if (t.prepare) t.prepare(handleError, vCon, contExec, flowEmitter);
125
- }); // create callbacks
126
- contExec(); // start things off
127
- return outTask.retValue; // could return promise
128
+ var reactFn = exec; // make the exec() the function returned
129
+ reactFn.ast = ast; // put AST hanging off the fn so it can be inspected
130
+ reactFn.setAndValidateAST = setAndValidateAST; // call to set AST and then validate
131
+ reactFn.events = flowEmitter; // used to listen to execution events for this flow
132
+ return reactFn;
128
133
  }
129
134
 
130
- var reactFn = exec; // make the exec() the function returned
131
- reactFn.ast = ast; // put AST hanging off the fn so it can be inspected
132
- reactFn.setAndValidateAST = setAndValidateAST; // call to set AST and then validate
133
- reactFn.events = flowEmitter; // used to listen to execution events for this flow
134
- return reactFn;
135
- }
136
-
137
- module.exports = reactFactory; // module returns reactFactory to create a react fn
138
- module.exports.options = reactOptions; // global react options
139
- module.exports.events = reactEmitter; // global react emitter
135
+ reactFactory.options = reactOptions; // global react options
136
+ reactFactory.events = reactEmitter; // global react emitter
137
+ return reactFactory; // module returns reactFactory to create a react fn
138
+ });