Skip to content

Instantly share code, notes, and snippets.

@theadam
Last active January 23, 2016 04:23
Show Gist options
  • Save theadam/0d319465094cb5b63112 to your computer and use it in GitHub Desktop.
Save theadam/0d319465094cb5b63112 to your computer and use it in GitHub Desktop.
requirebin sketch
var flyd = require('flyd');
var flydSpring = require('flyd-spring');
var changeDestination = flyd.stream(0);
var valueChange = flydSpring.spring(changeDestination);
flyd.on(console.log.bind(console), valueChange);
changeDestination(1);
setTimeout(function() {
changeDestination(2);
}, 100);
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){var _arity=require("./internal/_arity");var _curry1=require("./internal/_curry1");var _curry2=require("./internal/_curry2");var _curryN=require("./internal/_curryN");module.exports=_curry2(function curryN(length,fn){if(length===1){return _curry1(fn)}return _arity(length,_curryN(length,[],fn))})},{"./internal/_arity":2,"./internal/_curry1":3,"./internal/_curry2":4,"./internal/_curryN":5}],2:[function(require,module,exports){module.exports=function _arity(n,fn){switch(n){case 0:return function(){return fn.apply(this,arguments)};case 1:return function(a0){return fn.apply(this,arguments)};case 2:return function(a0,a1){return fn.apply(this,arguments)};case 3:return function(a0,a1,a2){return fn.apply(this,arguments)};case 4:return function(a0,a1,a2,a3){return fn.apply(this,arguments)};case 5:return function(a0,a1,a2,a3,a4){return fn.apply(this,arguments)};case 6:return function(a0,a1,a2,a3,a4,a5){return fn.apply(this,arguments)};case 7:return function(a0,a1,a2,a3,a4,a5,a6){return fn.apply(this,arguments)};case 8:return function(a0,a1,a2,a3,a4,a5,a6,a7){return fn.apply(this,arguments)};case 9:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8){return fn.apply(this,arguments)};case 10:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){return fn.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}},{}],3:[function(require,module,exports){module.exports=function _curry1(fn){return function f1(a){if(arguments.length===0){return f1}else if(a!=null&&a["@@functional/placeholder"]===true){return f1}else{return fn.apply(this,arguments)}}}},{}],4:[function(require,module,exports){var _curry1=require("./_curry1");module.exports=function _curry2(fn){return function f2(a,b){var n=arguments.length;if(n===0){return f2}else if(n===1&&a!=null&&a["@@functional/placeholder"]===true){return f2}else if(n===1){return _curry1(function(b){return fn(a,b)})}else if(n===2&&a!=null&&a["@@functional/placeholder"]===true&&b!=null&&b["@@functional/placeholder"]===true){return f2}else if(n===2&&a!=null&&a["@@functional/placeholder"]===true){return _curry1(function(a){return fn(a,b)})}else if(n===2&&b!=null&&b["@@functional/placeholder"]===true){return _curry1(function(b){return fn(a,b)})}else{return fn(a,b)}}}},{"./_curry1":3}],5:[function(require,module,exports){var _arity=require("./_arity");module.exports=function _curryN(length,received,fn){return function(){var combined=[];var argsIdx=0;var left=length;var combinedIdx=0;while(combinedIdx<received.length||argsIdx<arguments.length){var result;if(combinedIdx<received.length&&(received[combinedIdx]==null||received[combinedIdx]["@@functional/placeholder"]!==true||argsIdx>=arguments.length)){result=received[combinedIdx]}else{result=arguments[argsIdx];argsIdx+=1}combined[combinedIdx]=result;if(result==null||result["@@functional/placeholder"]!==true){left-=1}combinedIdx+=1}return left<=0?fn.apply(this,combined):_arity(left,_curryN(length,combined,fn))}}},{"./_arity":2}],flyd:[function(require,module,exports){var curryN=require("ramda/src/curryN");"use strict";function isFunction(obj){return!!(obj&&obj.constructor&&obj.call&&obj.apply)}var toUpdate=[];var inStream;function map(f,s){return combine(function(s,self){self(f(s.val))},[s])}function on(f,s){return combine(function(s){f(s.val)},[s])}function boundMap(f){return map(f,this)}var scan=curryN(3,function(f,acc,s){var ns=combine(function(s,self){self(acc=f(acc,s.val))},[s]);if(!ns.hasVal)ns(acc);return ns});var merge=curryN(2,function(s1,s2){var s=immediate(combine(function(s1,s2,self,changed){if(changed[0]){self(changed[0]())}else if(s1.hasVal){self(s1.val)}else if(s2.hasVal){self(s2.val)}},[s1,s2]));endsOn(combine(function(){return true},[s1.end,s2.end]),s);return s});function ap(s2){var s1=this;return combine(function(s1,s2,self){self(s1.val(s2.val))},[s1,s2])}function initialDepsNotMet(stream){stream.depsMet=stream.deps.every(function(s){return s.hasVal});return!stream.depsMet}function updateStream(s){if(s.depsMet!==true&&initialDepsNotMet(s)||s.end!==undefined&&s.end.val===true)return;if(inStream!==undefined){toUpdate.push(s);return}inStream=s;if(s.depsChanged)s.fnArgs[s.fnArgs.length-1]=s.depsChanged;var returnVal=s.fn.apply(s.fn,s.fnArgs);if(returnVal!==undefined){s(returnVal)}inStream=undefined;if(s.depsChanged!==undefined)s.depsChanged=[];s.shouldUpdate=false;if(flushing===false)flushUpdate()}var order=[];var orderNextIdx=-1;function findDeps(s){var i,listeners=s.listeners;if(s.queued===false){s.queued=true;for(i=0;i<listeners.length;++i){findDeps(listeners[i])}order[++orderNextIdx]=s}}function updateDeps(s){var i,o,list,listeners=s.listeners;for(i=0;i<listeners.length;++i){list=listeners[i];if(list.end===s){endStream(list)}else{if(list.depsChanged!==undefined)list.depsChanged.push(s);list.shouldUpdate=true;findDeps(list)}}for(;orderNextIdx>=0;--orderNextIdx){o=order[orderNextIdx];if(o.shouldUpdate===true)updateStream(o);o.queued=false}}var flushing=false;function flushUpdate(){flushing=true;while(toUpdate.length>0){var s=toUpdate.shift();if(s.vals.length>0)s.val=s.vals.shift();updateDeps(s)}flushing=false}function isStream(stream){return isFunction(stream)&&"hasVal"in stream}function streamToString(){return"stream("+this.val+")"}function updateStreamValue(s,n){if(n!==undefined&&n!==null&&isFunction(n.then)){n.then(s);return}s.val=n;s.hasVal=true;if(inStream===undefined){flushing=true;updateDeps(s);if(toUpdate.length>0)flushUpdate();else flushing=false}else if(inStream===s){markListeners(s,s.listeners)}else{s.vals.push(n);toUpdate.push(s)}}function markListeners(s,lists){var i,list;for(i=0;i<lists.length;++i){list=lists[i];if(list.end!==s){if(list.depsChanged!==undefined){list.depsChanged.push(s)}list.shouldUpdate=true}else{endStream(list)}}}function createStream(){function s(n){return arguments.length>0?(updateStreamValue(s,n),s):s.val}s.hasVal=false;s.val=undefined;s.vals=[];s.listeners=[];s.queued=false;s.end=undefined;s.map=boundMap;s.ap=ap;s.of=stream;s.toString=streamToString;return s}function addListeners(deps,s){for(var i=0;i<deps.length;++i){deps[i].listeners.push(s)}}function createDependentStream(deps,fn){var s=createStream();s.fn=fn;s.deps=deps;s.depsMet=false;s.depsChanged=deps.length>0?[]:undefined;s.shouldUpdate=false;addListeners(deps,s);return s}function immediate(s){if(s.depsMet===false){s.depsMet=true;updateStream(s)}return s}function removeListener(s,listeners){var idx=listeners.indexOf(s);listeners[idx]=listeners[listeners.length-1];listeners.length--}function detachDeps(s){for(var i=0;i<s.deps.length;++i){removeListener(s,s.deps[i].listeners)}s.deps.length=0}function endStream(s){if(s.deps!==undefined)detachDeps(s);if(s.end!==undefined)detachDeps(s.end)}function endsOn(endS,s){detachDeps(s.end);endS.listeners.push(s.end);s.end.deps.push(endS);return s}function trueFn(){return true}function stream(initialValue){var endStream=createDependentStream([],trueFn);var s=createStream();s.end=endStream;s.fnArgs=[];endStream.listeners.push(s);if(arguments.length>0)s(initialValue);return s}function combine(fn,streams){var i,s,deps,depEndStreams;var endStream=createDependentStream([],trueFn);deps=[];depEndStreams=[];for(i=0;i<streams.length;++i){if(streams[i]!==undefined){deps.push(streams[i]);if(streams[i].end!==undefined)depEndStreams.push(streams[i].end)}}s=createDependentStream(deps,fn);s.depsChanged=[];s.fnArgs=s.deps.concat([s,s.depsChanged]);s.end=endStream;endStream.listeners.push(s);addListeners(depEndStreams,endStream);endStream.deps=depEndStreams;updateStream(s);return s}var transduce=curryN(2,function(xform,source){xform=xform(new StreamTransformer);return combine(function(source,self){var res=xform["@@transducer/step"](undefined,source.val);if(res&&res["@@transducer/reduced"]===true){self.end(true);return res["@@transducer/value"]}else{return res}},[source])});function StreamTransformer(){}StreamTransformer.prototype["@@transducer/init"]=function(){};StreamTransformer.prototype["@@transducer/result"]=function(){};StreamTransformer.prototype["@@transducer/step"]=function(s,v){return v};module.exports={stream:stream,combine:curryN(2,combine),isStream:isStream,transduce:transduce,merge:merge,scan:scan,endsOn:endsOn,map:curryN(2,map),on:curryN(2,on),curryN:curryN,immediate:immediate}},{"ramda/src/curryN":1}]},{},[]);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){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]={noWobble:[170,26],gentle:[120,14],wobbly:[180,12],stiff:[210,20]};module.exports=exports["default"]},{}],2:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=stepper;var errorMargin=.001;function stepper(frameRate,x,v,destX,k,b){var Fspring=-k*(x-destX);var Fdamper=-b*v;var a=Fspring+Fdamper;var newV=v+a*frameRate;var newX=x+newV*frameRate;if(Math.abs(newV)<errorMargin&&Math.abs(newX-destX)<errorMargin){return[destX,0]}return[newX,newV]}module.exports=exports["default"]},{}],3:[function(require,module,exports){var curryN=require("ramda/src/curryN");"use strict";function isFunction(obj){return!!(obj&&obj.constructor&&obj.call&&obj.apply)}var toUpdate=[];var inStream;function map(f,s){return combine(function(s,self){self(f(s.val))},[s])}function on(f,s){return combine(function(s){f(s.val)},[s])}function boundMap(f){return map(f,this)}var scan=curryN(3,function(f,acc,s){var ns=combine(function(s,self){self(acc=f(acc,s.val))},[s]);if(!ns.hasVal)ns(acc);return ns});var merge=curryN(2,function(s1,s2){var s=immediate(combine(function(s1,s2,self,changed){if(changed[0]){self(changed[0]())}else if(s1.hasVal){self(s1.val)}else if(s2.hasVal){self(s2.val)}},[s1,s2]));endsOn(combine(function(){return true},[s1.end,s2.end]),s);return s});function ap(s2){var s1=this;return combine(function(s1,s2,self){self(s1.val(s2.val))},[s1,s2])}function initialDepsNotMet(stream){stream.depsMet=stream.deps.every(function(s){return s.hasVal});return!stream.depsMet}function updateStream(s){if(s.depsMet!==true&&initialDepsNotMet(s)||s.end!==undefined&&s.end.val===true)return;if(inStream!==undefined){toUpdate.push(s);return}inStream=s;if(s.depsChanged)s.fnArgs[s.fnArgs.length-1]=s.depsChanged;var returnVal=s.fn.apply(s.fn,s.fnArgs);if(returnVal!==undefined){s(returnVal)}inStream=undefined;if(s.depsChanged!==undefined)s.depsChanged=[];s.shouldUpdate=false;if(flushing===false)flushUpdate()}var order=[];var orderNextIdx=-1;function findDeps(s){var i,listeners=s.listeners;if(s.queued===false){s.queued=true;for(i=0;i<listeners.length;++i){findDeps(listeners[i])}order[++orderNextIdx]=s}}function updateDeps(s){var i,o,list,listeners=s.listeners;for(i=0;i<listeners.length;++i){list=listeners[i];if(list.end===s){endStream(list)}else{if(list.depsChanged!==undefined)list.depsChanged.push(s);list.shouldUpdate=true;findDeps(list)}}for(;orderNextIdx>=0;--orderNextIdx){o=order[orderNextIdx];if(o.shouldUpdate===true)updateStream(o);o.queued=false}}var flushing=false;function flushUpdate(){flushing=true;while(toUpdate.length>0){var s=toUpdate.shift();if(s.vals.length>0)s.val=s.vals.shift();updateDeps(s)}flushing=false}function isStream(stream){return isFunction(stream)&&"hasVal"in stream}function streamToString(){return"stream("+this.val+")"}function updateStreamValue(s,n){if(n!==undefined&&n!==null&&isFunction(n.then)){n.then(s);return}s.val=n;s.hasVal=true;if(inStream===undefined){flushing=true;updateDeps(s);if(toUpdate.length>0)flushUpdate();else flushing=false}else if(inStream===s){markListeners(s,s.listeners)}else{s.vals.push(n);toUpdate.push(s)}}function markListeners(s,lists){var i,list;for(i=0;i<lists.length;++i){list=lists[i];if(list.end!==s){if(list.depsChanged!==undefined){list.depsChanged.push(s)}list.shouldUpdate=true}else{endStream(list)}}}function createStream(){function s(n){return arguments.length>0?(updateStreamValue(s,n),s):s.val}s.hasVal=false;s.val=undefined;s.vals=[];s.listeners=[];s.queued=false;s.end=undefined;s.map=boundMap;s.ap=ap;s.of=stream;s.toString=streamToString;return s}function addListeners(deps,s){for(var i=0;i<deps.length;++i){deps[i].listeners.push(s)}}function createDependentStream(deps,fn){var s=createStream();s.fn=fn;s.deps=deps;s.depsMet=false;s.depsChanged=deps.length>0?[]:undefined;s.shouldUpdate=false;addListeners(deps,s);return s}function immediate(s){if(s.depsMet===false){s.depsMet=true;updateStream(s)}return s}function removeListener(s,listeners){var idx=listeners.indexOf(s);listeners[idx]=listeners[listeners.length-1];listeners.length--}function detachDeps(s){for(var i=0;i<s.deps.length;++i){removeListener(s,s.deps[i].listeners)}s.deps.length=0}function endStream(s){if(s.deps!==undefined)detachDeps(s);if(s.end!==undefined)detachDeps(s.end)}function endsOn(endS,s){detachDeps(s.end);endS.listeners.push(s.end);s.end.deps.push(endS);return s}function trueFn(){return true}function stream(initialValue){var endStream=createDependentStream([],trueFn);var s=createStream();s.end=endStream;s.fnArgs=[];endStream.listeners.push(s);if(arguments.length>0)s(initialValue);return s}function combine(fn,streams){var i,s,deps,depEndStreams;var endStream=createDependentStream([],trueFn);deps=[];depEndStreams=[];for(i=0;i<streams.length;++i){if(streams[i]!==undefined){deps.push(streams[i]);if(streams[i].end!==undefined)depEndStreams.push(streams[i].end)}}s=createDependentStream(deps,fn);s.depsChanged=[];s.fnArgs=s.deps.concat([s,s.depsChanged]);s.end=endStream;endStream.listeners.push(s);addListeners(depEndStreams,endStream);endStream.deps=depEndStreams;updateStream(s);return s}var transduce=curryN(2,function(xform,source){xform=xform(new StreamTransformer);return combine(function(source,self){var res=xform["@@transducer/step"](undefined,source.val);if(res&&res["@@transducer/reduced"]===true){self.end(true);return res["@@transducer/value"]}else{return res}},[source])});function StreamTransformer(){}StreamTransformer.prototype["@@transducer/init"]=function(){};StreamTransformer.prototype["@@transducer/result"]=function(){};StreamTransformer.prototype["@@transducer/step"]=function(s,v){return v};module.exports={stream:stream,combine:curryN(2,combine),isStream:isStream,transduce:transduce,merge:merge,scan:scan,endsOn:endsOn,map:curryN(2,map),on:curryN(2,on),curryN:curryN,immediate:immediate}},{"ramda/src/curryN":4}],4:[function(require,module,exports){var _arity=require("./internal/_arity");var _curry1=require("./internal/_curry1");var _curry2=require("./internal/_curry2");var _curryN=require("./internal/_curryN");module.exports=_curry2(function curryN(length,fn){if(length===1){return _curry1(fn)}return _arity(length,_curryN(length,[],fn))})},{"./internal/_arity":5,"./internal/_curry1":6,"./internal/_curry2":7,"./internal/_curryN":8}],5:[function(require,module,exports){module.exports=function _arity(n,fn){switch(n){case 0:return function(){return fn.apply(this,arguments)};case 1:return function(a0){return fn.apply(this,arguments)};case 2:return function(a0,a1){return fn.apply(this,arguments)};case 3:return function(a0,a1,a2){return fn.apply(this,arguments)};case 4:return function(a0,a1,a2,a3){return fn.apply(this,arguments)};case 5:return function(a0,a1,a2,a3,a4){return fn.apply(this,arguments)};case 6:return function(a0,a1,a2,a3,a4,a5){return fn.apply(this,arguments)};case 7:return function(a0,a1,a2,a3,a4,a5,a6){return fn.apply(this,arguments)};case 8:return function(a0,a1,a2,a3,a4,a5,a6,a7){return fn.apply(this,arguments)};case 9:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8){return fn.apply(this,arguments)};case 10:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){return fn.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}},{}],6:[function(require,module,exports){module.exports=function _curry1(fn){return function f1(a){if(arguments.length===0){return f1}else if(a!=null&&a["@@functional/placeholder"]===true){return f1}else{return fn.apply(this,arguments)}}}},{}],7:[function(require,module,exports){var _curry1=require("./_curry1");module.exports=function _curry2(fn){return function f2(a,b){var n=arguments.length;if(n===0){return f2}else if(n===1&&a!=null&&a["@@functional/placeholder"]===true){return f2}else if(n===1){return _curry1(function(b){return fn(a,b)})}else if(n===2&&a!=null&&a["@@functional/placeholder"]===true&&b!=null&&b["@@functional/placeholder"]===true){return f2}else if(n===2&&a!=null&&a["@@functional/placeholder"]===true){return _curry1(function(a){return fn(a,b)})}else if(n===2&&b!=null&&b["@@functional/placeholder"]===true){return _curry1(function(b){return fn(a,b)})}else{return fn(a,b)}}}},{"./_curry1":6}],8:[function(require,module,exports){var _arity=require("./_arity");module.exports=function _curryN(length,received,fn){return function(){var combined=[];var argsIdx=0;var left=length;var combinedIdx=0;while(combinedIdx<received.length||argsIdx<arguments.length){var result;if(combinedIdx<received.length&&(received[combinedIdx]==null||received[combinedIdx]["@@functional/placeholder"]!==true||argsIdx>=arguments.length)){result=received[combinedIdx]}else{result=arguments[argsIdx];argsIdx+=1}combined[combinedIdx]=result;if(result==null||result["@@functional/placeholder"]!==true){left-=1}combinedIdx+=1}return left<=0?fn.apply(this,combined):_arity(left,_curryN(length,combined,fn))}}},{"./_arity":5}],9:[function(require,module,exports){var inherits=require("inherits");var EventEmitter=require("events").EventEmitter;var now=require("right-now");var raf=require("raf");module.exports=Engine;function Engine(fn){if(!(this instanceof Engine))return new Engine(fn);this.running=false;this.last=now();this._frame=0;this._tick=this.tick.bind(this);if(fn)this.on("tick",fn)}inherits(Engine,EventEmitter);Engine.prototype.start=function(){if(this.running)return;this.running=true;this.last=now();this._frame=raf(this._tick);return this};Engine.prototype.stop=function(){this.running=false;if(this._frame!==0)raf.cancel(this._frame);this._frame=0;return this};Engine.prototype.tick=function(){this._frame=raf(this._tick);var time=now();var dt=time-this.last;this.emit("tick",dt);this.last=time}},{events:14,inherits:10,raf:11,"right-now":13}],10:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],11:[function(require,module,exports){var now=require("performance-now"),global=typeof window==="undefined"?{}:window,vendors=["moz","webkit"],suffix="AnimationFrame",raf=global["request"+suffix],caf=global["cancel"+suffix]||global["cancelRequest"+suffix];for(var i=0;i<vendors.length&&!raf;i++){raf=global[vendors[i]+"Request"+suffix];caf=global[vendors[i]+"Cancel"+suffix]||global[vendors[i]+"CancelRequest"+suffix]}if(!raf||!caf){var last=0,id=0,queue=[],frameDuration=1e3/60;raf=function(callback){if(queue.length===0){var _now=now(),next=Math.max(0,frameDuration-(_now-last));last=next+_now;setTimeout(function(){var cp=queue.slice(0);queue.length=0;for(var i=0;i<cp.length;i++){if(!cp[i].cancelled){try{cp[i].callback(last)}catch(e){setTimeout(function(){throw e},0)}}}},Math.round(next))}queue.push({handle:++id,callback:callback,cancelled:false});return id};caf=function(handle){for(var i=0;i<queue.length;i++){if(queue[i].handle===handle){queue[i].cancelled=true}}}}module.exports=function(fn){return raf.call(global,fn)};module.exports.cancel=function(){caf.apply(global,arguments)}},{"performance-now":12}],12:[function(require,module,exports){(function(process){(function(){var getNanoSeconds,hrtime,loadTime;if(typeof performance!=="undefined"&&performance!==null&&performance.now){module.exports=function(){return performance.now()}}else if(typeof process!=="undefined"&&process!==null&&process.hrtime){module.exports=function(){return(getNanoSeconds()-loadTime)/1e6};hrtime=process.hrtime;getNanoSeconds=function(){var hr;hr=hrtime();return hr[0]*1e9+hr[1]};loadTime=getNanoSeconds()}else if(Date.now){module.exports=function(){return Date.now()-loadTime};loadTime=Date.now()}else{module.exports=function(){return(new Date).getTime()-loadTime};loadTime=(new Date).getTime()}}).call(this)}).call(this,require("_process"))},{_process:15}],13:[function(require,module,exports){(function(global){module.exports=global.performance&&global.performance.now?function now(){return performance.now()}:Date.now||function now(){return+new Date}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],14:[function(require,module,exports){function EventEmitter(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}module.exports=EventEmitter;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._maxListeners=undefined;EventEmitter.defaultMaxListeners=10;EventEmitter.prototype.setMaxListeners=function(n){if(!isNumber(n)||n<0||isNaN(n))throw TypeError("n must be a positive number");this._maxListeners=n;return this};EventEmitter.prototype.emit=function(type){var er,handler,len,args,i,listeners;if(!this._events)this._events={};if(type==="error"){if(!this._events.error||isObject(this._events.error)&&!this._events.error.length){er=arguments[1];if(er instanceof Error){throw er}else{throw TypeError('Uncaught, unspecified "error" event.')}return false}}handler=this._events[type];if(isUndefined(handler))return false;if(isFunction(handler)){switch(arguments.length){case 1:handler.call(this);break;case 2:handler.call(this,arguments[1]);break;case 3:handler.call(this,arguments[1],arguments[2]);break;default:len=arguments.length;args=new Array(len-1);for(i=1;i<len;i++)args[i-1]=arguments[i];handler.apply(this,args)}}else if(isObject(handler)){len=arguments.length;args=new Array(len-1);for(i=1;i<len;i++)args[i-1]=arguments[i];listeners=handler.slice();len=listeners.length;for(i=0;i<len;i++)listeners[i].apply(this,args)}return true};EventEmitter.prototype.addListener=function(type,listener){var m;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",type,isFunction(listener.listener)?listener.listener:listener);if(!this._events[type])this._events[type]=listener;else if(isObject(this._events[type]))this._events[type].push(listener);else this._events[type]=[this._events[type],listener];if(isObject(this._events[type])&&!this._events[type].warned){var m;if(!isUndefined(this._maxListeners)){m=this._maxListeners}else{m=EventEmitter.defaultMaxListeners}if(m&&m>0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeof console.trace==="function"){console.trace()}}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-->0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else{while(listeners.length)this.removeListener(type,listeners[listeners.length-1])}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.listenerCount=function(emitter,type){var ret;if(!emitter._events||!emitter._events[type])ret=0;else if(isFunction(emitter._events[type]))ret=1;else ret=emitter._events[type].length;return ret};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return typeof arg==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],15:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}if(canPost){var queue=[];window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],"flyd-spring":[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"])_i["return"]()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i)}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}}}();exports.spring=spring;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _flyd=require("flyd");var _stepper3=require("./stepper");var _stepper4=_interopRequireDefault(_stepper3);var _presets=require("./presets");var _presets2=_interopRequireDefault(_presets);var loop=require("raf-loop");exports.presets=_presets2["default"];var engine=loop();function spring(val$){var _ref=arguments.length<=1||arguments[1]===undefined?_presets2["default"].noWobble:arguments[1];var _ref2=_slicedToArray(_ref,2);var k=_ref2[0];var b=_ref2[1];var vel=0;var x=val$()||0;var k$=(0,_flyd.isStream)(k)?k:(0,_flyd.stream)(k);var b$=(0,_flyd.isStream)(b)?b:(0,_flyd.stream)(b);var output$=(0,_flyd.stream)();engine.on("tick",function(delta){var destX=val$()||0;if(destX===x)return;var _stepper=(0,_stepper4["default"])(delta/1e3,x,vel,destX,k$(),b$());var _stepper2=_slicedToArray(_stepper,2);var newX=_stepper2[0];var newV=_stepper2[1];vel=newV;x=newX;output$(newX)});engine.start();return output$}},{"./presets":1,"./stepper":2,flyd:3,"raf-loop":9}]},{},[]);var flyd=require("flyd");var flydSpring=require("flyd-spring");var changeDestination=flyd.stream(0);var valueChange=flydSpring.spring(changeDestination);flyd.on(console.log.bind(console),valueChange);changeDestination(1);setTimeout(function(){changeDestination(2)},100);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"flyd": "0.2.1",
"flyd-spring": "0.0.1"
}
}
<!-- contents of this file will be placed inside the <body> -->
<div id='container'/>
<!-- 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