Comparing version 0.2.4 to 0.2.5
{ | ||
"name": "baconjs", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"main": "./dist/Bacon.js" | ||
} |
@@ -1005,3 +1005,3 @@ (function() { | ||
this.subscribe(function(event) { | ||
return console.log.apply(console, __slice.call(args).concat([event.describe()])); | ||
return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log.apply(console, __slice.call(args).concat([event.describe()])) : void 0 : void 0; | ||
}); | ||
@@ -1008,0 +1008,0 @@ return this; |
@@ -1,1 +0,1 @@ | ||
(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I=[].slice,q={}.hasOwnProperty,R=function(e,t){function r(){this.constructor=e}for(var n in t)q.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},U=function(e,t){return function(){return e.apply(t,arguments)}};typeof module!="undefined"&&module!==null?(module.exports=e={},e.Bacon=e):this.Bacon=e={},e.fromBinder=function(t,n){return n==null&&(n=j.id),new o(function(r){var i,o;return i=function(){return typeof o!="undefined"&&o!==null?o():setTimeout(function(){return o()},0)},o=t(function(){var t,o,u,a,f,l,c;t=1<=arguments.length?I.call(arguments,0):[],a=n.apply(null,t),a instanceof Array&&j.last(a)instanceof s||(a=[a]);try{c=[];for(f=0,l=a.length;f<l;f++)o=a[f],u=r(o=_(o)),u===e.noMore||o.isEnd()?c.push(i()):c.push(void 0);return c}catch(h){throw j.last(a).isEnd()&&i(),h}})})},e.$={asEventStream:function(t,n,r){var i,s=this;return E(n)&&(i=[n,null],r=i[0],n=i[1]),e.fromBinder(function(e){return s.on(t,n,e),function(){return s.off(t,n,e)}},r)}},(F=typeof jQuery!=="undefined"&&jQuery!==null?jQuery:typeof Zepto!=="undefined"&&Zepto!==null?Zepto:null)!=null&&(F.fn.asEventStream=e.$.asEventStream),e.fromEventTarget=function(t,n,r){var i,s,o,u,a,f;return i=(o=t.addEventListener)!=null?o:(u=t.addListener)!=null?u:t.bind,s=(a=t.removeEventListener)!=null?a:(f=t.removeListener)!=null?f:t.unbind,e.fromBinder(function(e){return i.call(t,n,e),function(){return s.call(t,n,e)}},r)},e.fromPromise=function(t){return e.fromBinder(function(e){return t.then(e,function(t){return e(new i(t))}),function(){return typeof t.abort=="function"?t.abort():void 0}},function(e){return[e,m()]})},e.noMore=["<no-more>"],e.more=["<more>"],e.later=function(t,n){return e.sequentially(t,[n])},e.sequentially=function(t,n){var r;return r=0,e.fromPoll(t,function(){var e;return e=n[r++],r<n.length?e:[e,m()]})},e.repeatedly=function(t,n){var r;return r=0,e.fromPoll(t,function(){return n[r++%n.length]})},e.fromCallback=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],e.fromBinder(function(e){return x(n,t)(e),k},function(e){return[e,m()]})},e.fromNodeCallback=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],e.fromBinder(function(e){return x(n,t)(e),k},function(e,t){return e?[new i(e),m()]:[t,m()]})},e.fromPoll=function(t,n){return e.fromBinder(function(e){var n;return n=setInterval(e,t),function(){return clearInterval(n)}},n)},e.interval=function(t,n){return n==null&&(n={}),e.fromPoll(t,function(){return C(n)})},e.constant=function(e){return new c(O([e],b))},e.never=function(){return e.fromArray([])},e.once=function(t){return e.fromArray([t])},e.fromArray=function(e){return new o(O(e,C))},O=function(e,t){return function(n){var r,i,s;for(i=0,s=e.length;i<s;i++)r=e[i],n(t(r));return n(m()),k}},e.combineAll=function(e,t){var n,r,i,s,o;r=j.head(e),o=j.tail(e);for(i=0,s=o.length;i<s;i++)n=o[i],r=t(r,n);return r},e.mergeAll=function(t){return e.combineAll(t,function(e,t){return e.merge(t)})},e.combineAsArray=function(){var t,n,r,i,s=this;return r=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],r instanceof Array||(r=[r].concat(t)),r.length?(i=function(){var e,t,i;i=[];for(e=0,t=r.length;e<t;e++)n=r[e],i.push(f);return i}(),new c(function(t){var s,o,u,a,f,l,c,h,d,v,g,y;v=!1,d=function(){var e,t,i;i=[];for(e=0,t=r.length;e<t;e++)n=r[e],i.push(k);return i}(),h=function(){var e,t,n;for(t=0,n=d.length;t<n;t++)e=d[t],e();return v=!0},u=function(){var e,t,i;i=[];for(e=0,t=r.length;e<t;e++)n=r[e],i.push(!1);return i}(),s=function(){var n;if(j.all(u))return n=t(m()),n===e.noMore&&h(),n},f=!1,o=function(n,r){return function(o){var u,a;return o.isEnd()?(n(),s(),e.noMore):o.isError()?(u=t(o),u===e.noMore&&h(),u):(r(o.value),j.all(j.map(function(e){return e.isDefined},i))?f&&o.isInitial()?e.more:(f=!0,a=function(){var e,t,n,r;r=[];for(t=0,n=i.length;t<n;t++)e=i[t],r.push(e.get()());return r},u=t(o.apply(a)),u===e.noMore&&h(),u):e.more)}},l=function(e){return o(function(){return u[e]=!0},function(t){return i[e]=new p(t)})};for(a=g=0,y=r.length;g<y;a=++g)c=r[a],v||(d[a]=c.subscribe(l(a)));return h})):e.constant([])},e.combineWith=function(t,n){return e.combineAll(t,function(e,t){return e.toProperty().combine(t,n)})},e.combineTemplate=function(t){var n,r,i,s,o,u,a,f,c,h;return a=[],h=[],u=function(e){return e[e.length-1]},c=function(e,t,n){return u(e)[t]=n},n=function(e,t){return function(n,r){return c(n,e,r[t])}},o=function(e,t){return function(n,r){return c(n,e,t)}},f=function(e){return e instanceof Array?[]:{}},i=function(e,t){var r,i;return t instanceof l?(h.push(t),a.push(n(e,h.length-1))):typeof t=="object"?(i=function(e){return function(n,r){var i;return i=f(t),c(n,e,i),n.push(i)}},r=function(e,t){return e.pop()},a.push(i(e)),s(t),a.push(r)):a.push(o(e,t))},s=function(e){return j.each(e,i)},s(t),r=function(e){var n,r,i,s,o;i=f(t),n=[i];for(s=0,o=a.length;s<o;s++)r=a[s],r(n,e);return i},e.combineAsArray(h).map(r)},s=function(){function e(){}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(e){return!0},e.prototype.onDone=function(e){return e()},e}(),a=function(e){function t(e,t){var n=this;E(e)?this.value=function(){var t;return t=e(),n.value=j.always(t),t}:this.value=j.always(e)}return R(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t=this;return this.apply(function(){return e(t.value())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.describe=function(){return this.value()},t}(s),u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return R(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new a(this.value)},t}(a),r=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return R(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.describe=function(){return"<end>"},t}(s),i=function(e){function t(e){this.error=e}return R(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.describe=function(){return"<error> "+this.error},t}(s),l=function(){function t(){this.flatMapLatest=U(this.flatMapLatest,this),this.scan=U(this.scan,this),this.takeUntil=U(this.takeUntil,this),this.assign=this.onValue}return t.prototype.onValue=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.subscribe(function(e){if(e.hasValue())return t(e.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.subscribe(function(e){if(e.isError())return t(e.error)})},t.prototype.onEnd=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.subscribe(function(e){if(e.isEnd())return t()})},t.prototype.errors=function(){return this.filter(function(){return!1})},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],n instanceof c?n.sampledBy(this,function(e,t){return[e,t]}).filter(function(e){var t,n;return t=e[0],n=e[1],t}).map(function(e){var t,n;return t=e[0],n=e[1],n}):(n=x(n,t),this.withHandler(function(t){return t.filter(n)?this.push(t):e.more}))},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],n=x(n,t),this.withHandler(function(t){return t.filter(n)?this.push(t):(this.push(m()),e.noMore)})},t.prototype.endOnError=function(){return this.withHandler(function(e){return e.isError()?(this.push(e),this.push(m())):this.push(e)})},t.prototype.take=function(t){return this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(this.push(n),this.push(m()),e.noMore)):this.push(n)})},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.withHandler(function(e){return this.push(e.fmap(t))})},t.prototype.mapError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.withHandler(function(e){return e.isError()?this.push(C(t(e.error))):this.push(e)})},t.prototype.mapEnd=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],n=x(n,t),this.withHandler(function(t){return t.isEnd()?(this.push(C(n(t))),this.push(m()),e.noMore):this.push(t)})},t.prototype.doAction=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.withHandler(function(e){return e.hasValue()&&t(e.value()),this.push(e)})},t.prototype.takeUntil=function(t){var n;return n=this,this.withSubscribe(function(r){var i,s,o,u,a,f;return f=!1,u=k,a=k,o=function(){return u(),a(),f=!0},i=function(t){return t.isEnd()?(a(),r(t),e.noMore):(t.onDone(function(){var n;if(!f){n=r(t);if(n===e.noMore)return o()}}),e.more)},s=function(t){return t.isError()?e.more:t.isEnd()?e.noMore:(u(),r(m()),e.noMore)},u=n.subscribe(i),f||(a=t.subscribe(s)),o})},t.prototype.skip=function(t){return this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)})},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),this.withStateMachine(f,function(t,n){return n.hasValue()?t===f||!e(t.get(),n.value())?[new p(n.value()),[n]]:[t,[]]:[t,[n]]})},t.prototype.withStateMachine=function(t,n){var r;return r=t,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f<l;f++){o=u[f],a=this.push(o);if(a===e.noMore)return a}return a})},t.prototype.scan=function(t,n){var r,i,s=this;return n=M(n),r=H(t),i=function(t){var i,o;return i=!1,o=s.subscribe(function(s){return s.hasValue()?i&&s.isInitial()?e.more:(i=!0,r=new p(n(r.getOrElse(void 0),s.value())),t(s.apply(j.always(r.get())))):(s.isEnd()&&(i=!0),t(s))}),i||r.forEach(function(n){var r;r=t(b(n));if(r===e.noMore)return o(),o=k}),o},new c((new h(i)).subscribe)},t.prototype.diff=function(e,t){return t=M(t),this.scan([e],function(e,n){return[n,t(e[0],n)]}).filter(function(e){return e.length===2}).map(function(e){return e[1]})},t.prototype.flatMap=function(t){var n;return t=T(t),n=this,new o(function(r){var i,s,o,a,f,l;return s=[],o=!1,l=function(){},f=function(){var e,t,n;l();for(t=0,n=s.length;t<n;t++)e=s[t],e();return s=[]},i=function(){if(o&&s.length===0)return r(m())},a=function(n){var a,l,c,h,p;if(n.isEnd())return o=!0,i();if(n.isError())return r(n);a=t(n.value()),p=void 0,l=!1,h=function(){return p!=null&&A(p,s),i()},c=function(t){var n;return t.isEnd()?(h(),l=!0,e.noMore):(t instanceof u&&(t=t.toNext()),n=r(t),n===e.noMore&&f(),n)},p=a.subscribe(c);if(!l)return s.push(p)},l=n.subscribe(a),f})},t.prototype.flatMapLatest=function(e){var t,n=this;return e=T(e),t=this.toEventStream(),t.flatMap(function(n){return e(n).takeUntil(t)})},t.prototype.not=function(){return this.map(function(e){return!e})},t.prototype.log=function(){var e;return e=1<=arguments.length?I.call(arguments,0):[],this.subscribe(function(t){return console.log.apply(console,I.call(e).concat([t.describe()]))}),this},t.prototype.slidingWindow=function(e){return this.scan([],function(t,n){return t.concat([n]).slice(-e)})},t}(),o=function(t){function r(e){var t;r.__super__.constructor.call(this),t=new n(e),this.subscribe=t.subscribe,this.hasSubscribers=t.hasSubscribers}return R(r,t),r.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t instanceof c?t.sampledBy(this,g):r.__super__.map.apply(this,[t].concat(I.call(e)))},r.prototype.delay=function(t){return this.flatMap(function(n){return e.later(t,n)})},r.prototype.debounce=function(t){return this.flatMapLatest(function(n){return e.later(t,n)})},r.prototype.throttle=function(e){return this.bufferWithTime(e).map(function(e){return e[e.length-1]})},r.prototype.bufferWithTime=function(e){var t,n=this;return t=function(e){return e.schedule()},this.buffer(e,t,t)},r.prototype.bufferWithCount=function(e){var t;return t=function(t){if(t.values.length===e)return t.flush()},this.buffer(0,t)},r.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(C(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){var e=this;if(!this.scheduled)return this.scheduled=!0,t(function(){return e.flush()})}},o=e.more,E(t)||(s=t,t=function(e){return setTimeout(e,s)}),this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o})},r.prototype.merge=function(t){var n;return n=this,new r(function(r){var i,s,o,u,a,f;return u=k,a=k,f=!1,o=function(){return u(),a(),f=!0},i=0,s=function(t){var n;return t.isEnd()?(i++,i===2?r(m()):e.more):(n=r(t),n===e.noMore&&o(),n)},u=n.subscribe(s),f||(a=t.subscribe(s)),o})},r.prototype.toProperty=function(e){return arguments.length===0&&(e=f),this.scan(e,S)},r.prototype.toEventStream=function(){return this},r.prototype.concat=function(e){var t;return t=this,new r(function(n){var r;return r=t.subscribe(function(t){return t.isEnd()?r=e.subscribe(n):n(t)}),function(){return r()}})},r.prototype.awaiting=function(e){return this.map(!0).merge(e.map(!1)).toProperty(!1)},r.prototype.startWith=function(t){return e.once(t).concat(this)},r.prototype.withHandler=function(e){var t;return t=new n(this.subscribe,e),new r(t.subscribe)},r.prototype.withSubscribe=function(e){return new r(e)},r}(l),c=function(t){function n(t){var r,i=this;this.subscribe=t,this.toEventStream=U(this.toEventStream,this),this.toProperty=U(this.toProperty,this),this.changes=U(this.changes,this),this.sample=U(this.sample,this),n.__super__.constructor.call(this),r=function(t,r,s){var o,u;return o=f,u=f,new n(function(n){var a,f,l,c,h,d,v,g,y,b,w;return w=!1,y=k,b=k,g=function(){return y(),b(),w=!0},c=!1,d=!1,a=function(){var t;if(c&&d)return t=n(m()),t===e.noMore&&g(),t},l=!1,f=function(t,r,i){return function(s){var f;return s.isEnd()?(t(),a(),e.noMore):s.isError()?(f=n(s),f===e.noMore&&g(),f):(r(new p(s.value)),o.isDefined&&u.isDefined?l&&s.isInitial()?e.more:(l=!0,f=i(n,s,o.value,u.value),f===e.noMore&&g(),f):e.more)}},h=f(function(){return c=!0},function(e){return o=e},r),v=f(function(){return d=!0},function(e){return u=e},s),y=i.subscribe(h),w||(b=t.subscribe(v)),g})},this.combine=function(t,n){var r;return r=M(n),e.combineAsArray(i,t).map(function(e){return r(e[0],e[1])})},this.sampledBy=function(e,t){var n,i;return t==null&&(t=g),t=M(t),n=function(e,n,r,i){return e(n.apply(function(){return t(r(),i())}))},i=r(e,k,n),e instanceof o&&(i=i.changes()),i.takeUntil(e.filter(!1).mapEnd())}}return R(n,t),n.prototype.sample=function(t){return this.sampledBy(e.interval(t,{}))},n.prototype.changes=function(){var e=this;return new o(function(t){return e.subscribe(function(e){if(!e.isInitial())return t(e)})})},n.prototype.withHandler=function(e){return new n((new h(this.subscribe,e)).subscribe)},n.prototype.withSubscribe=function(e){return new n((new h(e)).subscribe)},n.prototype.toProperty=function(){return this},n.prototype.toEventStream=function(){var e=this;return new o(function(t){return e.subscribe(function(e){return e.isInitial()&&(e=e.toNext()),t(e)})})},n.prototype.and=function(e){return this.combine(e,function(e,t){return e&&t})},n.prototype.or=function(e){return this.combine(e,function(e,t){return e||t})},n.prototype.decode=function(t){return this.combine(e.combineTemplate(t),function(e,t){return t[e]})},n.prototype.delay=function(e){return this.delayChanges(function(t){return t.delay(e)})},n.prototype.debounce=function(e){return this.delayChanges(function(t){return t.debounce(e)})},n.prototype.throttle=function(e){return this.delayChanges(function(t){return t.throttle(e)})},n.prototype.delayChanges=function(e){return d(this,e(this.changes()))},n}(l),d=function(t,n){var r;return r=function(t){var n;return n=f,t.subscribe(function(t){return t.isInitial()&&(n=new p(t.value())),e.noMore}),n},n.toProperty(r(t))},n=function(){function t(t,n){var r,i,o,u,a,f,l,c,h,p=this;t==null&&(t=function(){return k}),l=[],a=null,u=!1,o=!1,this.hasSubscribers=function(){return l.length>0},c=k,f=function(e){return l=j.without(e,l)},h=null,i=function(e){var t,n,r,i;if(h!=null){n=h,h=null;for(r=0,i=n.length;r<i;r++)t=n[r],t()}return e.onDone=s.prototype.onDone},r=function(e){return h=(h||[]).concat([e])},this.push=function(t){var n,s,o,c,h;if(!u){try{u=!0,t.onDone=r,o=l;for(c=0,h=o.length;c<h;c++)s=o[c],n=s(t),(n===e.noMore||t.isEnd())&&f(s)}catch(d){throw a=null,d}finally{u=!1}while(a!=null?a.length:void 0)t=j.head(a),a=j.tail(a),p.push(t);return i(t),p.hasSubscribers()?e.more:e.noMore}return a=(a||[]).concat([t]),e.more},n==null&&(n=function(e){return this.push(e)}),this.handleEvent=function(e){return e.isEnd()&&(o=!0),n.apply(p,[e])},this.subscribe=function(e){return o?(e(m()),k):(l=l.concat(e),l.length===1&&(c=t(p.handleEvent)),function(){f(e);if(!p.hasSubscribers())return c()})}}return t}(),h=function(t){function n(t,r){var i,s,o,u=this;n.__super__.constructor.call(this,t,r),i=f,o=this.push,t=this.subscribe,s=!1,this.push=function(e){return e.isEnd()&&(s=!0),e.hasValue()&&(i=new p(e.value())),o.apply(u,[e])},this.subscribe=function(n){var r,o,a;return r=!1,a=function(){return u.hasSubscribers()||s},o=i.filter(a).map(function(e){return n(b(e))}),o.getOrElse(e.more)===e.noMore?k:s?(n(m()),k):t.apply(u,[n])}}return R(n,t),n}(n),t=function(t){function n(){var t,r,s,o,u,a,f,l,c=this;s=void 0,a=[],t=!1,r=function(t){return function(n){return n.isEnd()?(l(t),e.noMore):s(n)}},f=function(){var e,t,n,r;r=[];for(t=0,n=a.length;t<n;t++)e=a[t],r.push(typeof e.unsub=="function"?e.unsub():void 0);return r},u=function(e){return e.unsub=e.input.subscribe(r(e.input))},l=function(e){var t,n,r,i;for(t=r=0,i=a.length;r<i;t=++r){n=a[t];if(n.input===e){typeof n.unsub=="function"&&n.unsub(),a.splice(t,1);return}}},o=function(e){var t,n,r,i,o;s=e,n=[],o=v(a);for(r=0,i=o.length;r<i;r++)t=o[r],u(t);return f},n.__super__.constructor.call(this,o),this.plug=function(e){var n;if(t)return;return n={input:e},a.push(n),s!=null&&u(n),function(){return l(e)}},this.push=function(e){return typeof s=="function"?s(C(e)):void 0},this.error=function(e){return typeof s=="function"?s(new i(e)):void 0},this.end=function(){return t=!0,f(),typeof s=="function"?s(m()):void 0}}return R(n,t),n}(o),p=function(){function e(e){this.value=e}return e.prototype.getOrElse=function(){return this.value},e.prototype.get=function(){return this.value},e.prototype.filter=function(t){return t(this.value)?new e(this.value):f},e.prototype.map=function(t){return new e(t(this.value))},e.prototype.forEach=function(e){return e(this.value)},e.prototype.isDefined=!0,e.prototype.toArray=function(){return[this.value]},e}(),f={getOrElse:function(e){return e},filter:function(){return f},map:function(){return f},forEach:function(){},isDefined:!1,toArray:function(){return[]}},e.EventStream=o,e.Property=c,e.Observable=l,e.Bus=t,e.Initial=u,e.Next=a,e.End=r,e.Error=i,k=function(){},S=function(e,t){return t},g=function(e,t){return e},b=function(e){return new u(j.always(e))},C=function(e){return new a(j.always(e))},m=function(){return new r},_=function(e){return e instanceof s?e:C(e)},v=function(e){return e.slice(0)},y=Array.prototype.indexOf?function(e,t){return e.indexOf(t)}:function(e,t){var n,r,i,s;for(n=i=0,s=e.length;i<s;n=++i){r=e[n];if(t===r)return n}return-1},A=function(e,t){var n;n=y(t,e);if(n>=0)return t.splice(n,1)},E=function(e){return typeof e=="function"},N=function(e,t,n){return n===void 0&&(n=[]),function(r){return e[t].apply(e,n.concat([r]))}},L=function(e,t){return function(){var n;return n=1<=arguments.length?I.call(arguments,0):[],e.apply(null,t.concat(n))}},T=function(e){return e instanceof l&&(e=j.always(e)),e},x=function(e,t){return E(e)?t.length?L(e,t):e:w(e)?D(e,t):typeof e=="object"&&t.length?N(e,j.head(t),j.tail(t)):j.always(e)},w=function(e){return typeof e=="string"&&e.length>1&&e.charAt(0)==="."},e.isFieldKey=w,D=function(e,t){var n,r;return r=e.slice(1).split("."),n=j.map(B(t),r),function(t){var r,i;for(r=0,i=n.length;r<i;r++)e=n[r],t=e(t);return t}},B=function(e){return function(t){return function(n){var r;return r=n[t],E(r)?r.apply(n,e):r}}},P=function(e){return e.slice(1)},M=function(e){var t;if(E(e))return e;if(w(e))return t=P(e),function(e,n){return e[t](n)}},H=function(e){return e instanceof p||e===f?e:new p(e)},typeof define!="undefined"&&define!==null&&define.amd!=null&&typeof define=="function"&&define(function(){return e}),j={head:function(e){return e[0]},always:function(e){return function(){return e}},empty:function(e){return e.length===0},tail:function(e){return e.slice(1,e.length)},filter:function(e,t){var n,r,i,s;n=[];for(i=0,s=t.length;i<s;i++)r=t[i],e(r)&&n.push(r);return n},map:function(e,t){var n,r,i,s;s=[];for(r=0,i=t.length;r<i;r++)n=t[r],s.push(e(n));return s},each:function(e,t){var n,r,i;i=[];for(n in e)r=e[n],i.push(t(n,r));return i},toArray:function(e){return e instanceof Array?e:[e]},contains:function(e,t){return y(e,t)!==-1},id:function(e){return e},last:function(e){return e[e.length-1]},all:function(e){var t,n,r;for(n=0,r=e.length;n<r;n++){t=e[n];if(!t)return!1}return!0},without:function(e,t){return j.filter(function(t){return t!==e},t)}},e._=j}).call(this); | ||
(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I=[].slice,q={}.hasOwnProperty,R=function(e,t){function r(){this.constructor=e}for(var n in t)q.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},U=function(e,t){return function(){return e.apply(t,arguments)}};typeof module!="undefined"&&module!==null?(module.exports=e={},e.Bacon=e):this.Bacon=e={},e.fromBinder=function(t,n){return n==null&&(n=j.id),new o(function(r){var i,o;return i=function(){return typeof o!="undefined"&&o!==null?o():setTimeout(function(){return o()},0)},o=t(function(){var t,o,u,a,f,l,c;t=1<=arguments.length?I.call(arguments,0):[],a=n.apply(null,t),a instanceof Array&&j.last(a)instanceof s||(a=[a]);try{c=[];for(f=0,l=a.length;f<l;f++)o=a[f],u=r(o=_(o)),u===e.noMore||o.isEnd()?c.push(i()):c.push(void 0);return c}catch(h){throw j.last(a).isEnd()&&i(),h}})})},e.$={asEventStream:function(t,n,r){var i,s=this;return E(n)&&(i=[n,null],r=i[0],n=i[1]),e.fromBinder(function(e){return s.on(t,n,e),function(){return s.off(t,n,e)}},r)}},(F=typeof jQuery!=="undefined"&&jQuery!==null?jQuery:typeof Zepto!=="undefined"&&Zepto!==null?Zepto:null)!=null&&(F.fn.asEventStream=e.$.asEventStream),e.fromEventTarget=function(t,n,r){var i,s,o,u,a,f;return i=(o=t.addEventListener)!=null?o:(u=t.addListener)!=null?u:t.bind,s=(a=t.removeEventListener)!=null?a:(f=t.removeListener)!=null?f:t.unbind,e.fromBinder(function(e){return i.call(t,n,e),function(){return s.call(t,n,e)}},r)},e.fromPromise=function(t){return e.fromBinder(function(e){return t.then(e,function(t){return e(new i(t))}),function(){return typeof t.abort=="function"?t.abort():void 0}},function(e){return[e,m()]})},e.noMore=["<no-more>"],e.more=["<more>"],e.later=function(t,n){return e.sequentially(t,[n])},e.sequentially=function(t,n){var r;return r=0,e.fromPoll(t,function(){var e;return e=n[r++],r<n.length?e:[e,m()]})},e.repeatedly=function(t,n){var r;return r=0,e.fromPoll(t,function(){return n[r++%n.length]})},e.fromCallback=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],e.fromBinder(function(e){return x(n,t)(e),k},function(e){return[e,m()]})},e.fromNodeCallback=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],e.fromBinder(function(e){return x(n,t)(e),k},function(e,t){return e?[new i(e),m()]:[t,m()]})},e.fromPoll=function(t,n){return e.fromBinder(function(e){var n;return n=setInterval(e,t),function(){return clearInterval(n)}},n)},e.interval=function(t,n){return n==null&&(n={}),e.fromPoll(t,function(){return C(n)})},e.constant=function(e){return new c(O([e],b))},e.never=function(){return e.fromArray([])},e.once=function(t){return e.fromArray([t])},e.fromArray=function(e){return new o(O(e,C))},O=function(e,t){return function(n){var r,i,s;for(i=0,s=e.length;i<s;i++)r=e[i],n(t(r));return n(m()),k}},e.combineAll=function(e,t){var n,r,i,s,o;r=j.head(e),o=j.tail(e);for(i=0,s=o.length;i<s;i++)n=o[i],r=t(r,n);return r},e.mergeAll=function(t){return e.combineAll(t,function(e,t){return e.merge(t)})},e.combineAsArray=function(){var t,n,r,i,s=this;return r=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],r instanceof Array||(r=[r].concat(t)),r.length?(i=function(){var e,t,i;i=[];for(e=0,t=r.length;e<t;e++)n=r[e],i.push(f);return i}(),new c(function(t){var s,o,u,a,f,l,c,h,d,v,g,y;v=!1,d=function(){var e,t,i;i=[];for(e=0,t=r.length;e<t;e++)n=r[e],i.push(k);return i}(),h=function(){var e,t,n;for(t=0,n=d.length;t<n;t++)e=d[t],e();return v=!0},u=function(){var e,t,i;i=[];for(e=0,t=r.length;e<t;e++)n=r[e],i.push(!1);return i}(),s=function(){var n;if(j.all(u))return n=t(m()),n===e.noMore&&h(),n},f=!1,o=function(n,r){return function(o){var u,a;return o.isEnd()?(n(),s(),e.noMore):o.isError()?(u=t(o),u===e.noMore&&h(),u):(r(o.value),j.all(j.map(function(e){return e.isDefined},i))?f&&o.isInitial()?e.more:(f=!0,a=function(){var e,t,n,r;r=[];for(t=0,n=i.length;t<n;t++)e=i[t],r.push(e.get()());return r},u=t(o.apply(a)),u===e.noMore&&h(),u):e.more)}},l=function(e){return o(function(){return u[e]=!0},function(t){return i[e]=new p(t)})};for(a=g=0,y=r.length;g<y;a=++g)c=r[a],v||(d[a]=c.subscribe(l(a)));return h})):e.constant([])},e.combineWith=function(t,n){return e.combineAll(t,function(e,t){return e.toProperty().combine(t,n)})},e.combineTemplate=function(t){var n,r,i,s,o,u,a,f,c,h;return a=[],h=[],u=function(e){return e[e.length-1]},c=function(e,t,n){return u(e)[t]=n},n=function(e,t){return function(n,r){return c(n,e,r[t])}},o=function(e,t){return function(n,r){return c(n,e,t)}},f=function(e){return e instanceof Array?[]:{}},i=function(e,t){var r,i;return t instanceof l?(h.push(t),a.push(n(e,h.length-1))):typeof t=="object"?(i=function(e){return function(n,r){var i;return i=f(t),c(n,e,i),n.push(i)}},r=function(e,t){return e.pop()},a.push(i(e)),s(t),a.push(r)):a.push(o(e,t))},s=function(e){return j.each(e,i)},s(t),r=function(e){var n,r,i,s,o;i=f(t),n=[i];for(s=0,o=a.length;s<o;s++)r=a[s],r(n,e);return i},e.combineAsArray(h).map(r)},s=function(){function e(){}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(e){return!0},e.prototype.onDone=function(e){return e()},e}(),a=function(e){function t(e,t){var n=this;E(e)?this.value=function(){var t;return t=e(),n.value=j.always(t),t}:this.value=j.always(e)}return R(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t=this;return this.apply(function(){return e(t.value())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.describe=function(){return this.value()},t}(s),u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return R(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new a(this.value)},t}(a),r=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return R(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.describe=function(){return"<end>"},t}(s),i=function(e){function t(e){this.error=e}return R(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.describe=function(){return"<error> "+this.error},t}(s),l=function(){function t(){this.flatMapLatest=U(this.flatMapLatest,this),this.scan=U(this.scan,this),this.takeUntil=U(this.takeUntil,this),this.assign=this.onValue}return t.prototype.onValue=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.subscribe(function(e){if(e.hasValue())return t(e.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.subscribe(function(e){if(e.isError())return t(e.error)})},t.prototype.onEnd=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.subscribe(function(e){if(e.isEnd())return t()})},t.prototype.errors=function(){return this.filter(function(){return!1})},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],n instanceof c?n.sampledBy(this,function(e,t){return[e,t]}).filter(function(e){var t,n;return t=e[0],n=e[1],t}).map(function(e){var t,n;return t=e[0],n=e[1],n}):(n=x(n,t),this.withHandler(function(t){return t.filter(n)?this.push(t):e.more}))},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],n=x(n,t),this.withHandler(function(t){return t.filter(n)?this.push(t):(this.push(m()),e.noMore)})},t.prototype.endOnError=function(){return this.withHandler(function(e){return e.isError()?(this.push(e),this.push(m())):this.push(e)})},t.prototype.take=function(t){return this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(this.push(n),this.push(m()),e.noMore)):this.push(n)})},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.withHandler(function(e){return this.push(e.fmap(t))})},t.prototype.mapError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.withHandler(function(e){return e.isError()?this.push(C(t(e.error))):this.push(e)})},t.prototype.mapEnd=function(){var t,n;return n=arguments[0],t=2<=arguments.length?I.call(arguments,1):[],n=x(n,t),this.withHandler(function(t){return t.isEnd()?(this.push(C(n(t))),this.push(m()),e.noMore):this.push(t)})},t.prototype.doAction=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t=x(t,e),this.withHandler(function(e){return e.hasValue()&&t(e.value()),this.push(e)})},t.prototype.takeUntil=function(t){var n;return n=this,this.withSubscribe(function(r){var i,s,o,u,a,f;return f=!1,u=k,a=k,o=function(){return u(),a(),f=!0},i=function(t){return t.isEnd()?(a(),r(t),e.noMore):(t.onDone(function(){var n;if(!f){n=r(t);if(n===e.noMore)return o()}}),e.more)},s=function(t){return t.isError()?e.more:t.isEnd()?e.noMore:(u(),r(m()),e.noMore)},u=n.subscribe(i),f||(a=t.subscribe(s)),o})},t.prototype.skip=function(t){return this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)})},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),this.withStateMachine(f,function(t,n){return n.hasValue()?t===f||!e(t.get(),n.value())?[new p(n.value()),[n]]:[t,[]]:[t,[n]]})},t.prototype.withStateMachine=function(t,n){var r;return r=t,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f<l;f++){o=u[f],a=this.push(o);if(a===e.noMore)return a}return a})},t.prototype.scan=function(t,n){var r,i,s=this;return n=M(n),r=H(t),i=function(t){var i,o;return i=!1,o=s.subscribe(function(s){return s.hasValue()?i&&s.isInitial()?e.more:(i=!0,r=new p(n(r.getOrElse(void 0),s.value())),t(s.apply(j.always(r.get())))):(s.isEnd()&&(i=!0),t(s))}),i||r.forEach(function(n){var r;r=t(b(n));if(r===e.noMore)return o(),o=k}),o},new c((new h(i)).subscribe)},t.prototype.diff=function(e,t){return t=M(t),this.scan([e],function(e,n){return[n,t(e[0],n)]}).filter(function(e){return e.length===2}).map(function(e){return e[1]})},t.prototype.flatMap=function(t){var n;return t=T(t),n=this,new o(function(r){var i,s,o,a,f,l;return s=[],o=!1,l=function(){},f=function(){var e,t,n;l();for(t=0,n=s.length;t<n;t++)e=s[t],e();return s=[]},i=function(){if(o&&s.length===0)return r(m())},a=function(n){var a,l,c,h,p;if(n.isEnd())return o=!0,i();if(n.isError())return r(n);a=t(n.value()),p=void 0,l=!1,h=function(){return p!=null&&A(p,s),i()},c=function(t){var n;return t.isEnd()?(h(),l=!0,e.noMore):(t instanceof u&&(t=t.toNext()),n=r(t),n===e.noMore&&f(),n)},p=a.subscribe(c);if(!l)return s.push(p)},l=n.subscribe(a),f})},t.prototype.flatMapLatest=function(e){var t,n=this;return e=T(e),t=this.toEventStream(),t.flatMap(function(n){return e(n).takeUntil(t)})},t.prototype.not=function(){return this.map(function(e){return!e})},t.prototype.log=function(){var e;return e=1<=arguments.length?I.call(arguments,0):[],this.subscribe(function(t){return typeof console!="undefined"&&console!==null?typeof console.log=="function"?console.log.apply(console,I.call(e).concat([t.describe()])):void 0:void 0}),this},t.prototype.slidingWindow=function(e){return this.scan([],function(t,n){return t.concat([n]).slice(-e)})},t}(),o=function(t){function r(e){var t;r.__super__.constructor.call(this),t=new n(e),this.subscribe=t.subscribe,this.hasSubscribers=t.hasSubscribers}return R(r,t),r.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?I.call(arguments,1):[],t instanceof c?t.sampledBy(this,g):r.__super__.map.apply(this,[t].concat(I.call(e)))},r.prototype.delay=function(t){return this.flatMap(function(n){return e.later(t,n)})},r.prototype.debounce=function(t){return this.flatMapLatest(function(n){return e.later(t,n)})},r.prototype.throttle=function(e){return this.bufferWithTime(e).map(function(e){return e[e.length-1]})},r.prototype.bufferWithTime=function(e){var t,n=this;return t=function(e){return e.schedule()},this.buffer(e,t,t)},r.prototype.bufferWithCount=function(e){var t;return t=function(t){if(t.values.length===e)return t.flush()},this.buffer(0,t)},r.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(C(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){var e=this;if(!this.scheduled)return this.scheduled=!0,t(function(){return e.flush()})}},o=e.more,E(t)||(s=t,t=function(e){return setTimeout(e,s)}),this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o})},r.prototype.merge=function(t){var n;return n=this,new r(function(r){var i,s,o,u,a,f;return u=k,a=k,f=!1,o=function(){return u(),a(),f=!0},i=0,s=function(t){var n;return t.isEnd()?(i++,i===2?r(m()):e.more):(n=r(t),n===e.noMore&&o(),n)},u=n.subscribe(s),f||(a=t.subscribe(s)),o})},r.prototype.toProperty=function(e){return arguments.length===0&&(e=f),this.scan(e,S)},r.prototype.toEventStream=function(){return this},r.prototype.concat=function(e){var t;return t=this,new r(function(n){var r;return r=t.subscribe(function(t){return t.isEnd()?r=e.subscribe(n):n(t)}),function(){return r()}})},r.prototype.awaiting=function(e){return this.map(!0).merge(e.map(!1)).toProperty(!1)},r.prototype.startWith=function(t){return e.once(t).concat(this)},r.prototype.withHandler=function(e){var t;return t=new n(this.subscribe,e),new r(t.subscribe)},r.prototype.withSubscribe=function(e){return new r(e)},r}(l),c=function(t){function n(t){var r,i=this;this.subscribe=t,this.toEventStream=U(this.toEventStream,this),this.toProperty=U(this.toProperty,this),this.changes=U(this.changes,this),this.sample=U(this.sample,this),n.__super__.constructor.call(this),r=function(t,r,s){var o,u;return o=f,u=f,new n(function(n){var a,f,l,c,h,d,v,g,y,b,w;return w=!1,y=k,b=k,g=function(){return y(),b(),w=!0},c=!1,d=!1,a=function(){var t;if(c&&d)return t=n(m()),t===e.noMore&&g(),t},l=!1,f=function(t,r,i){return function(s){var f;return s.isEnd()?(t(),a(),e.noMore):s.isError()?(f=n(s),f===e.noMore&&g(),f):(r(new p(s.value)),o.isDefined&&u.isDefined?l&&s.isInitial()?e.more:(l=!0,f=i(n,s,o.value,u.value),f===e.noMore&&g(),f):e.more)}},h=f(function(){return c=!0},function(e){return o=e},r),v=f(function(){return d=!0},function(e){return u=e},s),y=i.subscribe(h),w||(b=t.subscribe(v)),g})},this.combine=function(t,n){var r;return r=M(n),e.combineAsArray(i,t).map(function(e){return r(e[0],e[1])})},this.sampledBy=function(e,t){var n,i;return t==null&&(t=g),t=M(t),n=function(e,n,r,i){return e(n.apply(function(){return t(r(),i())}))},i=r(e,k,n),e instanceof o&&(i=i.changes()),i.takeUntil(e.filter(!1).mapEnd())}}return R(n,t),n.prototype.sample=function(t){return this.sampledBy(e.interval(t,{}))},n.prototype.changes=function(){var e=this;return new o(function(t){return e.subscribe(function(e){if(!e.isInitial())return t(e)})})},n.prototype.withHandler=function(e){return new n((new h(this.subscribe,e)).subscribe)},n.prototype.withSubscribe=function(e){return new n((new h(e)).subscribe)},n.prototype.toProperty=function(){return this},n.prototype.toEventStream=function(){var e=this;return new o(function(t){return e.subscribe(function(e){return e.isInitial()&&(e=e.toNext()),t(e)})})},n.prototype.and=function(e){return this.combine(e,function(e,t){return e&&t})},n.prototype.or=function(e){return this.combine(e,function(e,t){return e||t})},n.prototype.decode=function(t){return this.combine(e.combineTemplate(t),function(e,t){return t[e]})},n.prototype.delay=function(e){return this.delayChanges(function(t){return t.delay(e)})},n.prototype.debounce=function(e){return this.delayChanges(function(t){return t.debounce(e)})},n.prototype.throttle=function(e){return this.delayChanges(function(t){return t.throttle(e)})},n.prototype.delayChanges=function(e){return d(this,e(this.changes()))},n}(l),d=function(t,n){var r;return r=function(t){var n;return n=f,t.subscribe(function(t){return t.isInitial()&&(n=new p(t.value())),e.noMore}),n},n.toProperty(r(t))},n=function(){function t(t,n){var r,i,o,u,a,f,l,c,h,p=this;t==null&&(t=function(){return k}),l=[],a=null,u=!1,o=!1,this.hasSubscribers=function(){return l.length>0},c=k,f=function(e){return l=j.without(e,l)},h=null,i=function(e){var t,n,r,i;if(h!=null){n=h,h=null;for(r=0,i=n.length;r<i;r++)t=n[r],t()}return e.onDone=s.prototype.onDone},r=function(e){return h=(h||[]).concat([e])},this.push=function(t){var n,s,o,c,h;if(!u){try{u=!0,t.onDone=r,o=l;for(c=0,h=o.length;c<h;c++)s=o[c],n=s(t),(n===e.noMore||t.isEnd())&&f(s)}catch(d){throw a=null,d}finally{u=!1}while(a!=null?a.length:void 0)t=j.head(a),a=j.tail(a),p.push(t);return i(t),p.hasSubscribers()?e.more:e.noMore}return a=(a||[]).concat([t]),e.more},n==null&&(n=function(e){return this.push(e)}),this.handleEvent=function(e){return e.isEnd()&&(o=!0),n.apply(p,[e])},this.subscribe=function(e){return o?(e(m()),k):(l=l.concat(e),l.length===1&&(c=t(p.handleEvent)),function(){f(e);if(!p.hasSubscribers())return c()})}}return t}(),h=function(t){function n(t,r){var i,s,o,u=this;n.__super__.constructor.call(this,t,r),i=f,o=this.push,t=this.subscribe,s=!1,this.push=function(e){return e.isEnd()&&(s=!0),e.hasValue()&&(i=new p(e.value())),o.apply(u,[e])},this.subscribe=function(n){var r,o,a;return r=!1,a=function(){return u.hasSubscribers()||s},o=i.filter(a).map(function(e){return n(b(e))}),o.getOrElse(e.more)===e.noMore?k:s?(n(m()),k):t.apply(u,[n])}}return R(n,t),n}(n),t=function(t){function n(){var t,r,s,o,u,a,f,l,c=this;s=void 0,a=[],t=!1,r=function(t){return function(n){return n.isEnd()?(l(t),e.noMore):s(n)}},f=function(){var e,t,n,r;r=[];for(t=0,n=a.length;t<n;t++)e=a[t],r.push(typeof e.unsub=="function"?e.unsub():void 0);return r},u=function(e){return e.unsub=e.input.subscribe(r(e.input))},l=function(e){var t,n,r,i;for(t=r=0,i=a.length;r<i;t=++r){n=a[t];if(n.input===e){typeof n.unsub=="function"&&n.unsub(),a.splice(t,1);return}}},o=function(e){var t,n,r,i,o;s=e,n=[],o=v(a);for(r=0,i=o.length;r<i;r++)t=o[r],u(t);return f},n.__super__.constructor.call(this,o),this.plug=function(e){var n;if(t)return;return n={input:e},a.push(n),s!=null&&u(n),function(){return l(e)}},this.push=function(e){return typeof s=="function"?s(C(e)):void 0},this.error=function(e){return typeof s=="function"?s(new i(e)):void 0},this.end=function(){return t=!0,f(),typeof s=="function"?s(m()):void 0}}return R(n,t),n}(o),p=function(){function e(e){this.value=e}return e.prototype.getOrElse=function(){return this.value},e.prototype.get=function(){return this.value},e.prototype.filter=function(t){return t(this.value)?new e(this.value):f},e.prototype.map=function(t){return new e(t(this.value))},e.prototype.forEach=function(e){return e(this.value)},e.prototype.isDefined=!0,e.prototype.toArray=function(){return[this.value]},e}(),f={getOrElse:function(e){return e},filter:function(){return f},map:function(){return f},forEach:function(){},isDefined:!1,toArray:function(){return[]}},e.EventStream=o,e.Property=c,e.Observable=l,e.Bus=t,e.Initial=u,e.Next=a,e.End=r,e.Error=i,k=function(){},S=function(e,t){return t},g=function(e,t){return e},b=function(e){return new u(j.always(e))},C=function(e){return new a(j.always(e))},m=function(){return new r},_=function(e){return e instanceof s?e:C(e)},v=function(e){return e.slice(0)},y=Array.prototype.indexOf?function(e,t){return e.indexOf(t)}:function(e,t){var n,r,i,s;for(n=i=0,s=e.length;i<s;n=++i){r=e[n];if(t===r)return n}return-1},A=function(e,t){var n;n=y(t,e);if(n>=0)return t.splice(n,1)},E=function(e){return typeof e=="function"},N=function(e,t,n){return n===void 0&&(n=[]),function(r){return e[t].apply(e,n.concat([r]))}},L=function(e,t){return function(){var n;return n=1<=arguments.length?I.call(arguments,0):[],e.apply(null,t.concat(n))}},T=function(e){return e instanceof l&&(e=j.always(e)),e},x=function(e,t){return E(e)?t.length?L(e,t):e:w(e)?D(e,t):typeof e=="object"&&t.length?N(e,j.head(t),j.tail(t)):j.always(e)},w=function(e){return typeof e=="string"&&e.length>1&&e.charAt(0)==="."},e.isFieldKey=w,D=function(e,t){var n,r;return r=e.slice(1).split("."),n=j.map(B(t),r),function(t){var r,i;for(r=0,i=n.length;r<i;r++)e=n[r],t=e(t);return t}},B=function(e){return function(t){return function(n){var r;return r=n[t],E(r)?r.apply(n,e):r}}},P=function(e){return e.slice(1)},M=function(e){var t;if(E(e))return e;if(w(e))return t=P(e),function(e,n){return e[t](n)}},H=function(e){return e instanceof p||e===f?e:new p(e)},typeof define!="undefined"&&define!==null&&define.amd!=null&&typeof define=="function"&&define(function(){return e}),j={head:function(e){return e[0]},always:function(e){return function(){return e}},empty:function(e){return e.length===0},tail:function(e){return e.slice(1,e.length)},filter:function(e,t){var n,r,i,s;n=[];for(i=0,s=t.length;i<s;i++)r=t[i],e(r)&&n.push(r);return n},map:function(e,t){var n,r,i,s;s=[];for(r=0,i=t.length;r<i;r++)n=t[r],s.push(e(n));return s},each:function(e,t){var n,r,i;i=[];for(n in e)r=e[n],i.push(t(n,r));return i},toArray:function(e){return e instanceof Array?e:[e]},contains:function(e,t){return y(e,t)!==-1},id:function(e){return e},last:function(e){return e[e.length-1]},all:function(e){var t,n,r;for(n=0,r=e.length;n<r;n++){t=e[n];if(!t)return!1}return!0},without:function(e,t){return j.filter(function(t){return t!==e},t)}},e._=j}).call(this); |
{ | ||
"name": "baconjs", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"author": "Juha Paananen", | ||
@@ -5,0 +5,0 @@ "licenses": [ |
234
README.md
@@ -39,3 +39,5 @@ Bacon.js | ||
<script src="https://raw.github.com/raimohanska/bacon.js/master/dist/Bacon.js"></script> | ||
```html | ||
<script src="https://raw.github.com/raimohanska/bacon.js/master/dist/Bacon.js"></script> | ||
``` | ||
@@ -61,4 +63,6 @@ If you're targeting to [node.js](http://nodejs.org/), you can | ||
var cliks = $("h1").asEventStream("click") | ||
```js | ||
var cliks = $("h1").asEventStream("click") | ||
``` | ||
Each EventStream represents a stream of events. It is an Observable object, meaning | ||
@@ -68,4 +72,6 @@ that you can listen to events in the stream using, for instance, the `onValue` method | ||
cliks.onValue(function() { alert("you clicked the h1 element") }) | ||
```js | ||
cliks.onValue(function() { alert("you clicked the h1 element") }) | ||
``` | ||
But you can do neater stuff too. The Bacon of bacon.js is in that you can transform, | ||
@@ -76,5 +82,7 @@ filter and combine these streams in a multitude of ways (see API below). The methods `map`, | ||
var plus = $("#plus").asEventStream("click").map(1) | ||
var minus = $("#minus").asEventStream("click").map(-1) | ||
var both = plus.merge(minus) | ||
```js | ||
var plus = $("#plus").asEventStream("click").map(1) | ||
var minus = $("#minus").asEventStream("click").map(-1) | ||
var both = plus.merge(minus) | ||
``` | ||
@@ -86,3 +94,5 @@ .. you'll have a stream that will output the number 1 when the "plus" button is clicked | ||
both.onValue(function(val) { /* val will be 1 or -1 */ }) | ||
```js | ||
both.onValue(function(val) { /* val will be 1 or -1 */ }) | ||
``` | ||
@@ -95,5 +105,7 @@ In addition to EventStreams, bacon.js has a thing called `Property`, that is almost like an | ||
function add(x, y) { return x + y } | ||
var counter = both.scan(0, add) | ||
counter.onValue(function(sum) { $("#sum").text(sum) }) | ||
```js | ||
function add(x, y) { return x + y } | ||
var counter = both.scan(0, add) | ||
counter.onValue(function(sum) { $("#sum").text(sum) }) | ||
``` | ||
@@ -110,12 +122,18 @@ The `counter` property will contain the sum of the values in the `both` stream, so it's practically | ||
property.assign($("span"), "text") | ||
```js | ||
property.assign($("span"), "text") | ||
``` | ||
Hiding and showing the same span depending on the content of the property value is equally straightforward | ||
function hiddenForEmptyValue(value) { return value == "" ? "hidden" : "visible" } | ||
property.map(hiddenForEmptyValue).assign($("span"), "css", "visibility") | ||
```js | ||
function hiddenForEmptyValue(value) { return value == "" ? "hidden" : "visible" } | ||
property.map(hiddenForEmptyValue).assign($("span"), "css", "visibility") | ||
``` | ||
In the example above a property value of "hello" would be mapped to "visible", which in turn would result in Bacon calling | ||
$("span").css("visibility", "visible") | ||
```js | ||
$("span").css("visibility", "visible") | ||
``` | ||
@@ -134,6 +152,9 @@ For an actual tutorial, please check out my [blog posts](http://nullzzz.blogspot.fi/2012/11/baconjs-tutorial-part-i-hacking-with.html) | ||
event and its parameters, if given, like this: | ||
`$("#my-div").asEventStream("click", ".more-specific-selector")` | ||
`$("#my-div").asEventStream("click", ".more-specific-selector", function(event, args) { return args[0] })` | ||
`$("#my-div").asEventStream("click", function(event, args) { return args[0] })` | ||
```js | ||
$("#my-div").asEventStream("click", ".more-specific-selector") | ||
$("#my-div").asEventStream("click", ".more-specific-selector", function(event, args) { return args[0] }) | ||
$("#my-div").asEventStream("click", function(event, args) { return args[0] }) | ||
``` | ||
`Bacon.fromPromise(promise)` creates an EventStream from a Promise object such as JQuery Ajax. This stream will contain a single value or an error, followed immediately by stream end. | ||
@@ -149,7 +170,9 @@ | ||
Bacon.fromCallback(function(callback) { | ||
setTimeout(function() { | ||
callback("Bacon!") | ||
}, 1000) | ||
}) | ||
```js | ||
Bacon.fromCallback(function(callback) { | ||
setTimeout(function() { | ||
callback("Bacon!") | ||
}, 1000) | ||
}) | ||
``` | ||
@@ -164,7 +187,9 @@ This would create a stream that outputs a single value "Bacon!" and ends | ||
var Bacon = require('baconjs').Bacon, | ||
fs = require('fs'); | ||
var read = Bacon.fromNodeCallback(fs.readFile, 'input.txt'); | ||
read.onError(function(error) { console.log("Reading failed: " + error); }); | ||
read.onValue(function(value) { console.log("Read contents: " + value); }); | ||
```js | ||
var Bacon = require('baconjs').Bacon, | ||
fs = require('fs'); | ||
var read = Bacon.fromNodeCallback(fs.readFile, 'input.txt'); | ||
read.onError(function(error) { console.log("Reading failed: " + error); }); | ||
read.onValue(function(value) { console.log("Read contents: " + value); }); | ||
``` | ||
@@ -212,3 +237,5 @@ `Bacon.fromPoll(interval, f)` polls given function with given interval. | ||
new EventStream(subscribe) | ||
```js | ||
new EventStream(subscribe) | ||
``` | ||
@@ -219,11 +246,13 @@ The parameter `subscribe` is a function that accepts an subscriber which is a function that will receive Events. | ||
new Bacon.EventStream(function(subscriber) { | ||
subscriber(new Bacon.Next("a value here")) | ||
subscriber(new Bacon.Next(function() { | ||
return "This one will be evaluated lazily" | ||
})) | ||
subscriber(new Bacon.Error("oops, an error")) | ||
subscriber(new Bacon.End()) | ||
return function() { // unsub functionality here, this one's a no-op } | ||
}) | ||
```js | ||
new Bacon.EventStream(function(subscriber) { | ||
subscriber(new Bacon.Next("a value here")) | ||
subscriber(new Bacon.Next(function() { | ||
return "This one will be evaluated lazily" | ||
})) | ||
subscriber(new Bacon.Error("oops, an error")) | ||
subscriber(new Bacon.End()) | ||
return function() { // unsub functionality here, this one's a no-op } | ||
}) | ||
``` | ||
@@ -246,8 +275,11 @@ The subscribe function must return a function. Let's call that function | ||
new Bacon.Next("value") | ||
```js | ||
new Bacon.Next("value") | ||
``` | ||
But the canonical way would be | ||
```js | ||
new Bacon.Next(function() { return "value") }) | ||
``` | ||
new Bacon.Next(function() { return "value") }) | ||
The former version is safe only when you know that the actual value in | ||
@@ -309,6 +341,10 @@ the stream is not a function. | ||
var delayed = source.delay(2) | ||
source: asdf----asdf---- | ||
delayed: --asdf----asdf-- | ||
```js | ||
var delayed = source.delay(2) | ||
``` | ||
``` | ||
source: asdf----asdf---- | ||
delayed: --asdf----asdf-- | ||
``` | ||
@@ -322,6 +358,10 @@ `observable.throttle(delay)` throttles stream/property by given amount | ||
var throttled = source.throttle(2) | ||
```js | ||
var throttled = source.throttle(2) | ||
``` | ||
source: asdf----asdf---- | ||
throttled: --s--f----s--f-- | ||
``` | ||
source: asdf----asdf---- | ||
throttled: --s--f----s--f-- | ||
``` | ||
@@ -336,7 +376,11 @@ `observable.debounce(delay)` throttles stream/property by given amount | ||
var debounced = source.debounce(2) | ||
source: asdf----asdf---- | ||
debounce: -----f-------f-- | ||
```js | ||
var debounced = source.debounce(2) | ||
``` | ||
``` | ||
source: asdf----asdf---- | ||
debounce: -----f-------f-- | ||
``` | ||
`observable.doAction(f)` returns a stream/property where the function f | ||
@@ -364,5 +408,7 @@ is executed for each value, before dispatching to subscribers. This is | ||
stream.flatMap(function(text) { | ||
return (text != "") ? Bacon.once(parseInt(text)) : Bacon.never() | ||
}) | ||
```js | ||
stream.flatMap(function(text) { | ||
return (text != "") ? Bacon.once(parseInt(text)) : Bacon.never() | ||
}) | ||
``` | ||
@@ -384,4 +430,6 @@ `observable.flatMapLatest(f)` like flatMap, but instead of including events from | ||
var plus = function (a,b) { return a + b } | ||
Bacon.sequentially(1, [1,2,3]).scan(0, plus) | ||
```js | ||
var plus = function (a,b) { return a + b } | ||
Bacon.sequentially(1, [1,2,3]).scan(0, plus) | ||
``` | ||
@@ -409,4 +457,6 @@ This would result to following elements in the result stream: | ||
var distance = function (a,b) { return Math.abs(b - a) } | ||
Bacon.sequentially(1, [1,2,3]).diff(0, distance) | ||
```js | ||
var distance = function (a,b) { return Math.abs(b - a) } | ||
Bacon.sequentially(1, [1,2,3]).diff(0, distance) | ||
``` | ||
@@ -432,7 +482,11 @@ This would result to following elements in the result stream: | ||
myStream.log("New event in myStream") | ||
```js | ||
myStream.log("New event in myStream") | ||
``` | ||
or just | ||
myStream.log() | ||
```js | ||
myStream.log() | ||
``` | ||
@@ -481,3 +535,5 @@ | ||
stream.bufferWithTime(function(f) { setTimeout(f, 10) }) | ||
```js | ||
stream.bufferWithTime(function(f) { setTimeout(f, 10) }) | ||
``` | ||
@@ -503,3 +559,5 @@ `stream.bufferWithCount(count)` buffers stream events with given count. | ||
var showAjaxIndicator = ajaxRequest.awaiting(ajaxResponse) | ||
```js | ||
var showAjaxIndicator = ajaxRequest.awaiting(ajaxResponse) | ||
``` | ||
@@ -537,3 +595,5 @@ Property | ||
myProperty.assign($("#my-button"), "attr", "disabled") | ||
```js | ||
myProperty.assign($("#my-button"), "attr", "disabled") | ||
``` | ||
@@ -543,3 +603,5 @@ A simpler example would be to toggle the visibility of an element based | ||
myProperty.assign($("#my-button"), "toggle") | ||
```js | ||
myProperty.assign($("#my-button"), "toggle") | ||
``` | ||
@@ -591,3 +653,5 @@ Note that the `assign` method is actually just a synonym for `onValue` and | ||
property.decode({1 : "mike", 2 : who}) | ||
```js | ||
property.decode({1 : "mike", 2 : who}) | ||
``` | ||
@@ -597,3 +661,5 @@ This is actually based on `combineTemplate` so you can compose static | ||
property.decode({1 : { type: "mike" }, 2 : { type: "other", whoThen : who }}) | ||
```js | ||
property.decode({1 : { type: "mike" }, 2 : { type: "other", whoThen : who }}) | ||
``` | ||
@@ -634,7 +700,9 @@ Combining multiple streams and properties | ||
var password, username, firstname, lastname; // <- properties or streams | ||
var loginInfo = Bacon.combineTemplate({ | ||
userid: username, | ||
passwd: password, | ||
name: { first: firstname, last: lastname }}) | ||
```js | ||
var password, username, firstname, lastname; // <- properties or streams | ||
var loginInfo = Bacon.combineTemplate({ | ||
userid: username, | ||
passwd: password, | ||
name: { first: firstname, last: lastname }}) | ||
``` | ||
@@ -645,5 +713,7 @@ .. and your new loginInfo property will combine values from all these | ||
{ userid: "juha", | ||
passwd: "easy", | ||
name : { first: "juha", last: "paananen" }} | ||
```js | ||
{ userid: "juha", | ||
passwd: "easy", | ||
name : { first: "juha", last: "paananen" }} | ||
``` | ||
@@ -655,3 +725,5 @@ In addition to combining data from streams, you can include constant | ||
Bacon.combineWith([stream1,stream2], function(v1,v2) {} ).changes() | ||
```js | ||
Bacon.combineWith([stream1,stream2], function(v1,v2) {} ).changes() | ||
``` | ||
@@ -982,4 +1054,6 @@ Function Construction rules | ||
Bacon = require("baconjs").Bacon | ||
Bacon.sequentially(1000, ["B", "A", "C", "O", "N"]).log() | ||
```js | ||
Bacon = require("baconjs").Bacon | ||
Bacon.sequentially(1000, ["B", "A", "C", "O", "N"]).log() | ||
``` | ||
@@ -986,0 +1060,0 @@ Why Bacon? |
@@ -0,1 +1,5 @@ | ||
## 0.2.5 | ||
- log() does not crash if console or console.log is undefined | ||
## 0.2.4 | ||
@@ -2,0 +6,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
568271
1049