Skip to content

Instantly share code, notes, and snippets.

@fibo
Last active October 16, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fibo/45520011e093d6dfec9f to your computer and use it in GitHub Desktop.
Save fibo/45520011e093d6dfec9f to your computer and use it in GitHub Desktop.
requirebin sketch
// Backlink: http://g14n.info/dflow#requirebin
var dflow = require('dflow')
var funcs = {
createElement: document.createElement.bind(document),
appendChild: function (parent, child) { return parent.appendChild(child) },
bodyAppendChild: function (child) { return document.body.appendChild(child) },
createTextNode: document.createTextNode.bind(document)
},
graph = {
task: {
arg0: 'arguments[0]',
arg1: 'arguments[1]',
createElement: 'createElement',
createTextNode: 'createTextNode',
appendChild: 'appendChild',
bodyAppendChild: 'bodyAppendChild',
'return': 'return'
},
pipe: {
// Read arguments[0] and arguments[1]
// and pass them to createElement and createTextNode respectively.
a: ['arg0', 'createElement' ],
b: ['arg1', 'createTextNode' ],
// appendChild takes inputs from both createElement and createTextNode.
c: ['createElement', 'appendChild' ],
d: ['createTextNode', 'appendChild', 1],
// createElement returns a DOM node that is appended to body.
e: ['createElement', 'bodyAppendChild' ],
// body.appendChild returns a DOM node that is returned by the dflow graph.
f: ['bodyAppendChild', 'return' ]
}
}
// Create a dflow fun by given graph and additional functions.
var out = dflow.fun(graph, funcs)
out('h1', 'dflow')
out('h2', 'Dataflow programming for Node.js')
out('p', 'An example of dflow in a browser context, testing DOM manipulation.')
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){exports=module.exports=require("./debug");exports.log=log;exports.formatArgs=formatArgs;exports.save=save;exports.load=load;exports.useColors=useColors;exports.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:localstorage();exports.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"];function useColors(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}exports.formatters.j=function(v){return JSON.stringify(v)};function formatArgs(){var args=arguments;var useColors=this.useColors;args[0]=(useColors?"%c":"")+this.namespace+(useColors?" %c":" ")+args[0]+(useColors?"%c ":" ")+"+"+exports.humanize(this.diff);if(!useColors)return args;var c="color: "+this.color;args=[args[0],c,"color: inherit"].concat(Array.prototype.slice.call(args,1));var index=0;var lastC=0;args[0].replace(/%[a-z%]/g,function(match){if("%%"===match)return;index++;if("%c"===match){lastC=index}});args.splice(lastC,0,c);return args}function log(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function save(namespaces){try{if(null==namespaces){exports.storage.removeItem("debug")}else{exports.storage.debug=namespaces}}catch(e){}}function load(){var r;try{r=exports.storage.debug}catch(e){}return r}exports.enable(load());function localstorage(){try{return window.localStorage}catch(e){}}},{"./debug":2}],2:[function(require,module,exports){exports=module.exports=debug;exports.coerce=coerce;exports.disable=disable;exports.enable=enable;exports.enabled=enabled;exports.humanize=require("ms");exports.names=[];exports.skips=[];exports.formatters={};var prevColor=0;var prevTime;function selectColor(){return exports.colors[prevColor++%exports.colors.length]}function debug(namespace){function disabled(){}disabled.enabled=false;function enabled(){var self=enabled;var curr=+new Date;var ms=curr-(prevTime||curr);self.diff=ms;self.prev=prevTime;self.curr=curr;prevTime=curr;if(null==self.useColors)self.useColors=exports.useColors();if(null==self.color&&self.useColors)self.color=selectColor();var args=Array.prototype.slice.call(arguments);args[0]=exports.coerce(args[0]);if("string"!==typeof args[0]){args=["%o"].concat(args)}var index=0;args[0]=args[0].replace(/%([a-z%])/g,function(match,format){if(match==="%%")return match;index++;var formatter=exports.formatters[format];if("function"===typeof formatter){var val=args[index];match=formatter.call(self,val);args.splice(index,1);index--}return match});if("function"===typeof exports.formatArgs){args=exports.formatArgs.apply(self,args)}var logFn=enabled.log||exports.log||console.log.bind(console);logFn.apply(self,args)}enabled.enabled=true;var fn=exports.enabled(namespace)?enabled:disabled;fn.namespace=namespace;return fn}function enable(namespaces){exports.save(namespaces);var split=(namespaces||"").split(/[\s,]+/);var len=split.length;for(var i=0;i<len;i++){if(!split[i])continue;namespaces=split[i].replace(/\*/g,".*?");if(namespaces[0]==="-"){exports.skips.push(new RegExp("^"+namespaces.substr(1)+"$"))}else{exports.names.push(new RegExp("^"+namespaces+"$"))}}}function disable(){exports.enable("")}function enabled(name){var i,len;for(i=0,len=exports.skips.length;i<len;i++){if(exports.skips[i].test(name)){return false}}for(i=0,len=exports.names.length;i<len;i++){if(exports.names[i].test(name)){return true}}return false}function coerce(val){if(val instanceof Error)return val.stack||val.message;return val}},{ms:3}],3:[function(require,module,exports){var s=1e3;var m=s*60;var h=m*60;var d=h*24;var y=d*365.25;module.exports=function(val,options){options=options||{};if("string"==typeof val)return parse(val);return options.long?long(val):short(val)};function parse(str){str=""+str;if(str.length>1e4)return;var match=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);if(!match)return;var n=parseFloat(match[1]);var type=(match[2]||"ms").toLowerCase();switch(type){case"years":case"year":case"yrs":case"yr":case"y":return n*y;case"days":case"day":case"d":return n*d;case"hours":case"hour":case"hrs":case"hr":case"h":return n*h;case"minutes":case"minute":case"mins":case"min":case"m":return n*m;case"seconds":case"second":case"secs":case"sec":case"s":return n*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n}}function short(ms){if(ms>=d)return Math.round(ms/d)+"d";if(ms>=h)return Math.round(ms/h)+"h";if(ms>=m)return Math.round(ms/m)+"m";if(ms>=s)return Math.round(ms/s)+"s";return ms+"ms"}function long(ms){return plural(ms,d,"day")||plural(ms,h,"hour")||plural(ms,m,"minute")||plural(ms,s,"second")||ms+" ms"}function plural(ms,n,name){if(ms<n)return;if(ms<n*1.5)return Math.floor(ms/n)+" "+name;return Math.ceil(ms/n)+" "+name+"s"}},{}],4:[function(require,module,exports){var debug=require("debug");exports.compile=debug("dflow:compile");exports.inject=debug("dflow:inject");exports.run=debug("dflow:run")},{debug:1}],5:[function(require,module,exports){var builtinFunctions=require("./functions/builtin"),debug=require("./debug"),injectAdditionalFunctions=require("./inject/additionalFunctions"),injectArguments=require("./inject/arguments"),injectAccessors=require("./inject/accessors"),injectDotOperators=require("./inject/dotOperators"),injectGlobals=require("./inject/globals"),injectReferences=require("./inject/references"),inputArgs=require("./inputArgs"),isDflowFun=require("./isDflowFun"),level=require("./level"),validate=require("./validate");var debugRun=debug.run,debugCompile=debug.compile;function fun(graph,additionalFunctions){try{validate(graph,additionalFunctions)}catch(err){throw err}debugCompile("graph with "+Object.keys(graph.task).length+" tasks and "+Object.keys(graph.pipe).length+" pipes");var func=graph.func||{},pipe=graph.pipe,task=graph.task;var cachedLevelOf={},computeLevelOf=level.bind(null,pipe,cachedLevelOf),funcs=builtinFunctions;function compileSubgraph(key){if(typeof funcs[key]==="undefined")funcs[key]=fun(graph.func[key],additionalFunctions)}funcs["dflow.fun"]=fun;funcs["dflow.isDflowFun"]=isDflowFun;funcs["dflow.validate"]=validate;injectGlobals(funcs,task);injectAccessors(funcs,graph);injectAdditionalFunctions(funcs,additionalFunctions);injectDotOperators(funcs,task);injectReferences(funcs,task);Object.keys(func).forEach(compileSubgraph);function dflowFun(){debugRun("start");var gotReturn=false,outs={},returnValue;var startMessage="fun start";if(typeof graph.info!=="undefined")startMessage+=graph.info;var inputArgsOf=inputArgs.bind(null,outs,pipe);funcs["this"]=function(){return dflowFun};funcs["this.graph"]=function(){return graph};injectArguments(funcs,task,arguments);function byLevel(a,b){if(typeof cachedLevelOf[a]==="undefined")cachedLevelOf[a]=computeLevelOf(a);if(typeof cachedLevelOf[b]==="undefined")cachedLevelOf[b]=computeLevelOf(b);return cachedLevelOf[a]-cachedLevelOf[b]}function run(taskKey){var args=inputArgsOf(taskKey),funcName=task[taskKey],f=funcs[funcName];debugRun("task "+taskKey+" = "+funcName);if(gotReturn)return;if(funcName==="return"&&!gotReturn){returnValue=args[0];gotReturn=true;return}if(typeof f==="undefined")throw new TypeError("Task "+funcName+" ["+taskKey+"] is not defined");outs[taskKey]=f.apply(null,args)}Object.keys(task).sort(byLevel).forEach(run);debugRun("end");return returnValue}dflowFun.graph=graph;return dflowFun}module.exports=fun},{"./debug":4,"./functions/builtin":6,"./inject/accessors":8,"./inject/additionalFunctions":9,"./inject/arguments":10,"./inject/dotOperators":11,"./inject/globals":12,"./inject/references":13,"./inputArgs":14,"./isDflowFun":16,"./level":17,"./validate":23}],6:[function(require,module,exports){function addition(a,b){return a+b}exports["+"]=addition;function multiplication(a,b){return a*b}exports["*"]=multiplication;function subtraction(a,b){return a-b}exports["-"]=subtraction;function division(a,b){return a/b}exports["/"]=division;function modulus(a,b){return a%b}exports["%"]=modulus;function and(a,b){return a&&b}exports["&&"]=and;function or(a,b){return a||b}exports["||"]=or;function not(a){return!a}exports["!"]=not;function equalTo(a,b){return a==b}exports["=="]=equalTo;function equalValueAndEqualType(a,b){return a===b}exports["==="]=equalValueAndEqualType;function notEqual(a,b){return a!=b}exports["!="]=notEqual;function notEqualValueAndEqualType(a,b){return a!==b}exports["!=="]=notEqualValueAndEqualType;function greaterThen(a,b){return a>b}exports[">"]=greaterThen;function lessThen(a,b){return a<b}exports["<"]=lessThen;function greaterThenOrEqualTo(a,b){return a>=b}exports[">="]=greaterThenOrEqualTo;function lessThenOrEqualTo(a,b){return a<=b}exports["<="]=lessThenOrEqualTo;function applyMethod(fun,thisArg,argsArray){return fun.apply(thisArg,argsArray)}exports.apply=applyMethod;function dot(obj,prop){return obj[prop]}exports["."]=dot;function typeofOperator(operand){return typeof operand}exports["typeof"]=typeofOperator;function newOperator(){var Obj=arguments[0],arg1=arguments[1],arg2=arguments[2],arg3=arguments[3],arg4=arguments[4],arg5=arguments[5],argN=arguments.length-1;if(argN===0)return new Obj;if(argN===1)return new Obj(arg1);if(argN===2)return new Obj(arg1,arg2);if(argN===3)return new Obj(arg1,arg2,arg3);if(argN===4)return new Obj(arg1,arg2,arg3,arg4);if(argN===5)return new Obj(arg1,arg2,arg3,arg4,arg5)}exports["new"]=newOperator;function emptyArray(){return[]}exports["[]"]=emptyArray;exports.isArray=Array.isArray;exports.indexOf=function(a,b){return a.indexOf(b)};exports.filter=function(a,b,t){if(typeof t==="undefined")return a.filter(c,t);else return a.filter(c)};exports.forEach=function(a,c){if(typeof t==="undefined")return a.forEach(c,t);else return a.forEach(c)};exports["Array.prototype.join"]=Array.prototype.join;exports["Array.prototype.map"]=Array.prototype.map;exports["Array.prototype.pop"]=Array.prototype.pop;exports["Array.prototype.push"]=Array.prototype.push;exports["Array.prototype.reduce"]=Array.prototype.reduce;exports["Array.prototype.slice"]=Array.prototype.slice;exports["Array.prototype.sort"]=Array.prototype.sort;exports["console.error"]=console.error.bind(console);exports["console.log"]=console.log.bind(console);exports["Function.prototype"]=Function.prototype;exports["Infinity"]=function(){return Infinity};exports.NaN=function(){return NaN};exports["null"]=function(){return null};exports["{}"]=function(){return{}};exports["Object.prototype.defineProperties"]=Object.prototype.defineProperties;exports["Object.prototype.defineProperty"]=Object.prototype.defineProperty;exports["Object.prototype.hasOwnProperty"]=Object.prototype.hasOwnProperty;exports["Object.prototype.isPrototypeOf"]=Object.prototype.isPrototypeOf;exports["Object.prototype.propertyIsEnumerable"]=Object.prototype.propertyIsEnumerable;exports["Object.prototype.toLocaleString"]=Object.prototype.toLocaleString;exports["Object.prototype.toString"]=Object.prototype.toString;exports["Object.prototype.valueOf"]=Object.prototype.valueOf;exports["''"]=function(){return""};exports["String.prototype.charAt"]=String.prototype.charAt;exports["String.prototype.charCodeAt"]=String.prototype.charCodeAt;exports["String.prototype.concat"]=String.prototype.concat;exports["String.prototype.indexOf"]=String.prototype.indexOf;exports["String.prototype.lastIndexOf"]=String.prototype.lastIndexOf;exports["String.prototype.repeat"]=String.prototype.repeat;exports["String.prototype.search"]=String.prototype.search;exports["String.prototype.slice"]=String.prototype.slice;exports["String.prototype.split"]=String.prototype.split;exports["String.prototype.substr"]=String.prototype.substr;exports["String.prototype.substring"]=String.prototype.substring;exports["String.prototype.toLocaleLowerCase"]=String.prototype.toLocaleLowerCase;exports["String.prototype.toLocaleUpperCase"]=String.prototype.toLocaleUpperCase;exports["String.prototype.toLowerCase"]=String.prototype.toLowerCase;exports["String.prototype.toUpperCase"]=String.prototype.toUpperCase;exports["String.prototype.trim"]=String.prototype.trim},{}],7:[function(require,module,exports){exports.document=function _document(){return document};exports.body=function body(){return document.body};exportshead=function head(){return document.head};exports.window=function _window(){return window}},{}],8:[function(require,module,exports){var accessorRegex=require("../regex/accessor"),debug=require("../debug").inject;function injectAccessors(funcs,graph){if(typeof graph.data==="undefined")graph.data={};function inject(taskKey){var accessorName,taskName=graph.task[taskKey];function accessor(){if(arguments.length===1)graph.data[accessorName]=arguments[0];return graph.data[accessorName]}if(accessorRegex.test(taskName)){accessorName=taskName.substring(1);debug(taskName);funcs[taskName]=accessor}}Object.keys(graph.task).forEach(inject)}module.exports=injectAccessors},{"../debug":4,"../regex/accessor":19}],9:[function(require,module,exports){var debug=require("../debug").inject;function injectAdditionalFunctions(funcs,additionalFunctions){if(typeof additionalFunctions==="undefined")return;debug(Object.keys(additionalFunctions).length+" additionalFunctions");function injectAdditionalFunction(key){var isAFunction=typeof additionalFunctions[key]==="function";if(isAFunction)funcs[key]=additionalFunctions[key]}Object.keys(additionalFunctions).forEach(injectAdditionalFunction)}module.exports=injectAdditionalFunctions},{"../debug":4}],10:[function(require,module,exports){var argumentRegex=require("../regex/argument"),debug=require("../debug").inject;function injectArguments(funcs,task,args){function getArgument(index){return args[index]}function inject(taskKey){var funcName=task[taskKey];if(funcName==="arguments"){debug("arguments");funcs[funcName]=function getArguments(){return args}}else{var arg=argumentRegex.exec(funcName);if(arg){debug(funcName);funcs[funcName]=getArgument.bind(null,arg[1])}}}Object.keys(task).forEach(inject)}module.exports=injectArguments},{"../debug":4,"../regex/argument":20}],11:[function(require,module,exports){var debug=require("../debug").inject,dotOperatorRegex=require("../regex/dotOperator");function injectDotOperators(funcs,task){function inject(taskKey){var taskName=task[taskKey];function dotOperatorFunc(attributeName,obj){var func;if(typeof obj==="object")func=obj[attributeName];if(typeof func==="function")return func.apply(obj,Array.prototype.slice.call(arguments,2))}if(dotOperatorRegex.func.test(taskName)){attributeName=taskName.substring(1,taskName.length-2);debug(taskName);funcs[taskName]=dotOperatorFunc.bind(null,attributeName)}function dotOperatorAttr(attributeName,obj){var attr;if(typeof obj==="object")attr=obj[attributeName];if(typeof attr==="function")return attr.bind(obj);return attr}if(dotOperatorRegex.attr.test(taskName)){attributeName=taskName.substring(1);debug(taskName);funcs[taskName]=dotOperatorAttr.bind(null,attributeName)}}Object.keys(task).forEach(inject)}module.exports=injectDotOperators},{"../debug":4,"../regex/dotOperator":21}],12:[function(require,module,exports){var debug=require("../debug").inject,walkGlobal=require("../walkGlobal");function injectGlobals(funcs,task){function inject(taskKey){var taskName=task[taskKey];if(typeof funcs[taskName]==="function")return;if(taskName==="return"||taskName==="this.graph")return;var globalValue=walkGlobal(taskName);if(typeof globalValue==="undefined")return;debug("global "+taskName);if(typeof globalValue==="function")funcs[taskName]=globalValue;else funcs[taskName]=function(){return globalValue}}Object.keys(task).forEach(inject)}module.exports=injectGlobals},{"../debug":4,"../walkGlobal":24}],13:[function(require,module,exports){var debug=require("../debug").inject,referenceRegex=require("../regex/reference"),walkGlobal=require("../walkGlobal");function injectReferences(funcs,task){function inject(taskKey){var referenceName,referencedFunction,taskName=task[taskKey];function reference(){return referencedFunction}if(referenceRegex.test(taskName)){referenceName=taskName.substring(1);if(typeof funcs[referenceName]==="function")referencedFunction=funcs[referenceName];else referencedFunction=walkGlobal(referenceName);if(typeof referencedFunction==="function"){debug("reference to "+referenceName);funcs[taskName]=reference}}}Object.keys(task).forEach(inject)}module.exports=injectReferences},{"../debug":4,"../regex/reference":22,"../walkGlobal":24}],14:[function(require,module,exports){var inputPipes=require("./inputPipes");function inputArgs(outs,pipe,taskKey){var args=[],inputPipesOf=inputPipes.bind(null,pipe);function populateArg(inputPipe){var index=inputPipe[2]||0,value=outs[inputPipe[0]];args[index]=value}inputPipesOf(taskKey).forEach(populateArg);return args}module.exports=inputArgs},{"./inputPipes":15}],15:[function(require,module,exports){function inputPipes(pipe,taskKey){var pipes=[];function pushPipe(key){pipes.push(pipe[key])}function ifIsInputPipe(key){return pipe[key][1]===taskKey}Object.keys(pipe).filter(ifIsInputPipe).forEach(pushPipe);return pipes}module.exports=inputPipes},{}],16:[function(require,module,exports){var validate=require("./validate");function isDflowFun(f){var isFunction=typeof f==="function",hasGraphObject=typeof f.graph==="object",hasFuncsObject=typeof f.funcs==="object",hasValidGraph=false;if(isFunction&&hasGraphObject&&hasFuncsObject)hasValidGraph=validate(f.graph,f.funcs);return hasValidGraph}module.exports=isDflowFun},{"./validate":23}],17:[function(require,module,exports){var parents=require("./parents");function level(pipe,cachedLevelOf,taskKey){var taskLevel=0,parentsOf=parents.bind(null,pipe);if(typeof cachedLevelOf[taskKey]==="number")return cachedLevelOf[taskKey];function computeLevel(parentTaskKey){taskLevel=Math.max(taskLevel,level(pipe,cachedLevelOf,parentTaskKey)+1)}parentsOf(taskKey).forEach(computeLevel);cachedLevelOf[taskKey]=taskLevel;return taskLevel}module.exports=level},{"./parents":18}],18:[function(require,module,exports){var inputPipes=require("./inputPipes");function parents(pipe,taskKey){var inputPipesOf=inputPipes.bind(null,pipe),parentTaskIds=[];function pushParentTaskId(pipe){parentTaskIds.push(pipe[0])}inputPipesOf(taskKey).forEach(pushParentTaskId);return parentTaskIds}module.exports=parents},{"./inputPipes":15}],19:[function(require,module,exports){module.exports=/^@(.+)$/},{}],20:[function(require,module,exports){module.exports=/^arguments\[(\d+)\]$/},{}],21:[function(require,module,exports){exports.attr=/^\.([a-zA-Z_$][0-9a-zA-Z_$]+)$/;exports.func=/^\.([a-zA-Z_$][0-9a-zA-Z_$]+)\(\)$/},{}],22:[function(require,module,exports){module.exports=/^\&(.+)$/},{}],23:[function(require,module,exports){var accessorRegex=require("./regex/accessor"),argumentRegex=require("./regex/argument"),dotOperatorRegex=require("./regex/dotOperator"),referenceRegex=require("./regex/reference");function validate(graph,additionalFunctions){var pipe=graph.pipe,task=graph.task;var data=graph.data||{},func=graph.func||{},info=graph.info||{};var seenPipe={};function throwIfEquals(taskName,reservedKey){if(taskName===reservedKey)throw new TypeError("Reserved function name: "+taskName)}if(typeof additionalFunctions==="object"){for(var taskName in additionalFunctions){var reservedKeys=["return","arguments","this","this.graph"],throwIfEqualsTaskName=throwIfEquals.bind(null,taskName);reservedKeys.forEach(throwIfEqualsTaskName);if(argumentRegex.test(taskName))throw new TypeError("Reserved function name: "+taskName);if(accessorRegex.test(taskName))throw new TypeError('Function name cannot start with "@": '+taskName);if(dotOperatorRegex.attr.test(taskName))throw new TypeError('Function name cannot start with ".":'+taskName);if(dotOperatorRegex.func.test(taskName))throw new TypeError('Function name cannot start with "." and end with "()":'+taskName);if(referenceRegex.test(taskName))throw new TypeError('Function name cannot start with "&": '+taskName)}}if(typeof pipe!=="object")throw new TypeError("Not an object: pipe",pipe);if(typeof task!=="object")throw new TypeError("Not an object: task",task);if(typeof data!=="object")throw new TypeError("Not an object: data",data);if(typeof func!=="object")throw new TypeError("Not an object: func",func);if(typeof info!=="object")throw new TypeError("Not an object: info",info);function checkPipe(key){var arg=pipe[key][2]||0,from=pipe[key][0],to=pipe[key][1];if(typeof arg!=="number")throw new TypeError("Invalid pipe:",pipe[key]);if(typeof from!=="string")throw new TypeError("Invalid pipe:",pipe[key]);if(typeof to!=="string")throw new TypeError("Invalid pipe:",pipe[key]);if(typeof task[from]==="undefined")throw new Error("Orphan pipe:",pipe[key]);if(typeof task[to]==="undefined")throw new Error("Orphan pipe:",pipe[key]);if(typeof seenPipe[from]==="undefined")seenPipe[from]={};if(typeof seenPipe[from][to]==="undefined")seenPipe[from][to]=[];if(typeof seenPipe[from][to][arg]==="undefined")seenPipe[from][to][arg]=true;else throw new Error("Duplicated pipe:",pipe[key])}Object.keys(pipe).forEach(checkPipe);function checkFunc(key){validate(func[key],additionalFunctions)}if(typeof func==="object")Object.keys(func).forEach(checkFunc);return true}module.exports=validate},{"./regex/accessor":19,"./regex/argument":20,"./regex/dotOperator":21,"./regex/reference":22}],24:[function(require,module,exports){(function(global){var globalContext;if(typeof window==="object")globalContext=window;if(typeof global==="object")globalContext=global;function walkGlobal(taskName){function toNextProp(leaf,prop){return leaf[prop]}return taskName.split(".").reduce(toNextProp,globalContext)}module.exports=walkGlobal}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],dflow:[function(require,module,exports){var windowFunctions=require("../functions/window"),fun=require("../fun");function funBrowser(graph){var additionalFunctions=arguments[1]||{};function inject(key){additionalFunctions[key]=windowFunctions[key]}Object.keys(windowFunctions).forEach(inject);return fun(graph,additionalFunctions)}exports.fun=funBrowser},{"../fun":5,"../functions/window":7}]},{},[]);var dflow=require("dflow");funcs={createElement:document.createElement.bind(document),appendChild:function(parent,child){return parent.appendChild(child)},bodyAppendChild:function(child){return document.body.appendChild(child)},createTextNode:document.createTextNode.bind(document)},graph={task:{arg0:"arguments[0]",arg1:"arguments[1]",createElement:"createElement",createTextNode:"createTextNode",appendChild:"appendChild",bodyAppendChild:"bodyAppendChild","return":"return"},pipe:{a:["arg0","createElement"],b:["arg1","createTextNode"],c:["createElement","appendChild"],d:["createTextNode","appendChild",1],e:["createElement","bodyAppendChild"],f:["bodyAppendChild","return"]}};var test=dflow.fun(graph,funcs);test("h1","dflow test");test("p","it works!");
{
"name": "requirebin-dflow",
"version": "1.0.0",
"dependencies": {
"dflow": "*"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment