Skip to content

Instantly share code, notes, and snippets.

@nissoh
Last active August 29, 2015 14:24
Show Gist options
  • Save nissoh/f2079e74c13d548f251b to your computer and use it in GitHub Desktop.
Save nissoh/f2079e74c13d548f251b to your computer and use it in GitHub Desktop.
requirebin sketch
var most = require('most');
var hasTouch = 'ontouchstart' in window;
var dragEvtMap = {
START: hasTouch ? 'touchstart': 'mousedown',
END: hasTouch ? 'touchend' : 'mouseup',
HOVER: hasTouch ? 'touchmove' : 'mousemove'
};
var DROP = 0, GRAB = 1, DRAG = 2;
// The area where we want to do the dragging
var area = document.querySelector('.dragging-area');
// The thing we want to make draggable
var draggable = document.querySelector('.draggable');
// A higher-order stream (stream whose items are themselves streams)
// A mousedown DOM event generates a stream event which is
// a stream of 1 GRAB followed by DRAGs (ie mousemoves).
var drag = most.fromEvent(dragEvtMap.START, draggable)
.map(function(e) {
draggable.dataset.x = draggable.dataset.x || 0;
draggable.dataset.y = draggable.dataset.y || 0;
var initPos = {
x: e.clientX,
y: e.clientY,
};
// On Firefox, avoid the dragging to select text
e.preventDefault();
return most.fromEvent(dragEvtMap.HOVER, area)
.map(function(e) {
return eventToDragInfo(DRAG, draggable, e, initPos);
})
.startWith(eventToDragInfo(GRAB, draggable, e, initPos));
});
// A mouseup DOM event generates a stream event which is a
// stream containing a DROP.
var drop = most.fromEvent(dragEvtMap.END, area)
.map(function(e) {
return most.of(eventToDragInfo(DROP, draggable, e));
});
// Merge the drag and drop streams.
// Then use switch() to ensure that the resulting stream behaves
// like the drag stream until an event occurs on the drop stream. Then
// it will behave like the drop stream until the drag stream starts
// producing events again.
// This effectively *toggles behavior* between dragging behavior and
// dropped behavior.
most.merge(drag, drop)
.switch()
.observe(handleDrag);
var eventToDragInfo = hasTouch ? touchDragFn : mouseDragFn;
// dragOffset is undefined and unused for actions other than DRAG.
function mouseDragFn(action, target, e, initialPos) {
if (initialPos) {
var offstX = initialPos.x - e.clientX;
var offstY = initialPos.y - e.clientY;
draggable.dataset.x = (draggable.dataset.x - (offstX) - (+draggable.dataset.x)) || 0;
draggable.dataset.y = (draggable.dataset.y - (offstY) - (+draggable.dataset.y)) || 0;
}
return {
action: action,
target: target,
x: draggable.dataset.x,
y: draggable.dataset.y
};
}
function touchDragFn(action, target, e, dragOffset) {
return {
action: action,
target: target,
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
}
function handleDrag(dragInfo) {
var el = dragInfo.target;
if (dragInfo.action === GRAB) {
el.classList.add('dragging');
return;
}
if (dragInfo.action === DROP) {
el.classList.remove('dragging');
return;
}
var els = dragInfo.target.style;
els.transform = 'translate3d(' + dragInfo.x + 'px, ' + dragInfo.y + 'px, 0)';
}
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 process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){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")}},{}],2:[function(require,module,exports){var Promise=require("./Promise");var all=Promise.all;var resolve=Promise.resolve;module.exports=LinkedList;function LinkedList(){this.head=null;this.length=0}LinkedList.prototype.add=function(x){if(this.head!==null){this.head.prev=x;x.next=this.head}this.head=x;++this.length};LinkedList.prototype.remove=function(x){--this.length;if(x===this.head){this.head=this.head.next}if(x.next!==null){x.next.prev=x.prev;x.next=null}if(x.prev!==null){x.prev.next=x.next;x.prev=null}};LinkedList.prototype.isEmpty=function(){return this.length===0};LinkedList.prototype.dispose=function(){if(this.isEmpty()){return resolve()}var promises=[];var x=this.head;this.head=null;this.length=0;while(x!==null){promises.push(x.dispose());x=x.next}return all(promises)}},{"./Promise":3}],3:[function(require,module,exports){var unhandledRejection=require("when/lib/decorators/unhandledRejection");module.exports=unhandledRejection(require("when/lib/Promise"))},{"when/lib/Promise":62,"when/lib/decorators/unhandledRejection":64}],4:[function(require,module,exports){module.exports=Queue;function Queue(capPow2){this._capacity=capPow2||32;this._length=0;this._head=0}Queue.prototype.push=function(x){var len=this._length;this._checkCapacity(len+1);var i=this._head+len&this._capacity-1;this[i]=x;this._length=len+1};Queue.prototype.shift=function(){var head=this._head;var x=this[head];this[head]=void 0;this._head=head+1&this._capacity-1;this._length--;return x};Queue.prototype.isEmpty=function(){return this._length===0};Queue.prototype.length=function(){return this._length};Queue.prototype._checkCapacity=function(size){if(this._capacity<size){this._ensureCapacity(this._capacity<<1)}};Queue.prototype._ensureCapacity=function(capacity){var oldCapacity=this._capacity;this._capacity=capacity;var last=this._head+this._length;if(last>oldCapacity){copy(this,0,this,oldCapacity,last&oldCapacity-1)}};function copy(src,srcIndex,dst,dstIndex,len){for(var j=0;j<len;++j){dst[j+dstIndex]=src[j+srcIndex];src[j+srcIndex]=void 0}}},{}],5:[function(require,module,exports){module.exports=Stream;function Stream(source){this.source=source}},{}],6:[function(require,module,exports){exports.noop=noop;exports.identity=identity;exports.compose=compose;exports.cons=cons;exports.append=append;exports.drop=drop;exports.tail=tail;exports.copy=copy;exports.map=map;exports.reduce=reduce;exports.replace=replace;exports.remove=remove;exports.removeAll=removeAll;exports.findIndex=findIndex;function noop(){}function identity(x){return x}function compose(f,g){return function(x){return f(g(x))}}function cons(x,array){var l=array.length;var a=new Array(l+1);a[0]=x;for(var i=0;i<l;++i){a[i+1]=array[i]}return a}function append(x,a){var l=a.length;var b=new Array(l+1);for(var i=0;i<l;++i){b[i]=a[i]}b[l]=x;return b}function drop(n,array){var l=array.length;if(n>=l){return[]}l-=n;var a=new Array(l);for(var i=0;i<l;++i){a[i]=array[n+i]}return a}function tail(array){return drop(1,array)}function copy(array){var l=array.length;var a=new Array(l);for(var i=0;i<l;++i){a[i]=array[i]}return a}function map(f,array){var l=array.length;var a=new Array(l);for(var i=0;i<l;++i){a[i]=f(array[i])}return a}function reduce(f,z,array){var r=z;for(var i=0,l=array.length;i<l;++i){r=f(r,array[i],i)}return r}function replace(x,i,array){var l=array.length;var a=new Array(l);for(var j=0;j<l;++j){a[j]=i===j?x:array[j]}return a}function remove(index,array){var l=array.length;if(index>=array){return array}if(l===1){return[]}l-=1;var b=new Array(l);var i;for(i=0;i<index;++i){b[i]=array[i]}for(i=index;i<l;++i){b[i]=array[i+1]}return b}function removeAll(f,a){var l=a.length;var b=new Array(l);for(var x,i=0,j=0;i<l;++i){x=a[i];if(!f(x)){b[j]=x;++j}}b.length=j;return b}function findIndex(x,a){for(var i=0,l=a.length;i<l;++i){if(x===a[i]){return i}}return-1}},{}],7:[function(require,module,exports){var Stream=require("../Stream");var Pipe=require("../sink/Pipe");var runSource=require("../runSource");var noop=require("../base").noop;exports.scan=scan;exports.reduce=reduce;function scan(f,initial,stream){return new Stream(new Scan(f,initial,stream.source))}function Scan(f,z,source){this.f=f;this.value=z;this.source=source}Scan.prototype.run=function(sink,scheduler){return this.source.run(new ScanSink(this.f,this.value,sink),scheduler)};function ScanSink(f,z,sink){this.f=f;this.value=z;this.sink=sink;this.init=true}ScanSink.prototype.event=function(t,x){if(this.init){this.init=false;this.sink.event(t,this.value)}var f=this.f;this.value=f(this.value,x);this.sink.event(t,this.value)};ScanSink.prototype.error=Pipe.prototype.error;ScanSink.prototype.end=function(t){this.sink.end(t,this.value)};function reduce(f,initial,stream){return runSource(noop,new Accumulate(f,initial,stream.source))}function Accumulate(f,z,source){this.f=f;this.value=z;this.source=source}Accumulate.prototype.run=function(sink,scheduler){return this.source.run(new AccumulateSink(this.f,this.value,sink),scheduler)};function AccumulateSink(f,z,sink){this.f=f;this.value=z;this.sink=sink}AccumulateSink.prototype.event=function(t,x){var f=this.f;this.value=f(this.value,x);this.sink.event(t,this.value)};AccumulateSink.prototype.error=Pipe.prototype.error;AccumulateSink.prototype.end=function(t){this.sink.end(t,this.value)}},{"../Stream":5,"../base":6,"../runSource":42,"../sink/Pipe":48}],8:[function(require,module,exports){var combine=require("./combine").combine;exports.ap=ap;function ap(fs,xs){return combine(apply,fs,xs)}function apply(f,x){return f(x)}},{"./combine":10}],9:[function(require,module,exports){var Stream=require("../Stream");var streamOf=require("../source/core").of;var fromArray=require("../source/fromArray").fromArray;var concatMap=require("./concatMap").concatMap;var Sink=require("../sink/Pipe");var Promise=require("../Promise");var identity=require("../base").identity;exports.concat=concat;exports.cycle=cycle;exports.cons=cons;function cons(x,stream){return concat(streamOf(x),stream)}function concat(left,right){return concatMap(identity,fromArray([left,right]))}function cycle(stream){return new Stream(new Cycle(stream.source))}function Cycle(source){this.source=source}Cycle.prototype.run=function(sink,scheduler){return new CycleSink(this.source,sink,scheduler)};function CycleSink(source,sink,scheduler){this.active=true;this.sink=sink;this.scheduler=scheduler;this.source=source;this.disposable=source.run(this,scheduler)}CycleSink.prototype.error=Sink.prototype.error;CycleSink.prototype.event=function(t,x){if(!this.active){return}this.sink.event(t,x)};CycleSink.prototype.end=function(t){if(!this.active){return}var self=this;Promise.resolve(this.disposable.dispose()).catch(function(e){self.error(t,e)});this.disposable=this.source.run(this,this.scheduler)};CycleSink.prototype.dispose=function(){this.active=false;return this.disposable.dispose()}},{"../Promise":3,"../Stream":5,"../base":6,"../sink/Pipe":48,"../source/core":52,"../source/fromArray":55,"./concatMap":11}],10:[function(require,module,exports){var Stream=require("../Stream");var transform=require("./transform");var core=require("../source/core");var Pipe=require("../sink/Pipe");var IndexSink=require("../sink/IndexSink");var CompoundDisposable=require("../disposable/CompoundDisposable");var base=require("../base");var invoke=require("../invoke");var hasValue=IndexSink.hasValue;var getValue=IndexSink.getValue;var map=base.map;var tail=base.tail;exports.combineArray=combineArray;exports.combine=combine;function combine(f){return new Stream(new Combine(f,map(getSource,tail(arguments))))}function combineArray(f,streams){return streams.length===0?core.empty():streams.length===1?transform.map(f,streams[0]):new Stream(new Combine(f,map(getSource,streams)))}function getSource(stream){return stream.source}function Combine(f,sources){this.f=f;this.sources=sources}Combine.prototype.run=function(sink,scheduler){var l=this.sources.length;var disposables=new Array(l);var sinks=new Array(l);var combineSink=new CombineSink(this.f,sinks,sink);for(var indexSink,i=0;i<l;++i){indexSink=sinks[i]=new IndexSink(i,combineSink);disposables[i]=this.sources[i].run(indexSink,scheduler)}return new CompoundDisposable(disposables)};function CombineSink(f,sinks,sink){this.f=f;this.sinks=sinks;this.sink=sink;this.ready=false;this.activeCount=sinks.length}CombineSink.prototype.event=function(t){if(!this.ready){this.ready=this.sinks.every(hasValue)}if(this.ready){this.sink.event(t,invoke(this.f,map(getValue,this.sinks)))}};CombineSink.prototype.end=function(t,indexedValue){if(--this.activeCount===0){this.sink.end(t,indexedValue.value)}};CombineSink.prototype.error=Pipe.prototype.error},{"../Stream":5,"../base":6,"../disposable/CompoundDisposable":33,"../invoke":40,"../sink/IndexSink":46,"../sink/Pipe":48,"../source/core":52,"./transform":30}],11:[function(require,module,exports){var mergeConcurrently=require("./mergeConcurrently").mergeConcurrently;var map=require("./transform").map;exports.concatMap=concatMap;function concatMap(f,stream){return mergeConcurrently(1,map(f,stream))}},{"./mergeConcurrently":21,"./transform":30}],12:[function(require,module,exports){var Stream=require("../Stream");var Sink=require("../sink/Pipe");var CompoundDisposable=require("../disposable/CompoundDisposable");var PropagateTask=require("../scheduler/PropagateTask");exports.delay=delay;function delay(delayTime,stream){return delayTime<=0?stream:new Stream(new Delay(delayTime,stream.source))}function Delay(dt,source){this.dt=dt;this.source=source}Delay.prototype.run=function(sink,scheduler){var delaySink=new DelaySink(this.dt,sink,scheduler);return new CompoundDisposable([delaySink,this.source.run(delaySink,scheduler)])};function DelaySink(dt,sink,scheduler){this.dt=dt;this.sink=sink;this.scheduler=scheduler}DelaySink.prototype.dispose=function(){var self=this;this.scheduler.cancelAll(function(task){return task.sink===self.sink})};DelaySink.prototype.event=function(t,x){this.scheduler.delay(this.dt,PropagateTask.event(x,this.sink))};DelaySink.prototype.end=function(t,x){this.scheduler.delay(this.dt,PropagateTask.end(x,this.sink))};DelaySink.prototype.error=Sink.prototype.error},{"../Stream":5,"../disposable/CompoundDisposable":33,"../scheduler/PropagateTask":43,"../sink/Pipe":48}],13:[function(require,module,exports){var Stream=require("../Stream");var ValueSource=require("../source/ValueSource");exports.flatMapError=flatMapError;exports.throwError=throwError;function flatMapError(f,stream){return new Stream(new FlatMapError(f,stream.source))}function throwError(e){return new Stream(new ValueSource(error,e))}function error(t,e,sink){sink.error(t,e)}function FlatMapError(f,source){this.f=f;this.source=source}FlatMapError.prototype.run=function(sink,scheduler){return new FlatMapErrorSink(this.f,this.source,sink,scheduler)};function FlatMapErrorSink(f,source,sink,scheduler){this.f=f;this.sink=sink;this.scheduler=scheduler;this.active=true;this.disposable=source.run(this,scheduler)}FlatMapErrorSink.prototype.error=function(t,e){if(!this.active){return}this.disposable.dispose();var f=this.f;var stream=f(e);this.disposable=stream.source.run(this.sink,this.scheduler)};FlatMapErrorSink.prototype.event=function(t,x){if(!this.active){return}this.sink.event(t,x)};FlatMapErrorSink.prototype.end=function(t,x){if(!this.active){return}this.sink.end(t,x)};FlatMapErrorSink.prototype.dispose=function(){this.active=false;return this.disposable.dispose()}},{"../Stream":5,"../source/ValueSource":51}],14:[function(require,module,exports){var Stream=require("../Stream");var Sink=require("../sink/Pipe");var Filter=require("../fusion/Filter");exports.filter=filter;exports.skipRepeats=skipRepeats;exports.skipRepeatsWith=skipRepeatsWith;function filter(p,stream){return new Stream(Filter.create(p,stream.source))}function skipRepeats(stream){return skipRepeatsWith(same,stream)}function skipRepeatsWith(equals,stream){return new Stream(new SkipRepeats(equals,stream.source))}function SkipRepeats(equals,source){this.equals=equals;this.source=source}SkipRepeats.prototype.run=function(sink,scheduler){return this.source.run(new SkipRepeatsSink(this.equals,sink),scheduler)};function SkipRepeatsSink(equals,sink){this.equals=equals;this.sink=sink;this.value=void 0;this.init=true}SkipRepeatsSink.prototype.end=Sink.prototype.end;SkipRepeatsSink.prototype.error=Sink.prototype.error;SkipRepeatsSink.prototype.event=function(t,x){if(this.init){this.init=false;this.value=x;this.sink.event(t,x)}else if(!this.equals(this.value,x)){this.value=x;this.sink.event(t,x)}};function same(a,b){return a===b}},{"../Stream":5,"../fusion/Filter":37,"../sink/Pipe":48}],15:[function(require,module,exports){var mergeConcurrently=require("./mergeConcurrently").mergeConcurrently;var map=require("./transform").map;exports.flatMap=flatMap;exports.join=join;function flatMap(f,stream){return join(map(f,stream))}function join(stream){return mergeConcurrently(Infinity,stream)}},{"./mergeConcurrently":21,"./transform":30}],16:[function(require,module,exports){var Stream=require("../Stream");var Sink=require("../sink/Pipe");var AwaitingDisposable=require("../disposable/AwaitingDisposable");var CompoundDisposable=require("../disposable/CompoundDisposable");exports.flatMapEnd=flatMapEnd;function flatMapEnd(f,stream){return new Stream(new FlatMapEnd(f,stream.source))}function FlatMapEnd(f,source){this.f=f;this.source=source}FlatMapEnd.prototype.run=function(sink,scheduler){return new FlatMapEndSink(this.f,this.source,sink,scheduler)};function FlatMapEndSink(f,source,sink,scheduler){this.f=f;this.sink=sink;this.scheduler=scheduler;this.active=true;this.disposable=new AwaitingDisposable(source.run(this,scheduler))}FlatMapEndSink.prototype.error=Sink.prototype.error;FlatMapEndSink.prototype.event=function(t,x){if(!this.active){return}this.sink.event(t,x)};FlatMapEndSink.prototype.end=function(t,x){if(!this.active){return}this.dispose();var f=this.f;var stream=f(x);var disposable=stream.source.run(this.sink,this.scheduler);this.disposable=new CompoundDisposable([this.disposable,disposable])};FlatMapEndSink.prototype.dispose=function(){this.active=false;return this.disposable.dispose()}},{"../Stream":5,"../disposable/AwaitingDisposable":32,"../disposable/CompoundDisposable":33,"../sink/Pipe":48}],17:[function(require,module,exports){var combine=require("./combine").combineArray;var paramsRx=/\(([^)]*)/;var liftedSuffix="_most$Stream$lifted";exports.lift=lift;function lift(f){var m=paramsRx.exec(f.toString());var body="return function "+f.name+liftedSuffix+" ("+m[1]+") {\n"+" return combine(f, arguments);\n"+"};";return new Function("combine","f",body)(combine,f)}},{"./combine":10}],18:[function(require,module,exports){var Stream=require("../Stream");var Sink=require("../sink/Pipe");var CompoundDisposable=require("../disposable/CompoundDisposable");var PropagateTask=require("../scheduler/PropagateTask");exports.throttle=throttle;exports.debounce=debounce;function throttle(period,stream){return new Stream(new Throttle(period,stream.source))}function Throttle(period,source){this.dt=period;this.source=source}Throttle.prototype.run=function(sink,scheduler){return this.source.run(new ThrottleSink(this.dt,sink),scheduler)};function ThrottleSink(dt,sink){this.time=0;this.dt=dt;this.sink=sink}ThrottleSink.prototype.event=function(t,x){if(t>=this.time){this.time=t+this.dt;this.sink.event(t,x)}};ThrottleSink.prototype.end=function(t,e){return Sink.prototype.end.call(this,t,e)};ThrottleSink.prototype.error=Sink.prototype.error;function debounce(period,stream){return new Stream(new Debounce(period,stream.source))}function Debounce(dt,source){this.dt=dt;this.source=source}Debounce.prototype.run=function(sink,scheduler){return new DebounceSink(this.dt,this.source,sink,scheduler)};function DebounceSink(dt,source,sink,scheduler){this.dt=dt;this.sink=sink;this.scheduler=scheduler;this.value=void 0;this.timer=null;var sourceDisposable=source.run(this,scheduler);this.disposable=new CompoundDisposable([this,sourceDisposable])}DebounceSink.prototype.event=function(t,x){this._clearTimer();this.value=x;this.timer=this.scheduler.delay(this.dt,PropagateTask.event(x,this.sink))};DebounceSink.prototype.end=function(t,x){if(this._clearTimer()){this.sink.event(t,this.value);this.value=void 0}this.sink.end(t,x)};DebounceSink.prototype.error=function(t,x){this._clearTimer();this.sink.error(t,x)};DebounceSink.prototype.dispose=function(){this._clearTimer()};DebounceSink.prototype._clearTimer=function(){if(this.timer===null){return false}this.timer.cancel();this.timer=null;return true}},{"../Stream":5,"../disposable/CompoundDisposable":33,"../scheduler/PropagateTask":43,"../sink/Pipe":48}],19:[function(require,module,exports){var Stream=require("../Stream");var Pipe=require("../sink/Pipe");exports.loop=loop;function loop(stepper,seed,stream){return new Stream(new Loop(stepper,seed,stream.source))}function Loop(stepper,seed,source){this.step=stepper;this.seed=seed;this.source=source}Loop.prototype.run=function(sink,scheduler){return this.source.run(new LoopSink(this.step,this.seed,sink),scheduler)};function LoopSink(stepper,seed,sink){this.step=stepper;this.seed=seed;this.sink=sink}LoopSink.prototype.error=Pipe.prototype.error;LoopSink.prototype.event=function(t,x){var result=this.step(this.seed,x);this.seed=result.seed;this.sink.event(t,result.value)};LoopSink.prototype.end=function(t){this.sink.end(t,this.seed)}},{"../Stream":5,"../sink/Pipe":48}],20:[function(require,module,exports){var empty=require("../Stream").empty;var fromArray=require("../source/fromArray").fromArray;var mergeConcurrently=require("./mergeConcurrently").mergeConcurrently;var copy=require("../base").copy;exports.merge=merge;exports.mergeArray=mergeArray;function merge(){return mergeArray(copy(arguments))}function mergeArray(streams){var l=streams.length;return l===0?empty():l===1?streams[0]:mergeConcurrently(l,fromArray(streams))}},{"../Stream":5,"../base":6,"../source/fromArray":55,"./mergeConcurrently":21}],21:[function(require,module,exports){var Stream=require("../Stream");var AwaitingDisposable=require("../disposable/AwaitingDisposable");var LinkedList=require("../LinkedList");var Promise=require("../Promise");var resolve=Promise.resolve;var all=Promise.all;exports.mergeConcurrently=mergeConcurrently;function mergeConcurrently(concurrency,stream){return new Stream(new MergeConcurrently(concurrency,stream.source))}function MergeConcurrently(concurrency,source){this.concurrency=concurrency;this.source=source}MergeConcurrently.prototype.run=function(sink,scheduler){return new Outer(this.concurrency,this.source,sink,scheduler)};function Outer(concurrency,source,sink,scheduler){this.concurrency=concurrency;this.sink=sink;this.scheduler=scheduler;this.pending=[];this.current=new LinkedList;this.disposable=new AwaitingDisposable(source.run(this,scheduler));this.active=true}Outer.prototype.event=function(t,x){this._addInner(t,x)};Outer.prototype._addInner=function(t,stream){if(this.current.length<this.concurrency){this._startInner(t,stream)}else{this.pending.push(stream)}};Outer.prototype._startInner=function(t,stream){var innerSink=new Inner(t,this,this.sink);this.current.add(innerSink);innerSink.disposable=stream.source.run(innerSink,this.scheduler)};Outer.prototype.end=function(t,x){this.active=false;this.disposable.dispose();this._checkEnd(t,x)};Outer.prototype.error=function(t,e){this.active=false;this.sink.error(t,e)};Outer.prototype.dispose=function(){this.active=false;this.pending.length=0;return all([this.disposable.dispose(),this.current.dispose()])};Outer.prototype._endInner=function(t,x,inner){this.current.remove(inner);var self=this;resolve(inner.dispose()).catch(function(e){self.error(t,e)});if(this.pending.length===0){this._checkEnd(t,x)}else{this._startInner(t,this.pending.shift())}};Outer.prototype._checkEnd=function(t,x){if(!this.active&&this.current.isEmpty()){this.sink.end(t,x)}};function Inner(time,outer,sink){this.prev=this.next=null;this.time=time;this.outer=outer;this.sink=sink;this.disposable=void 0}Inner.prototype.event=function(t,x){this.sink.event(Math.max(t,this.time),x)};Inner.prototype.end=function(t,x){this.outer._endInner(Math.max(t,this.time),x,this)};Inner.prototype.error=function(t,e){this.outer.error(Math.max(t,this.time),e)};Inner.prototype.dispose=function(){return this.disposable.dispose()}},{"../LinkedList":2,"../Promise":3,"../Stream":5,"../disposable/AwaitingDisposable":32}],22:[function(require,module,exports){var runSource=require("../runSource");var noop=require("../base").noop;exports.observe=observe;exports.drain=drain;function observe(f,stream){return runSource(f,stream.source)}function drain(stream){return runSource(noop,stream.source)}},{"../base":6,"../runSource":42}],23:[function(require,module,exports){var Stream=require("../Stream");var resolve=require("../Promise").resolve;var fatal=require("../fatalError");exports.fromPromise=fromPromise;exports.await=await;function fromPromise(p){return new Stream(new PromiseSource(p))}function PromiseSource(p){this.promise=p}PromiseSource.prototype.run=function(sink,scheduler){return new PromiseProducer(this.promise,sink,scheduler)};function PromiseProducer(p,sink,scheduler){this.sink=sink;this.scheduler=scheduler;this.active=true;var self=this;resolve(p).then(function(x){self._emit(self.scheduler.now(),x)}).catch(function(e){self._error(self.scheduler.now(),e)})}PromiseProducer.prototype._emit=function(t,x){if(!this.active){return}this.sink.event(t,x);this.sink.end(t,void 0)};PromiseProducer.prototype._error=function(t,e){if(!this.active){return}this.sink.error(t,e)};PromiseProducer.prototype.dispose=function(){this.active=false};function await(stream){return new Stream(new Await(stream.source))}function Await(source){this.source=source}Await.prototype.run=function(sink,scheduler){return this.source.run(new AwaitSink(sink,scheduler),scheduler)};function AwaitSink(sink,scheduler){this.sink=sink;this.scheduler=scheduler;this.queue=void 0}AwaitSink.prototype.event=function(t,promise){var self=this;this.queue=resolve(this.queue).then(function(){return self._event(t,promise)}).catch(function(e){return self._error(t,e)})};AwaitSink.prototype.end=function(t,x){var self=this;this.queue=resolve(this.queue).then(function(){return self._end(t,x)}).catch(function(e){return self._error(t,e)})};AwaitSink.prototype.error=function(t,e){var self=this;this.queue=resolve(this.queue).then(function(){return self._error(t,e)}).catch(fatal)};AwaitSink.prototype._error=function(t,e){try{this.sink.error(Math.max(t,this.scheduler.now()),e)}catch(e){fatal(e);throw e}};AwaitSink.prototype._event=function(t,promise){var self=this;return promise.then(function(x){self.sink.event(Math.max(t,self.scheduler.now()),x)})};AwaitSink.prototype._end=function(t,x){var self=this;return resolve(x).then(function(x){self.sink.end(Math.max(t,self.scheduler.now()),x)})}},{"../Promise":3,"../Stream":5,"../fatalError":36}],24:[function(require,module,exports){var Stream=require("../Stream");var Pipe=require("../sink/Pipe");var CompoundDisposable=require("../disposable/CompoundDisposable");var base=require("../base");var invoke=require("../invoke");exports.sample=sample;exports.sampleWith=sampleWith;exports.sampleArray=sampleArray;function sample(f,sampler){return sampleArray(f,sampler,base.drop(2,arguments))}function sampleWith(sampler,stream){return new Stream(new Sampler(base.identity,sampler.source,[stream.source]))}function sampleArray(f,sampler,streams){return new Stream(new Sampler(f,sampler.source,base.map(getSource,streams)))}function getSource(stream){return stream.source}function Sampler(f,sampler,sources){this.f=f;this.sampler=sampler;this.sources=sources}Sampler.prototype.run=function(sink,scheduler){var l=this.sources.length;var disposables=new Array(l+1);var sinks=new Array(l);var sampleSink=new SampleSink(this.f,sinks,sink);for(var hold,i=0;i<l;++i){hold=sinks[i]=new Hold(sampleSink);disposables[i]=this.sources[i].run(hold,scheduler)}disposables[i]=this.sampler.run(sampleSink,scheduler);return new CompoundDisposable(disposables)};function Hold(sink){this.sink=sink;this.hasValue=false}Hold.prototype.event=function(t,x){this.value=x;this.hasValue=true;this.sink._notify(this)};Hold.prototype.end=base.noop;Hold.prototype.error=Pipe.prototype.error;function SampleSink(f,sinks,sink){this.f=f;this.sinks=sinks;this.sink=sink;this.active=false}SampleSink.prototype._notify=function(){if(!this.active){this.active=this.sinks.every(hasValue)}};SampleSink.prototype.event=function(t){if(this.active){this.sink.event(t,invoke(this.f,base.map(getValue,this.sinks)))}};SampleSink.prototype.end=Pipe.prototype.end;SampleSink.prototype.error=Pipe.prototype.error;function hasValue(hold){return hold.hasValue}function getValue(hold){return hold.value}},{"../Stream":5,"../base":6,"../disposable/CompoundDisposable":33,"../invoke":40,"../sink/Pipe":48}],25:[function(require,module,exports){var Stream=require("../Stream");var Sink=require("../sink/Pipe");var core=require("../source/core");var AwaitingDisposable=require("../disposable/AwaitingDisposable");exports.take=take;exports.skip=skip;exports.slice=slice;exports.takeWhile=takeWhile;exports.skipWhile=skipWhile;function take(n,stream){return slice(0,n,stream)}function skip(n,stream){return slice(n,Infinity,stream)}function slice(start,end,stream){return end<=start?core.empty():new Stream(new Slice(start,end,stream.source))}function Slice(min,max,source){this.skip=min;this.take=max-min;this.source=source}Slice.prototype.run=function(sink,scheduler){return new SliceSink(this.skip,this.take,this.source,sink,scheduler)};function SliceSink(skip,take,source,sink,scheduler){this.skip=skip;this.take=take;this.sink=sink;this.disposable=new AwaitingDisposable(source.run(this,scheduler))}SliceSink.prototype.end=Sink.prototype.end;SliceSink.prototype.error=Sink.prototype.error;SliceSink.prototype.event=function(t,x){if(this.skip>0){this.skip-=1;return}if(this.take===0){return}this.take-=1;this.sink.event(t,x);if(this.take===0){this.dispose();this.sink.end(t,x)}};SliceSink.prototype.dispose=function(){return this.disposable.dispose()};function takeWhile(p,stream){return new Stream(new TakeWhile(p,stream.source))}function TakeWhile(p,source){this.p=p;this.source=source}TakeWhile.prototype.run=function(sink,scheduler){return new TakeWhileSink(this.p,this.source,sink,scheduler)};function TakeWhileSink(p,source,sink,scheduler){this.p=p;this.sink=sink;this.active=true;this.disposable=new AwaitingDisposable(source.run(this,scheduler))}TakeWhileSink.prototype.end=Sink.prototype.end;TakeWhileSink.prototype.error=Sink.prototype.error;TakeWhileSink.prototype.event=function(t,x){if(!this.active){return}var p=this.p;this.active=p(x);if(this.active){this.sink.event(t,x)}else{this.dispose();this.sink.end(t,x)}};TakeWhileSink.prototype.dispose=function(){return this.disposable.dispose()};function skipWhile(p,stream){return new Stream(new SkipWhile(p,stream.source))}function SkipWhile(p,source){this.p=p;this.source=source}SkipWhile.prototype.run=function(sink,scheduler){return this.source.run(new SkipWhileSink(this.p,sink),scheduler)};function SkipWhileSink(p,sink){this.p=p;this.sink=sink;this.skipping=true}SkipWhileSink.prototype.end=Sink.prototype.end;SkipWhileSink.prototype.error=Sink.prototype.error;SkipWhileSink.prototype.event=function(t,x){if(this.skipping){var p=this.p;this.skipping=p(x);if(this.skipping){return}}this.sink.event(t,x)}},{"../Stream":5,"../disposable/AwaitingDisposable":32,"../sink/Pipe":48,"../source/core":52}],26:[function(require,module,exports){var Stream=require("../Stream");var MulticastSource=require("../source/MulticastSource");var until=require("./timeslice").takeUntil;var mergeConcurrently=require("./mergeConcurrently").mergeConcurrently;var map=require("./transform").map;exports.switch=switchLatest;function switchLatest(stream){var upstream=new Stream(new MulticastSource(stream.source));return mergeConcurrently(1,map(untilNext,upstream));function untilNext(s){return until(upstream,s)}}},{"../Stream":5,"../source/MulticastSource":50,"./mergeConcurrently":21,"./timeslice":27,"./transform":30}],27:[function(require,module,exports){var Stream=require("../Stream");var Pipe=require("../sink/Pipe");var CompoundDisposable=require("../disposable/CompoundDisposable");var core=require("../source/core");var join=require("../combinator/flatMap").join;var take=require("../combinator/slice").take;var noop=require("../base").noop;var streamOf=core.of;var never=core.never;exports.during=during;exports.takeUntil=takeUntil;exports.skipUntil=skipUntil;function takeUntil(signal,stream){return between(streamOf(),signal,stream)}function skipUntil(signal,stream){return between(signal,never(),stream)}function during(timeWindow,stream){return between(timeWindow,join(timeWindow),stream)}function between(start,end,stream){return new Stream(new Within(take(1,start).source,take(1,end).source,stream.source))}function Within(minSignal,maxSignal,source){this.minSignal=minSignal;this.maxSignal=maxSignal;this.source=source}Within.prototype.run=function(sink,scheduler){var min=new MinBound(this.minSignal,sink,scheduler);var max=new MaxBound(this.maxSignal,sink,scheduler);var disposable=this.source.run(new WithinSink(min,max,sink),scheduler);return new CompoundDisposable([min,max,disposable])};function WithinSink(min,max,sink){this.min=min;this.max=max;this.sink=sink}WithinSink.prototype.event=function(t,x){if(t>=this.min.value&&t<this.max.value){this.sink.event(t,x)}};WithinSink.prototype.error=Pipe.prototype.error;WithinSink.prototype.end=Pipe.prototype.end;function MinBound(signal,sink,scheduler){this.value=Infinity;this.sink=sink;this.disposable=signal.run(this,scheduler)}MinBound.prototype.event=function(t){if(t<this.value){this.value=t}};MinBound.prototype.end=noop;MinBound.prototype.error=Pipe.prototype.error;MinBound.prototype.dispose=function(){return this.disposable.dispose()};function MaxBound(signal,sink,scheduler){
this.value=Infinity;this.sink=sink;this.disposable=signal.run(this,scheduler)}MaxBound.prototype.event=function(t,x){if(t<this.value){this.value=t;this.sink.end(t,x)}};MaxBound.prototype.end=noop;MaxBound.prototype.error=Pipe.prototype.error;MaxBound.prototype.dispose=function(){return this.disposable.dispose()}},{"../Stream":5,"../base":6,"../combinator/flatMap":15,"../combinator/slice":25,"../disposable/CompoundDisposable":33,"../sink/Pipe":48,"../source/core":52}],28:[function(require,module,exports){var Stream=require("../Stream");var Sink=require("../sink/Pipe");exports.timestamp=timestamp;function timestamp(stream){return new Stream(new Timestamp(stream.source))}function Timestamp(source){this.source=source}Timestamp.prototype.run=function(sink,scheduler){return this.source.run(new TimestampSink(sink),scheduler)};function TimestampSink(sink){this.sink=sink}TimestampSink.prototype.end=Sink.prototype.end;TimestampSink.prototype.error=Sink.prototype.error;TimestampSink.prototype.event=function(t,x){this.sink.event(t,new TimeValue(t,x))};function TimeValue(t,x){this.time=t;this.value=x}},{"../Stream":5,"../sink/Pipe":48}],29:[function(require,module,exports){var Stream=require("../Stream");exports.transduce=transduce;function transduce(transducer,stream){return new Stream(new Transduce(transducer,stream.source))}function Transduce(transducer,source){this.transducer=transducer;this.source=source}Transduce.prototype.run=function(sink,scheduler){var xf=this.transducer(new Transformer(sink));return this.source.run(new TransduceSink(getTxHandler(xf),sink),scheduler)};function TransduceSink(adapter,sink){this.xf=adapter;this.sink=sink}TransduceSink.prototype.event=function(t,x){var next=this.xf.step(t,x);return this.xf.isReduced(next)?this.sink.end(t,this.xf.getResult(next)):next};TransduceSink.prototype.end=function(t,x){return this.xf.result(x)};TransduceSink.prototype.error=function(t,e){return this.sink.error(t,e)};function Transformer(sink){this.time=-Infinity;this.sink=sink}Transformer.prototype["@@transducer/init"]=Transformer.prototype.init=function(){};Transformer.prototype["@@transducer/step"]=Transformer.prototype.step=function(t,x){if(!isNaN(t)){this.time=Math.max(t,this.time)}return this.sink.event(this.time,x)};Transformer.prototype["@@transducer/result"]=Transformer.prototype.result=function(x){return this.sink.end(this.time,x)};function getTxHandler(tx){return typeof tx["@@transducer/step"]==="function"?new TxAdapter(tx):new LegacyTxAdapter(tx)}function TxAdapter(tx){this.tx=tx}TxAdapter.prototype.step=function(t,x){return this.tx["@@transducer/step"](t,x)};TxAdapter.prototype.result=function(x){return this.tx["@@transducer/result"](x)};TxAdapter.prototype.isReduced=function(x){return x!=null&&x["@@transducer/reduced"]};TxAdapter.prototype.getResult=function(x){return x["@@transducer/value"]};function LegacyTxAdapter(tx){this.tx=tx}LegacyTxAdapter.prototype.step=function(t,x){return this.tx.step(t,x)};LegacyTxAdapter.prototype.result=function(x){return this.tx.result(x)};LegacyTxAdapter.prototype.isReduced=function(x){return x!=null&&x.__transducers_reduced__};LegacyTxAdapter.prototype.getResult=function(x){return x.value}},{"../Stream":5}],30:[function(require,module,exports){var Stream=require("../Stream");var Map=require("../fusion/Map");exports.map=map;exports.constant=constant;exports.tap=tap;function map(f,stream){return new Stream(Map.create(f,stream.source))}function constant(x,stream){return map(function(){return x},stream)}function tap(f,stream){return map(function(x){f(x);return x},stream)}},{"../Stream":5,"../fusion/Map":39}],31:[function(require,module,exports){var Stream=require("../Stream");var transform=require("./transform");var core=require("../source/core");var Sink=require("../sink/Pipe");var IndexSink=require("../sink/IndexSink");var CompoundDisposable=require("../disposable/CompoundDisposable");var base=require("../base");var invoke=require("../invoke");var Queue=require("../Queue");var map=base.map;var tail=base.tail;exports.zip=zip;exports.zipArray=zipArray;function zip(f){return zipArray(f,tail(arguments))}function zipArray(f,streams){return streams.length===0?core.empty():streams.length===1?transform.map(f,streams[0]):new Stream(new Zip(f,map(getSource,streams)))}function getSource(stream){return stream.source}function Zip(f,sources){this.f=f;this.sources=sources}Zip.prototype.run=function(sink,scheduler){var l=this.sources.length;var disposables=new Array(l);var sinks=new Array(l);var buffers=new Array(l);var zipSink=new ZipSink(this.f,buffers,sinks,sink);for(var indexSink,i=0;i<l;++i){buffers[i]=new Queue;indexSink=sinks[i]=new IndexSink(i,zipSink);disposables[i]=this.sources[i].run(indexSink,scheduler)}return new CompoundDisposable(disposables)};function ZipSink(f,buffers,sinks,sink){this.f=f;this.sinks=sinks;this.sink=sink;this.buffers=buffers}ZipSink.prototype.event=function(t,indexedValue){var buffers=this.buffers;var buffer=buffers[indexedValue.index];buffer.push(indexedValue.value);if(buffer.length()===1){if(!ready(this.buffers)){return}emitZipped(this.f,t,buffers,this.sink);if(ended(this.buffers,this.sinks)){this.sink.end(t,void 0)}}};ZipSink.prototype.end=function(t,indexedValue){var buffer=this.buffers[indexedValue.index];if(buffer.isEmpty()){this.sink.end(t,indexedValue.value)}};ZipSink.prototype.error=Sink.prototype.error;function emitZipped(f,t,buffers,sink){sink.event(t,invoke(f,map(head,buffers)))}function head(buffer){return buffer.shift()}function ended(buffers,sinks){for(var i=0,l=buffers.length;i<l;++i){if(buffers[i].isEmpty()&&!sinks[i].active){return true}}return false}function ready(buffers){for(var i=0,l=buffers.length;i<l;++i){if(buffers[i].isEmpty()){return false}}return true}},{"../Queue":4,"../Stream":5,"../base":6,"../disposable/CompoundDisposable":33,"../invoke":40,"../sink/IndexSink":46,"../sink/Pipe":48,"../source/core":52,"./transform":30}],32:[function(require,module,exports){module.exports=AwaitingDisposable;function AwaitingDisposable(disposable){this.disposed=false;this.disposable=disposable;this.value=void 0}AwaitingDisposable.prototype.dispose=function(){if(!this.disposed){this.disposed=true;this.value=this.disposable.dispose()}return this.value}},{}],33:[function(require,module,exports){var all=require("../Promise").all;var map=require("../base").map;module.exports=CompoundDisposable;function CompoundDisposable(disposables){this.disposed=false;this.disposables=disposables}CompoundDisposable.prototype.dispose=function(){if(this.disposed){return}this.disposed=true;return all(map(dispose,this.disposables))};function dispose(disposable){return disposable.dispose()}},{"../Promise":3,"../base":6}],34:[function(require,module,exports){module.exports=Disposable;function Disposable(f,data){this.disposed=false;this._dispose=f;this._data=data}Disposable.prototype.dispose=function(){if(this.disposed){return}this.disposed=true;return this._dispose(this._data)}},{}],35:[function(require,module,exports){var noop=require("../base").noop;module.exports=EmptyDisposable;function EmptyDisposable(){}EmptyDisposable.prototype.dispose=noop},{"../base":6}],36:[function(require,module,exports){module.exports=fatalError;function fatalError(e){setTimeout(function(){throw e},0)}},{}],37:[function(require,module,exports){var Pipe=require("../sink/Pipe");module.exports=Filter;function Filter(p,source){this.p=p;this.source=source}Filter.create=function createFilter(p,source){if(source instanceof Filter){return new Filter(and(source.p,p),source.source)}return new Filter(p,source)};Filter.prototype.run=function(sink,scheduler){return this.source.run(new FilterSink(this.p,sink),scheduler)};function FilterSink(p,sink){this.p=p;this.sink=sink}FilterSink.prototype.end=Pipe.prototype.end;FilterSink.prototype.error=Pipe.prototype.error;FilterSink.prototype.event=function(t,x){var p=this.p;p(x)&&this.sink.event(t,x)};function and(p,q){return function(x){return p(x)&&q(x)}}},{"../sink/Pipe":48}],38:[function(require,module,exports){var Pipe=require("../sink/Pipe");module.exports=FilterMap;function FilterMap(p,f,source){this.p=p;this.f=f;this.source=source}FilterMap.prototype.run=function(sink,scheduler){return this.source.run(new FilterMapSink(this.p,this.f,sink),scheduler)};function FilterMapSink(p,f,sink){this.p=p;this.f=f;this.sink=sink}FilterMapSink.prototype.event=function(t,x){var f=this.f;var p=this.p;p(x)&&this.sink.event(t,f(x))};FilterMapSink.prototype.end=Pipe.prototype.end;FilterMapSink.prototype.error=Pipe.prototype.error},{"../sink/Pipe":48}],39:[function(require,module,exports){var Pipe=require("../sink/Pipe");var Filter=require("./Filter");var FilterMap=require("./FilterMap");var base=require("../base");module.exports=Map;function Map(f,source){this.f=f;this.source=source}Map.create=function createMap(f,source){if(source instanceof Map){return new Map(base.compose(f,source.f),source.source)}if(source instanceof Filter){return new FilterMap(source.p,f,source.source)}if(source instanceof FilterMap){return new FilterMap(source.p,base.compose(f,source.f),source.source)}return new Map(f,source)};Map.prototype.run=function(sink,scheduler){return this.source.run(new MapSink(this.f,sink),scheduler)};function MapSink(f,sink){this.f=f;this.sink=sink}MapSink.prototype.end=Pipe.prototype.end;MapSink.prototype.error=Pipe.prototype.error;MapSink.prototype.event=function(t,x){var f=this.f;this.sink.event(t,f(x))}},{"../base":6,"../sink/Pipe":48,"./Filter":37,"./FilterMap":38}],40:[function(require,module,exports){module.exports=invoke;function invoke(f,args){switch(args.length){case 0:return f();case 1:return f(args[0]);case 2:return f(args[0],args[1]);case 3:return f(args[0],args[1],args[2]);case 4:return f(args[0],args[1],args[2],args[3]);case 5:return f(args[0],args[1],args[2],args[3],args[4]);default:return f.apply(void 0,args)}}},{}],41:[function(require,module,exports){exports.isIterable=isIterable;exports.getIterator=getIterator;exports.makeIterable=makeIterable;var iteratorSymbol;if(typeof Set==="function"&&typeof(new Set)["@@iterator"]==="function"){iteratorSymbol="@@iterator"}else{iteratorSymbol=typeof Symbol==="function"&&Symbol.iterator||"_es6shim_iterator_"}function isIterable(o){return typeof o[iteratorSymbol]==="function"}function getIterator(o){return o[iteratorSymbol]()}function makeIterable(f,o){o[iteratorSymbol]=f;return o}},{}],42:[function(require,module,exports){var Promise=require("./Promise");var Observer=require("./sink/Observer");var scheduler=require("./scheduler/defaultScheduler");var resolve=Promise.resolve;module.exports=runSource;function runSource(f,source){return new Promise(function(res,rej){var disposable;var observer=new Observer(f,function(x){disposeThen(res,rej,disposable,x)},function(e){disposeThen(rej,rej,disposable,e)});disposable=source.run(observer,scheduler)})}function disposeThen(res,rej,disposable,x){resolve(disposable.dispose()).then(function(){res(x)},rej)}},{"./Promise":3,"./scheduler/defaultScheduler":45,"./sink/Observer":47}],43:[function(require,module,exports){var fatal=require("../fatalError");module.exports=PropagateTask;function PropagateTask(run,value,sink){this._run=run;this.value=value;this.sink=sink;this.active=true}PropagateTask.event=function(value,sink){return new PropagateTask(emit,value,sink)};PropagateTask.end=function(value,sink){return new PropagateTask(end,value,sink)};PropagateTask.error=function(value,sink){return new PropagateTask(error,value,sink)};PropagateTask.prototype.dispose=function(){this.active=false};PropagateTask.prototype.run=function(t){if(!this.active){return}this._run(t,this.value,this.sink)};PropagateTask.prototype.error=function(t,e){if(!this.active){return fatal(e)}this.sink.error(t,e)};function error(t,e,sink){sink.error(t,e)}function emit(t,x,sink){sink.event(t,x)}function end(t,x,sink){sink.end(t,x)}},{"../fatalError":36}],44:[function(require,module,exports){var base=require("./../base");var Promise=require("./../Promise");var findIndex=base.findIndex;module.exports=Scheduler;function ScheduledTask(delay,period,task,scheduler){this.time=delay;this.period=period;this.task=task;this.scheduler=scheduler;this.active=true}ScheduledTask.prototype.run=function(){return this.task.run(this.time)};ScheduledTask.prototype.error=function(e){return this.task.error(this.time,e)};ScheduledTask.prototype.cancel=function(){this.scheduler.cancel(this);return this.task.dispose()};function runTask(task){try{return task.run()}catch(e){return task.error(e)}}function Scheduler(setTimer,clearTimer,now){this.now=now;this._setTimer=setTimer;this._clearTimer=clearTimer;this._timer=null;this._nextArrival=0;this._tasks=[];var self=this;this._runReadyTasksBound=function(){self._runReadyTasks()}}Scheduler.prototype.asap=function(task){var scheduled=new ScheduledTask(0,-1,task,this);return Promise.resolve(scheduled).then(runTask)};Scheduler.prototype.delay=function(delay,task){return this.schedule(delay,-1,task)};Scheduler.prototype.periodic=function(period,task){return this.schedule(0,period,task)};Scheduler.prototype.schedule=function(delay,period,task){var st=new ScheduledTask(this.now()+Math.max(0,delay),period,task,this);insertByTime(st,this._tasks);this._scheduleNextRun(st);return st};Scheduler.prototype.cancel=function(task){task.active=false;var i=findIndex(task,this._tasks);if(i>=0){this._tasks.splice(i,1);this._reschedule()}};Scheduler.prototype.cancelAll=function(f){this._tasks=base.removeAll(f,this._tasks);this._reschedule()};Scheduler.prototype._reschedule=function(){if(this._tasks.length===0){this._unschedule()}else{this._scheduleNextRun(this.now())}};Scheduler.prototype._unschedule=function(){this._clearTimer(this._timer);this._timer=null};Scheduler.prototype._runReadyTasks=function(){this._timer=null;var now=this.now();var tasks=this._tasks;var l=tasks.length;var toRun=[];var task,i;for(i=0;i<l;++i){task=tasks[i];if(task.time>now){break}if(task.active){toRun.push(task)}}this._tasks=base.drop(i,tasks);for(i=0,l=toRun.length;i<l;++i){task=toRun[i];runTask(task);if(task.period>=0&&task.active){task.time=task.time+task.period;insertByTime(task,this._tasks)}}this._scheduleNextRun(this.now())};Scheduler.prototype._scheduleNextRun=function(now){if(this._tasks.length===0){return}var nextArrival=this._tasks[0].time;if(this._timer===null){this._schedulerNextArrival(nextArrival,now)}else if(nextArrival<this._nextArrival){this._unschedule();this._schedulerNextArrival(nextArrival,now)}};Scheduler.prototype._schedulerNextArrival=function(nextArrival,now){this._nextArrival=nextArrival;var delay=Math.max(0,nextArrival-now);this._timer=this._setTimer(this._runReadyTasksBound,delay)};function insertByTime(task,tasks){tasks.splice(findInsertion(task,tasks),0,task)}function findInsertion(task,tasks){var i=binarySearch(task,tasks);var l=tasks.length;var t=task.time;while(i<l&&t===tasks[i].time){++i}return i}function binarySearch(x,sortedArray){var lo=0;var hi=sortedArray.length;var mid,y;while(lo<hi){mid=Math.floor((lo+hi)/2);y=sortedArray[mid];if(x.time===y.time){return mid}else if(x.time<y.time){hi=mid}else{lo=mid+1}}return hi}},{"./../Promise":3,"./../base":6}],45:[function(require,module,exports){var Scheduler=require("./Scheduler");module.exports=new Scheduler(defaultSetTimer,defaultClearTimer,Date.now);function defaultSetTimer(f,ms){return setTimeout(f,ms)}function defaultClearTimer(t){return clearTimeout(t)}},{"./Scheduler":44}],46:[function(require,module,exports){var Sink=require("./Pipe");module.exports=IndexSink;IndexSink.hasValue=hasValue;IndexSink.getValue=getValue;function hasValue(indexSink){return indexSink.hasValue}function getValue(indexSink){return indexSink.value}function IndexSink(i,sink){this.index=i;this.sink=sink;this.active=true;this.hasValue=false;this.value=void 0}IndexSink.prototype.event=function(t,x){if(!this.active){return}this.value=x;this.hasValue=true;this.sink.event(t,this)};IndexSink.prototype.end=function(t,x){if(!this.active){return}this.active=false;this.sink.end(t,{index:this.index,value:x})};IndexSink.prototype.error=Sink.prototype.error},{"./Pipe":48}],47:[function(require,module,exports){module.exports=Observer;function Observer(event,end,error){this._event=event;this._end=end;this._error=error;this.active=true}Observer.prototype.event=function(t,x){if(!this.active){return}this._event(x)};Observer.prototype.end=function(t,x){if(!this.active){return}this.active=false;this._end(x)};Observer.prototype.error=function(t,e){this.active=false;this._error(e)}},{}],48:[function(require,module,exports){module.exports=Pipe;function Pipe(sink){this.sink=sink}Pipe.prototype.event=function(t,x){return this.sink.event(t,x)};Pipe.prototype.end=function(t,x){return this.sink.end(t,x)};Pipe.prototype.error=function(t,e){return this.sink.error(t,e)}},{}],49:[function(require,module,exports){var base=require("../base");var resolve=require("../Promise").resolve;var Disposable=require("../disposable/Disposable");module.exports=AsyncSource;function AsyncSource(source){this.source=source}AsyncSource.prototype.run=function(sink,scheduler){var task=new StartAsyncTask(this.source,sink,scheduler);var disposable=scheduler.asap(task);return new Disposable(asyncDispose,disposable)};function asyncDispose(disposable){return resolve(disposable).then(dispose)}function dispose(disposable){if(disposable===void 0){return}return disposable.dispose()}function StartAsyncTask(source,sink,scheduler){this.source=source;this.sink=sink;this.scheduler=scheduler}StartAsyncTask.prototype.run=function(){return this.source.run(this.sink,this.scheduler)};StartAsyncTask.prototype.error=function(t,e){this.sink.error(t,e)};StartAsyncTask.prototype.dispose=base.noop},{"../Promise":3,"../base":6,"../disposable/Disposable":34}],50:[function(require,module,exports){var base=require("../base");var resolve=require("../Promise").resolve;module.exports=MulticastSource;function MulticastSource(source){this.source=source;this.sink=new MulticastSink;this._disposable=void 0}MulticastSource.prototype.run=function(sink,scheduler){var n=this.sink.add(sink);if(n===1){this._disposable=this.source.run(this.sink,scheduler)}return new MulticastDisposable(this,sink)};MulticastSource.prototype._dispose=function(){return resolve(this._disposable).then(dispose)};function dispose(disposable){if(disposable===void 0){return}return disposable.dispose()}function MulticastDisposable(source,sink){this.source=source;this.sink=sink}MulticastDisposable.prototype.dispose=function(){var s=this.source;var remaining=s.sink.remove(this.sink);return remaining===0&&s._dispose()};function MulticastSink(){this.sinks=[]}MulticastSink.prototype.add=function(sink){this.sinks=base.append(sink,this.sinks);return this.sinks.length};MulticastSink.prototype.remove=function(sink){this.sinks=base.remove(base.findIndex(sink,this.sinks),this.sinks);return this.sinks.length};MulticastSink.prototype.event=function(t,x){var s=this.sinks;for(var i=0;i<s.length;++i){s[i].event(t,x)}};MulticastSink.prototype.end=function(t,x){var s=this.sinks;for(var i=0;i<s.length;++i){s[i].end(t,x)}};MulticastSink.prototype.error=function(t,e){var s=this.sinks;for(var i=0;i<s.length;++i){s[i].error(t,e)}}},{"../Promise":3,"../base":6}],51:[function(require,module,exports){var PropagateTask=require("../scheduler/PropagateTask");module.exports=ValueSource;function ValueSource(emit,x){this.emit=emit;this.value=x}ValueSource.prototype.run=function(sink,scheduler){return new ValueProducer(this.emit,this.value,sink,scheduler)};function ValueProducer(emit,x,sink,scheduler){this.task=new PropagateTask(emit,x,sink);scheduler.asap(this.task)}ValueProducer.prototype.dispose=function(){return this.task.dispose()}},{"../scheduler/PropagateTask":43}],52:[function(require,module,exports){var Stream=require("../Stream");var ValueSource=require("../source/ValueSource");var Disposable=require("../disposable/Disposable");var EmptyDisposable=require("../disposable/EmptyDisposable");var PropagateTask=require("../scheduler/PropagateTask");exports.of=streamOf;exports.empty=empty;exports.never=never;function streamOf(x){return new Stream(new ValueSource(emit,x))}function emit(t,x,sink){sink.event(0,x);sink.end(0,void 0)}function empty(){return EMPTY}function EmptySource(){}EmptySource.prototype.run=function(sink,scheduler){var task=PropagateTask.end(void 0,sink);scheduler.asap(task);return new Disposable(dispose,task)};function dispose(task){return task.dispose()}var EMPTY=new Stream(new EmptySource);function never(){return NEVER}function NeverSource(){}NeverSource.prototype.run=function(){return new EmptyDisposable};var NEVER=new Stream(new NeverSource)},{"../Stream":5,"../disposable/Disposable":34,"../disposable/EmptyDisposable":35,"../scheduler/PropagateTask":43,"../source/ValueSource":51}],53:[function(require,module,exports){var Stream=require("../Stream");var MulticastSource=require("./MulticastSource");var AsyncSource=require("./AsyncSource");exports.create=create;function create(run){return new Stream(new MulticastSource(new AsyncSource(new SubscriberSource(run))))}function SubscriberSource(subscribe){this._subscribe=subscribe}SubscriberSource.prototype.run=function(sink,scheduler){return new Subscription(sink,scheduler,this._subscribe)};function Subscription(sink,scheduler,subscribe){this.sink=sink;this.scheduler=scheduler;this.active=true;var s=this;this._unsubscribe=subscribe(add,end,error);function add(x){s._add(x)}function end(x){s._end(x)}function error(e){s._error(e)}}Subscription.prototype._add=function(x){if(!this.active){return}tryEvent(this.scheduler.now(),x,this.sink)};Subscription.prototype._end=function(x){if(!this.active){return}this.active=false;tryEnd(this.scheduler.now(),x,this.sink)};Subscription.prototype._error=function(x){this.active=false;this.sink.error(this.scheduler.now(),x)};Subscription.prototype.dispose=function(){this.active=false;if(typeof this._unsubscribe==="function"){return this._unsubscribe()}};function tryEvent(t,x,sink){try{sink.event(t,x)}catch(e){sink.error(t,e)}}function tryEnd(t,x,sink){try{sink.end(t,x)}catch(e){sink.error(t,e)}}},{"../Stream":5,"./AsyncSource":49,"./MulticastSource":50}],54:[function(require,module,exports){var fromArray=require("./fromArray").fromArray;var isIterable=require("../iterable").isIterable;var fromIterable=require("./fromIterable").fromIterable;exports.from=from;function from(a){if(Array.isArray(a)){return fromArray(a)}if(isIterable(a)){return fromIterable(a)}throw new TypeError("not iterable: "+a)}},{"../iterable":41,"./fromArray":55,"./fromIterable":57}],55:[function(require,module,exports){var Stream=require("../Stream");var PropagateTask=require("../scheduler/PropagateTask");exports.fromArray=fromArray;function fromArray(a){return new Stream(new ArraySource(a))}function ArraySource(a){this.array=a}ArraySource.prototype.run=function(sink,scheduler){return new ArrayProducer(this.array,sink,scheduler)};function ArrayProducer(array,sink,scheduler){this.scheduler=scheduler;this.task=new PropagateTask(runProducer,array,sink);scheduler.asap(this.task)}ArrayProducer.prototype.dispose=function(){return this.task.dispose()};function runProducer(t,array,sink){return produce(this,array,sink,0)}function produce(task,array,sink,k){for(var i=k,l=array.length;i<l&&task.active;++i){sink.event(0,array[i])}return end();function end(){return task.active&&sink.end(0)}}},{"../Stream":5,"../scheduler/PropagateTask":43}],56:[function(require,module,exports){var Stream=require("../Stream");var MulticastSource=require("./MulticastSource");var PropagateTask=require("../scheduler/PropagateTask");var base=require("../base");exports.fromEvent=fromEvent;function fromEvent(event,source){var s;if(typeof source.addEventListener==="function"){s=new MulticastSource(new EventSource(event,source))}else if(typeof source.addListener==="function"){s=new EventEmitterSource(event,source)}else{throw new Error("source must support addEventListener or addListener")}return new Stream(s)}function EventSource(event,source){this.event=event;this.source=source}EventSource.prototype.run=function(sink,scheduler){return new EventAdapter(this.event,this.source,sink,scheduler)};function EventAdapter(event,source,sink,scheduler){this.event=event;this.source=source;this.sink=sink;var self=this;function addEvent(ev){tryEvent(scheduler.now(),ev,self.sink)}this._addEvent=this._init(addEvent,event,source)}EventAdapter.prototype._init=function(addEvent,event,source){source.addEventListener(event,addEvent,false);return addEvent};EventAdapter.prototype.dispose=function(){if(typeof this.source.removeEventListener!=="function"){throw new Error("source must support removeEventListener or removeListener")}this.source.removeEventListener(this.event,this._addEvent,false)};function EventEmitterSource(event,source){this.event=event;this.source=source}EventEmitterSource.prototype.run=function(sink,scheduler){return new EventEmitterAdapter(this.event,this.source,sink,scheduler)};function EventEmitterAdapter(event,source,sink,scheduler){this.event=event;this.source=source;this.sink=sink;var self=this;function addEvent(ev){scheduler.asap(new PropagateTask(tryEvent,ev,self.sink))}this._addEvent=this._init(addEvent,event,source)}EventEmitterAdapter.prototype._init=function(addEvent,event,source){var doAddEvent=addEvent;doAddEvent=function addVarargs(a){return arguments.length>1?addEvent(base.copy(arguments)):addEvent(a)};source.addListener(event,doAddEvent);return doAddEvent};EventEmitterAdapter.prototype.dispose=function(){if(typeof this.source.removeListener!=="function"){throw new Error("source must support removeEventListener or removeListener")}this.source.removeListener(this.event,this._addEvent)};function tryEvent(t,x,sink){try{sink.event(t,x)}catch(e){sink.error(t,e)}}},{"../Stream":5,"../base":6,"../scheduler/PropagateTask":43,"./MulticastSource":50}],57:[function(require,module,exports){var Stream=require("../Stream");var getIterator=require("../iterable").getIterator;var PropagateTask=require("../scheduler/PropagateTask");exports.fromIterable=fromIterable;function fromIterable(iterable){return new Stream(new IterableSource(iterable))}function IterableSource(iterable){this.iterable=iterable}IterableSource.prototype.run=function(sink,scheduler){return new IteratorProducer(getIterator(this.iterable),sink,scheduler)};function IteratorProducer(iterator,sink,scheduler){this.scheduler=scheduler;this.iterator=iterator;this.task=new PropagateTask(runProducer,this,sink);scheduler.asap(this.task)}IteratorProducer.prototype.dispose=function(){return this.task.dispose()};function runProducer(t,producer,sink){var x=producer.iterator.next();if(x.done){sink.end(t,x.value)}else{sink.event(t,x.value)}producer.scheduler.asap(producer.task)}},{"../Stream":5,"../iterable":41,"../scheduler/PropagateTask":43}],58:[function(require,module,exports){var Stream=require("../Stream");var Promise=require("../Promise");var base=require("../base");exports.generate=generate;function generate(f){return new Stream(new GenerateSource(f,base.tail(arguments)))}function GenerateSource(f,args){this.f=f;this.args=args}GenerateSource.prototype.run=function(sink,scheduler){return new Generate(this.f.apply(void 0,this.args),sink,scheduler)};function Generate(iterator,sink,scheduler){this.iterator=iterator;this.sink=sink;this.scheduler=scheduler;this.active=true;var self=this;function err(e){self.sink.error(self.scheduler.now(),e)}Promise.resolve(this).then(next).catch(err)}function next(generate,x){return generate.active?handle(generate,generate.iterator.next(x)):x}function handle(generate,result){if(result.done){return generate.sink.end(generate.scheduler.now(),result.value)}return Promise.resolve(result.value).then(function(x){return emit(generate,x)},function(e){return error(generate,e)})}function emit(generate,x){generate.sink.event(generate.scheduler.now(),x);return next(generate,x)}function error(generate,e){return handle(generate,generate.iterator.throw(e))}Generate.prototype.dispose=function(){this.active=false}},{"../Promise":3,"../Stream":5,"../base":6}],59:[function(require,module,exports){var Stream=require("../Stream");var Promise=require("../Promise");exports.iterate=iterate;function iterate(f,x){return new Stream(new IterateSource(f,x))}function IterateSource(f,x){this.f=f;this.value=x}IterateSource.prototype.run=function(sink,scheduler){return new Iterate(this.f,this.value,sink,scheduler)};function Iterate(f,initial,sink,scheduler){this.f=f;this.sink=sink;this.scheduler=scheduler;this.active=true;var x=initial;var self=this;function err(e){self.sink.error(self.scheduler.now(),e)}function start(iterate){return stepIterate(iterate,x)}Promise.resolve(this).then(start).catch(err)}Iterate.prototype.dispose=function(){this.active=false};function stepIterate(iterate,x){iterate.sink.event(iterate.scheduler.now(),x);if(!iterate.active){return x}var f=iterate.f;return Promise.resolve(f(x)).then(function(y){return continueIterate(iterate,y)})}function continueIterate(iterate,x){return!iterate.active?iterate.value:stepIterate(iterate,x)}},{"../Promise":3,"../Stream":5}],60:[function(require,module,exports){var Stream=require("../Stream");var Disposable=require("../disposable/Disposable");var MulticastSource=require("./MulticastSource");var PropagateTask=require("../scheduler/PropagateTask");exports.periodic=periodic;function periodic(period,value){return new Stream(new MulticastSource(new Periodic(period,value)))}function Periodic(period,value){this.period=period;this.value=value}Periodic.prototype.run=function(sink,scheduler){var task=scheduler.periodic(this.period,new PropagateTask(emit,this.value,sink));return new Disposable(cancelTask,task)};function cancelTask(task){task.cancel()}function emit(t,x,sink){sink.event(t,x)}},{"../Stream":5,"../disposable/Disposable":34,"../scheduler/PropagateTask":43,"./MulticastSource":50}],61:[function(require,module,exports){var Stream=require("../Stream");var Promise=require("../Promise");exports.unfold=unfold;function unfold(f,seed){return new Stream(new UnfoldSource(f,seed))}function UnfoldSource(f,seed){this.f=f;this.value=seed}UnfoldSource.prototype.run=function(sink,scheduler){return new Unfold(this.f,this.value,sink,scheduler)};function Unfold(f,x,sink,scheduler){this.f=f;this.sink=sink;this.scheduler=scheduler;this.active=true;var self=this;function err(e){self.sink.error(self.scheduler.now(),e)}function start(unfold){return stepUnfold(unfold,x)}Promise.resolve(this).then(start).catch(err)}Unfold.prototype.dispose=function(){this.active=false};function stepUnfold(unfold,x){var f=unfold.f;return Promise.resolve(f(x)).then(function(tuple){return continueUnfold(unfold,tuple)})}function continueUnfold(unfold,tuple){if(tuple.done){unfold.sink.end(unfold.scheduler.now(),tuple.value);return tuple.value}unfold.sink.event(unfold.scheduler.now(),tuple.value);if(!unfold.active){return tuple.value}return stepUnfold(unfold,tuple.seed)}},{"../Promise":3,"../Stream":5}],62:[function(require,module,exports){(function(define){"use strict";define(function(require){var makePromise=require("./makePromise");var Scheduler=require("./Scheduler");var async=require("./env").asap;return makePromise({scheduler:new Scheduler(async)})})})(typeof define==="function"&&define.amd?define:function(factory){module.exports=factory(require)})},{"./Scheduler":63,"./env":65,"./makePromise":67}],63:[function(require,module,exports){(function(define){"use strict";define(function(){function Scheduler(async){this._async=async;this._running=false;this._queue=this;this._queueLen=0;this._afterQueue={};this._afterQueueLen=0;var self=this;this.drain=function(){self._drain()}}Scheduler.prototype.enqueue=function(task){this._queue[this._queueLen++]=task;this.run()};Scheduler.prototype.afterQueue=function(task){this._afterQueue[this._afterQueueLen++]=task;this.run()};Scheduler.prototype.run=function(){if(!this._running){this._running=true;this._async(this.drain)}};Scheduler.prototype._drain=function(){var i=0;for(;i<this._queueLen;++i){
this._queue[i].run();this._queue[i]=void 0}this._queueLen=0;this._running=false;for(i=0;i<this._afterQueueLen;++i){this._afterQueue[i].run();this._afterQueue[i]=void 0}this._afterQueueLen=0};return Scheduler})})(typeof define==="function"&&define.amd?define:function(factory){module.exports=factory()})},{}],64:[function(require,module,exports){(function(define){"use strict";define(function(require){var setTimer=require("../env").setTimer;var format=require("../format");return function unhandledRejection(Promise){var logError=noop;var logInfo=noop;var localConsole;if(typeof console!=="undefined"){localConsole=console;logError=typeof localConsole.error!=="undefined"?function(e){localConsole.error(e)}:function(e){localConsole.log(e)};logInfo=typeof localConsole.info!=="undefined"?function(e){localConsole.info(e)}:function(e){localConsole.log(e)}}Promise.onPotentiallyUnhandledRejection=function(rejection){enqueue(report,rejection)};Promise.onPotentiallyUnhandledRejectionHandled=function(rejection){enqueue(unreport,rejection)};Promise.onFatalRejection=function(rejection){enqueue(throwit,rejection.value)};var tasks=[];var reported=[];var running=null;function report(r){if(!r.handled){reported.push(r);logError("Potentially unhandled rejection ["+r.id+"] "+format.formatError(r.value))}}function unreport(r){var i=reported.indexOf(r);if(i>=0){reported.splice(i,1);logInfo("Handled previous rejection ["+r.id+"] "+format.formatObject(r.value))}}function enqueue(f,x){tasks.push(f,x);if(running===null){running=setTimer(flush,0)}}function flush(){running=null;while(tasks.length>0){tasks.shift()(tasks.shift())}}return Promise};function throwit(e){throw e}function noop(){}})})(typeof define==="function"&&define.amd?define:function(factory){module.exports=factory(require)})},{"../env":65,"../format":66}],65:[function(require,module,exports){(function(process){(function(define){"use strict";define(function(require){var MutationObs;var capturedSetTimeout=typeof setTimeout!=="undefined"&&setTimeout;var setTimer=function(f,ms){return setTimeout(f,ms)};var clearTimer=function(t){return clearTimeout(t)};var asap=function(f){return capturedSetTimeout(f,0)};if(isNode()){asap=function(f){return process.nextTick(f)}}else if(MutationObs=hasMutationObserver()){asap=initMutationObserver(MutationObs)}else if(!capturedSetTimeout){var vertxRequire=require;var vertx=vertxRequire("vertx");setTimer=function(f,ms){return vertx.setTimer(ms,f)};clearTimer=vertx.cancelTimer;asap=vertx.runOnLoop||vertx.runOnContext}return{setTimer:setTimer,clearTimer:clearTimer,asap:asap};function isNode(){return typeof process!=="undefined"&&Object.prototype.toString.call(process)==="[object process]"}function hasMutationObserver(){return typeof MutationObserver==="function"&&MutationObserver||typeof WebKitMutationObserver==="function"&&WebKitMutationObserver}function initMutationObserver(MutationObserver){var scheduled;var node=document.createTextNode("");var o=new MutationObserver(run);o.observe(node,{characterData:true});function run(){var f=scheduled;scheduled=void 0;f()}var i=0;return function(f){scheduled=f;node.data=i^=1}}})})(typeof define==="function"&&define.amd?define:function(factory){module.exports=factory(require)})}).call(this,require("_process"))},{_process:1}],66:[function(require,module,exports){(function(define){"use strict";define(function(){return{formatError:formatError,formatObject:formatObject,tryStringify:tryStringify};function formatError(e){var s=typeof e==="object"&&e!==null&&e.stack?e.stack:formatObject(e);return e instanceof Error?s:s+" (WARNING: non-Error used)"}function formatObject(o){var s=String(o);if(s==="[object Object]"&&typeof JSON!=="undefined"){s=tryStringify(o,s)}return s}function tryStringify(x,defaultValue){try{return JSON.stringify(x)}catch(e){return defaultValue}}})})(typeof define==="function"&&define.amd?define:function(factory){module.exports=factory()})},{}],67:[function(require,module,exports){(function(process){(function(define){"use strict";define(function(){return function makePromise(environment){var tasks=environment.scheduler;var emitRejection=initEmitRejection();var objectCreate=Object.create||function(proto){function Child(){}Child.prototype=proto;return new Child};function Promise(resolver,handler){this._handler=resolver===Handler?handler:init(resolver)}function init(resolver){var handler=new Pending;try{resolver(promiseResolve,promiseReject,promiseNotify)}catch(e){promiseReject(e)}return handler;function promiseResolve(x){handler.resolve(x)}function promiseReject(reason){handler.reject(reason)}function promiseNotify(x){handler.notify(x)}}Promise.resolve=resolve;Promise.reject=reject;Promise.never=never;Promise._defer=defer;Promise._handler=getHandler;function resolve(x){return isPromise(x)?x:new Promise(Handler,new Async(getHandler(x)))}function reject(x){return new Promise(Handler,new Async(new Rejected(x)))}function never(){return foreverPendingPromise}function defer(){return new Promise(Handler,new Pending)}Promise.prototype.then=function(onFulfilled,onRejected,onProgress){var parent=this._handler;var state=parent.join().state();if(typeof onFulfilled!=="function"&&state>0||typeof onRejected!=="function"&&state<0){return new this.constructor(Handler,parent)}var p=this._beget();var child=p._handler;parent.chain(child,parent.receiver,onFulfilled,onRejected,onProgress);return p};Promise.prototype["catch"]=function(onRejected){return this.then(void 0,onRejected)};Promise.prototype._beget=function(){return begetFrom(this._handler,this.constructor)};function begetFrom(parent,Promise){var child=new Pending(parent.receiver,parent.join().context);return new Promise(Handler,child)}Promise.all=all;Promise.race=race;Promise._traverse=traverse;function all(promises){return traverseWith(snd,null,promises)}function traverse(f,promises){return traverseWith(tryCatch2,f,promises)}function traverseWith(tryMap,f,promises){var handler=typeof f==="function"?mapAt:settleAt;var resolver=new Pending;var pending=promises.length>>>0;var results=new Array(pending);for(var i=0,x;i<promises.length&&!resolver.resolved;++i){x=promises[i];if(x===void 0&&!(i in promises)){--pending;continue}traverseAt(promises,handler,i,x,resolver)}if(pending===0){resolver.become(new Fulfilled(results))}return new Promise(Handler,resolver);function mapAt(i,x,resolver){if(!resolver.resolved){traverseAt(promises,settleAt,i,tryMap(f,x,i),resolver)}}function settleAt(i,x,resolver){results[i]=x;if(--pending===0){resolver.become(new Fulfilled(results))}}}function traverseAt(promises,handler,i,x,resolver){if(maybeThenable(x)){var h=getHandlerMaybeThenable(x);var s=h.state();if(s===0){h.fold(handler,i,void 0,resolver)}else if(s>0){handler(i,h.value,resolver)}else{resolver.become(h);visitRemaining(promises,i+1,h)}}else{handler(i,x,resolver)}}Promise._visitRemaining=visitRemaining;function visitRemaining(promises,start,handler){for(var i=start;i<promises.length;++i){markAsHandled(getHandler(promises[i]),handler)}}function markAsHandled(h,handler){if(h===handler){return}var s=h.state();if(s===0){h.visit(h,void 0,h._unreport)}else if(s<0){h._unreport()}}function race(promises){if(typeof promises!=="object"||promises===null){return reject(new TypeError("non-iterable passed to race()"))}return promises.length===0?never():promises.length===1?resolve(promises[0]):runRace(promises)}function runRace(promises){var resolver=new Pending;var i,x,h;for(i=0;i<promises.length;++i){x=promises[i];if(x===void 0&&!(i in promises)){continue}h=getHandler(x);if(h.state()!==0){resolver.become(h);visitRemaining(promises,i+1,h);break}else{h.visit(resolver,resolver.resolve,resolver.reject)}}return new Promise(Handler,resolver)}function getHandler(x){if(isPromise(x)){return x._handler.join()}return maybeThenable(x)?getHandlerUntrusted(x):new Fulfilled(x)}function getHandlerMaybeThenable(x){return isPromise(x)?x._handler.join():getHandlerUntrusted(x)}function getHandlerUntrusted(x){try{var untrustedThen=x.then;return typeof untrustedThen==="function"?new Thenable(untrustedThen,x):new Fulfilled(x)}catch(e){return new Rejected(e)}}function Handler(){}Handler.prototype.when=Handler.prototype.become=Handler.prototype.notify=Handler.prototype.fail=Handler.prototype._unreport=Handler.prototype._report=noop;Handler.prototype._state=0;Handler.prototype.state=function(){return this._state};Handler.prototype.join=function(){var h=this;while(h.handler!==void 0){h=h.handler}return h};Handler.prototype.chain=function(to,receiver,fulfilled,rejected,progress){this.when({resolver:to,receiver:receiver,fulfilled:fulfilled,rejected:rejected,progress:progress})};Handler.prototype.visit=function(receiver,fulfilled,rejected,progress){this.chain(failIfRejected,receiver,fulfilled,rejected,progress)};Handler.prototype.fold=function(f,z,c,to){this.when(new Fold(f,z,c,to))};function FailIfRejected(){}inherit(Handler,FailIfRejected);FailIfRejected.prototype.become=function(h){h.fail()};var failIfRejected=new FailIfRejected;function Pending(receiver,inheritedContext){Promise.createContext(this,inheritedContext);this.consumers=void 0;this.receiver=receiver;this.handler=void 0;this.resolved=false}inherit(Handler,Pending);Pending.prototype._state=0;Pending.prototype.resolve=function(x){this.become(getHandler(x))};Pending.prototype.reject=function(x){if(this.resolved){return}this.become(new Rejected(x))};Pending.prototype.join=function(){if(!this.resolved){return this}var h=this;while(h.handler!==void 0){h=h.handler;if(h===this){return this.handler=cycle()}}return h};Pending.prototype.run=function(){var q=this.consumers;var handler=this.handler;this.handler=this.handler.join();this.consumers=void 0;for(var i=0;i<q.length;++i){handler.when(q[i])}};Pending.prototype.become=function(handler){if(this.resolved){return}this.resolved=true;this.handler=handler;if(this.consumers!==void 0){tasks.enqueue(this)}if(this.context!==void 0){handler._report(this.context)}};Pending.prototype.when=function(continuation){if(this.resolved){tasks.enqueue(new ContinuationTask(continuation,this.handler))}else{if(this.consumers===void 0){this.consumers=[continuation]}else{this.consumers.push(continuation)}}};Pending.prototype.notify=function(x){if(!this.resolved){tasks.enqueue(new ProgressTask(x,this))}};Pending.prototype.fail=function(context){var c=typeof context==="undefined"?this.context:context;this.resolved&&this.handler.join().fail(c)};Pending.prototype._report=function(context){this.resolved&&this.handler.join()._report(context)};Pending.prototype._unreport=function(){this.resolved&&this.handler.join()._unreport()};function Async(handler){this.handler=handler}inherit(Handler,Async);Async.prototype.when=function(continuation){tasks.enqueue(new ContinuationTask(continuation,this))};Async.prototype._report=function(context){this.join()._report(context)};Async.prototype._unreport=function(){this.join()._unreport()};function Thenable(then,thenable){Pending.call(this);tasks.enqueue(new AssimilateTask(then,thenable,this))}inherit(Pending,Thenable);function Fulfilled(x){Promise.createContext(this);this.value=x}inherit(Handler,Fulfilled);Fulfilled.prototype._state=1;Fulfilled.prototype.fold=function(f,z,c,to){runContinuation3(f,z,this,c,to)};Fulfilled.prototype.when=function(cont){runContinuation1(cont.fulfilled,this,cont.receiver,cont.resolver)};var errorId=0;function Rejected(x){Promise.createContext(this);this.id=++errorId;this.value=x;this.handled=false;this.reported=false;this._report()}inherit(Handler,Rejected);Rejected.prototype._state=-1;Rejected.prototype.fold=function(f,z,c,to){to.become(this)};Rejected.prototype.when=function(cont){if(typeof cont.rejected==="function"){this._unreport()}runContinuation1(cont.rejected,this,cont.receiver,cont.resolver)};Rejected.prototype._report=function(context){tasks.afterQueue(new ReportTask(this,context))};Rejected.prototype._unreport=function(){if(this.handled){return}this.handled=true;tasks.afterQueue(new UnreportTask(this))};Rejected.prototype.fail=function(context){this.reported=true;emitRejection("unhandledRejection",this);Promise.onFatalRejection(this,context===void 0?this.context:context)};function ReportTask(rejection,context){this.rejection=rejection;this.context=context}ReportTask.prototype.run=function(){if(!this.rejection.handled&&!this.rejection.reported){this.rejection.reported=true;emitRejection("unhandledRejection",this.rejection)||Promise.onPotentiallyUnhandledRejection(this.rejection,this.context)}};function UnreportTask(rejection){this.rejection=rejection}UnreportTask.prototype.run=function(){if(this.rejection.reported){emitRejection("rejectionHandled",this.rejection)||Promise.onPotentiallyUnhandledRejectionHandled(this.rejection)}};Promise.createContext=Promise.enterContext=Promise.exitContext=Promise.onPotentiallyUnhandledRejection=Promise.onPotentiallyUnhandledRejectionHandled=Promise.onFatalRejection=noop;var foreverPendingHandler=new Handler;var foreverPendingPromise=new Promise(Handler,foreverPendingHandler);function cycle(){return new Rejected(new TypeError("Promise cycle"))}function ContinuationTask(continuation,handler){this.continuation=continuation;this.handler=handler}ContinuationTask.prototype.run=function(){this.handler.join().when(this.continuation)};function ProgressTask(value,handler){this.handler=handler;this.value=value}ProgressTask.prototype.run=function(){var q=this.handler.consumers;if(q===void 0){return}for(var c,i=0;i<q.length;++i){c=q[i];runNotify(c.progress,this.value,this.handler,c.receiver,c.resolver)}};function AssimilateTask(then,thenable,resolver){this._then=then;this.thenable=thenable;this.resolver=resolver}AssimilateTask.prototype.run=function(){var h=this.resolver;tryAssimilate(this._then,this.thenable,_resolve,_reject,_notify);function _resolve(x){h.resolve(x)}function _reject(x){h.reject(x)}function _notify(x){h.notify(x)}};function tryAssimilate(then,thenable,resolve,reject,notify){try{then.call(thenable,resolve,reject,notify)}catch(e){reject(e)}}function Fold(f,z,c,to){this.f=f;this.z=z;this.c=c;this.to=to;this.resolver=failIfRejected;this.receiver=this}Fold.prototype.fulfilled=function(x){this.f.call(this.c,this.z,x,this.to)};Fold.prototype.rejected=function(x){this.to.reject(x)};Fold.prototype.progress=function(x){this.to.notify(x)};function isPromise(x){return x instanceof Promise}function maybeThenable(x){return(typeof x==="object"||typeof x==="function")&&x!==null}function runContinuation1(f,h,receiver,next){if(typeof f!=="function"){return next.become(h)}Promise.enterContext(h);tryCatchReject(f,h.value,receiver,next);Promise.exitContext()}function runContinuation3(f,x,h,receiver,next){if(typeof f!=="function"){return next.become(h)}Promise.enterContext(h);tryCatchReject3(f,x,h.value,receiver,next);Promise.exitContext()}function runNotify(f,x,h,receiver,next){if(typeof f!=="function"){return next.notify(x)}Promise.enterContext(h);tryCatchReturn(f,x,receiver,next);Promise.exitContext()}function tryCatch2(f,a,b){try{return f(a,b)}catch(e){return reject(e)}}function tryCatchReject(f,x,thisArg,next){try{next.become(getHandler(f.call(thisArg,x)))}catch(e){next.become(new Rejected(e))}}function tryCatchReject3(f,x,y,thisArg,next){try{f.call(thisArg,x,y,next)}catch(e){next.become(new Rejected(e))}}function tryCatchReturn(f,x,thisArg,next){try{next.notify(f.call(thisArg,x))}catch(e){next.notify(e)}}function inherit(Parent,Child){Child.prototype=objectCreate(Parent.prototype);Child.prototype.constructor=Child}function snd(x,y){return y}function noop(){}function initEmitRejection(){if(typeof process!=="undefined"&&process!==null&&typeof process.emit==="function"){return function(type,rejection){return type==="unhandledRejection"?process.emit(type,rejection.value,rejection):process.emit(type,rejection)}}else if(typeof self!=="undefined"&&typeof CustomEvent==="function"){return function(noop,self,CustomEvent){var hasCustomEvent=false;try{var ev=new CustomEvent("unhandledRejection");hasCustomEvent=ev instanceof CustomEvent}catch(e){}return!hasCustomEvent?noop:function(type,rejection){var ev=new CustomEvent(type,{detail:{reason:rejection.value,key:rejection},bubbles:false,cancelable:true});return!self.dispatchEvent(ev)}}(noop,self,CustomEvent)}return noop}return Promise}})})(typeof define==="function"&&define.amd?define:function(factory){module.exports=factory()})}).call(this,require("_process"))},{_process:1}],most:[function(require,module,exports){var Stream=require("./lib/Stream");var base=require("./lib/base");var core=require("./lib/source/core");var from=require("./lib/source/from").from;var periodic=require("./lib/source/periodic").periodic;exports.Stream=Stream;exports.of=Stream.of=core.of;exports.empty=Stream.empty=core.empty;exports.never=core.never;exports.from=from;exports.periodic=periodic;var create=require("./lib/source/create");exports.create=create.create;var events=require("./lib/source/fromEvent");exports.fromEvent=events.fromEvent;var lift=require("./lib/combinator/lift").lift;exports.lift=lift;var observe=require("./lib/combinator/observe");exports.observe=observe.observe;exports.forEach=observe.observe;exports.drain=observe.drain;Stream.prototype.observe=Stream.prototype.forEach=function(f){return observe.observe(f,this)};Stream.prototype.drain=function(){return observe.drain(this)};var loop=require("./lib/combinator/loop").loop;exports.loop=loop;Stream.prototype.loop=function(stepper,seed){return loop(stepper,seed,this)};var accumulate=require("./lib/combinator/accumulate");exports.scan=accumulate.scan;exports.reduce=accumulate.reduce;Stream.prototype.scan=function(f,initial){return accumulate.scan(f,initial,this)};Stream.prototype.reduce=function(f,initial){return accumulate.reduce(f,initial,this)};var unfold=require("./lib/source/unfold");var iterate=require("./lib/source/iterate");var generate=require("./lib/source/generate");var build=require("./lib/combinator/build");exports.unfold=unfold.unfold;exports.iterate=iterate.iterate;exports.generate=generate.generate;exports.concat=build.cycle;exports.concat=build.concat;exports.startWith=build.cons;Stream.prototype.cycle=function(){return build.cycle(this)};Stream.prototype.concat=function(tail){return build.concat(this,tail)};Stream.prototype.startWith=function(x){return build.cons(x,this)};var transform=require("./lib/combinator/transform");var applicative=require("./lib/combinator/applicative");exports.map=transform.map;exports.constant=transform.constant;exports.tap=transform.tap;exports.ap=applicative.ap;Stream.prototype.map=function(f){return transform.map(f,this)};Stream.prototype.ap=function(xs){return applicative.ap(this,xs)};Stream.prototype.constant=function(x){return transform.constant(x,this)};Stream.prototype.tap=function(f){return transform.tap(f,this)};var transduce=require("./lib/combinator/transduce");exports.transduce=transduce.transduce;Stream.prototype.transduce=function(transducer){return transduce.transduce(transducer,this)};var flatMap=require("./lib/combinator/flatMap");exports.flatMap=exports.chain=flatMap.flatMap;exports.join=flatMap.join;Stream.prototype.flatMap=Stream.prototype.chain=function(f){return flatMap.flatMap(f,this)};Stream.prototype.join=function(){return flatMap.join(this)};var flatMapEnd=require("./lib/combinator/flatMapEnd").flatMapEnd;exports.flatMapEnd=flatMapEnd;Stream.prototype.flatMapEnd=function(f){return flatMapEnd(f,this)};var concatMap=require("./lib/combinator/concatMap").concatMap;exports.concatMap=concatMap;Stream.prototype.concatMap=function(f){return concatMap(f,this)};var merge=require("./lib/combinator/merge");exports.merge=merge.merge;Stream.prototype.merge=function(){return merge.mergeArray(base.cons(this,arguments))};var combine=require("./lib/combinator/combine");exports.combine=combine.combine;Stream.prototype.combine=function(f){return combine.combineArray(f,base.replace(this,0,arguments))};var sample=require("./lib/combinator/sample");exports.sample=sample.sample;exports.sampleWith=sample.sampleWith;Stream.prototype.sampleWith=function(sampler){return sample.sampleWith(sampler,this)};Stream.prototype.sample=function(f){return sample.sampleArray(f,this,base.tail(arguments))};var zip=require("./lib/combinator/zip");exports.zip=zip.zip;Stream.prototype.zip=function(f){return zip.zipArray(f,base.replace(this,0,arguments))};var switchLatest=require("./lib/combinator/switch").switch;exports.switch=switchLatest;exports.switchLatest=switchLatest;Stream.prototype.switch=Stream.prototype.switchLatest=function(){return switchLatest(this)};var filter=require("./lib/combinator/filter");exports.filter=filter.filter;exports.skipRepeats=exports.distinct=filter.skipRepeats;exports.skipRepeatsWith=exports.distinctBy=filter.skipRepeatsWith;Stream.prototype.filter=function(p){return filter.filter(p,this)};Stream.prototype.skipRepeats=function(){return filter.skipRepeats(this)};Stream.prototype.skipRepeatsWith=function(equals){return filter.skipRepeatsWith(equals,this)};var slice=require("./lib/combinator/slice");exports.take=slice.take;exports.skip=slice.skip;exports.slice=slice.slice;exports.takeWhile=slice.takeWhile;exports.skipWhile=slice.skipWhile;Stream.prototype.take=function(n){return slice.take(n,this)};Stream.prototype.skip=function(n){return slice.skip(n,this)};Stream.prototype.slice=function(start,end){return slice.slice(start,end,this)};Stream.prototype.takeWhile=function(p){return slice.takeWhile(p,this)};Stream.prototype.skipWhile=function(p){return slice.skipWhile(p,this)};var timeslice=require("./lib/combinator/timeslice");exports.until=exports.takeUntil=timeslice.takeUntil;exports.since=exports.skipUntil=timeslice.skipUntil;exports.during=timeslice.during;Stream.prototype.until=Stream.prototype.takeUntil=function(signal){return timeslice.takeUntil(signal,this)};Stream.prototype.since=Stream.prototype.skipUntil=function(signal){return timeslice.skipUntil(signal,this)};Stream.prototype.during=function(timeWindow){return timeslice.during(timeWindow,this)};var delay=require("./lib/combinator/delay").delay;exports.delay=delay;Stream.prototype.delay=function(delayTime){return delay(delayTime,this)};var timestamp=require("./lib/combinator/timestamp").timestamp;exports.timestamp=timestamp;Stream.prototype.timestamp=function(){return timestamp(this)};var limit=require("./lib/combinator/limit");exports.throttle=limit.throttle;exports.debounce=limit.debounce;Stream.prototype.throttle=function(period){return limit.throttle(period,this)};Stream.prototype.debounce=function(period){return limit.debounce(period,this)};var promises=require("./lib/combinator/promises");exports.fromPromise=promises.fromPromise;exports.await=promises.await;Stream.prototype.await=function(){return promises.await(this)};var errors=require("./lib/combinator/errors");exports.flatMapError=errors.flatMapError;exports.throwError=errors.throwError;Stream.prototype.flatMapError=function(f){return errors.flatMapError(f,this)}},{"./lib/Stream":5,"./lib/base":6,"./lib/combinator/accumulate":7,"./lib/combinator/applicative":8,"./lib/combinator/build":9,"./lib/combinator/combine":10,"./lib/combinator/concatMap":11,"./lib/combinator/delay":12,"./lib/combinator/errors":13,"./lib/combinator/filter":14,"./lib/combinator/flatMap":15,"./lib/combinator/flatMapEnd":16,"./lib/combinator/lift":17,"./lib/combinator/limit":18,"./lib/combinator/loop":19,"./lib/combinator/merge":20,"./lib/combinator/observe":22,"./lib/combinator/promises":23,"./lib/combinator/sample":24,"./lib/combinator/slice":25,"./lib/combinator/switch":26,"./lib/combinator/timeslice":27,"./lib/combinator/timestamp":28,"./lib/combinator/transduce":29,"./lib/combinator/transform":30,"./lib/combinator/zip":31,"./lib/source/core":52,"./lib/source/create":53,"./lib/source/from":54,"./lib/source/fromEvent":56,"./lib/source/generate":58,"./lib/source/iterate":59,"./lib/source/periodic":60,"./lib/source/unfold":61}]},{},[]);var most=require("most");var hasTouch="ontouchstart"in window;var dragEvtMap={START:hasTouch?"touchstart":"mousedown",END:hasTouch?"touchend":"mouseup",HOVER:hasTouch?"touchmove":"mousemove"};var DROP=0,GRAB=1,DRAG=2;var area=document.querySelector(".dragging-area");var draggable=document.querySelector(".draggable");var drag=most.fromEvent(dragEvtMap.START,draggable).map(function(e){draggable.dataset.x=draggable.dataset.x||0;draggable.dataset.y=draggable.dataset.y||0;var initPos={x:e.clientX,y:e.clientY};e.preventDefault();return most.fromEvent(dragEvtMap.HOVER,area).map(function(e){return eventToDragInfo(DRAG,draggable,e,initPos)}).startWith(eventToDragInfo(GRAB,draggable,e,initPos))});var drop=most.fromEvent(dragEvtMap.END,area).map(function(e){return most.of(eventToDragInfo(DROP,draggable,e))});most.merge(drag,drop).switch().observe(handleDrag);var eventToDragInfo=hasTouch?touchDragFn:mouseDragFn;function mouseDragFn(action,target,e,initialPos){if(initialPos){var offstX=initialPos.x-e.clientX;var offstY=initialPos.y-e.clientY;draggable.dataset.x=draggable.dataset.x-offstX-+draggable.dataset.x||0;draggable.dataset.y=draggable.dataset.y-offstY-+draggable.dataset.y||0}return{action:action,target:target,x:draggable.dataset.x,y:draggable.dataset.y}}function touchDragFn(action,target,e,dragOffset){return{action:action,target:target,x:e.touches[0].clientX,y:e.touches[0].clientY}}function handleDrag(dragInfo){var el=dragInfo.target;if(dragInfo.action===GRAB){el.classList.add("dragging");return}if(dragInfo.action===DROP){el.classList.remove("dragging");return}var els=dragInfo.target.style;els.transform="translate3d("+dragInfo.x+"px, "+dragInfo.y+"px, 0)"}
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"most": "0.14.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<div class="dragging-area">
<div class="box draggable"><span class="rest">Drag</span><span class="drag">Drop</span> me, baby!</div>
</div>
<!-- contents of this file will be placed inside the <head> -->
<style>
html, body {
height: 100%;
margin: 0;
}
body {
font-size: 1em;
font-family: 'Helvetica Neue', Helvetica, sans-serif;
}
.dragging-area {
width: 100%;
height: 100%;
}
.box {
-webkit-transition: box-shadow 100ms ease;
color: white;
background: #28f;
text-align: center;
padding: 1em;
box-shadow: 1px 1px 5px #444;
}
.draggable {
transform: translate3d(0,0,0);
cursor: move;
width: 150px;
height: 150px;
position: absolute;
}
.dragging {
box-shadow: 10px 10px 40px #444;
}
.draggable .drag {
font-style: italic;
font-weight: bold;
display: none;
}
.dragging .drag {
display: inline;
}
.dragging .rest {
display: none;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment