diff --git a/ajax/libs/bacon.js/0.4.1/Bacon.js b/ajax/libs/bacon.js/0.4.1/Bacon.js new file mode 100644 index 000000000..e1dce6d19 --- /dev/null +++ b/ajax/libs/bacon.js/0.4.1/Bacon.js @@ -0,0 +1,2297 @@ +(function() { + var Bacon, Bus, Dispatcher, End, Error, Event, EventStream, Initial, Next, None, Observable, Property, PropertyDispatcher, PropertyTransaction, Some, addPropertyInitValueToStream, assert, assertArray, assertEvent, assertFunction, assertNoArguments, assertString, cloneArray, end, former, indexOf, initial, isFieldKey, isFunction, latter, liftCallback, makeFunction, makeSpawner, methodCall, next, nop, partiallyApplied, sendWrapped, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, _, _ref, + __slice = [].slice, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + if (typeof module !== "undefined" && module !== null) { + module.exports = Bacon = {}; + Bacon.Bacon = Bacon; + } else { + if (typeof require === 'function' && (require.amd != null)) { + define('bacon', [], function() { + return Bacon; + }); + } + this.Bacon = Bacon = {}; + } + + Bacon.fromBinder = function(binder, eventTransformer) { + if (eventTransformer == null) { + eventTransformer = _.id; + } + return new EventStream(function(sink) { + var unbinder; + return unbinder = binder(function() { + var args, event, reply, value, _i, _len, _results; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + value = eventTransformer.apply(null, args); + if (!(value instanceof Array && _.last(value) instanceof Event)) { + value = [value]; + } + _results = []; + for (_i = 0, _len = value.length; _i < _len; _i++) { + event = value[_i]; + reply = sink(event = toEvent(event)); + if (reply === Bacon.noMore || event.isEnd()) { + if (unbinder != null) { + _results.push(unbinder()); + } else { + _results.push(Bacon.scheduler.setTimeout((function() { + return unbinder(); + }), 0)); + } + } else { + _results.push(void 0); + } + } + return _results; + }); + }); + }; + + Bacon.$ = { + asEventStream: function(eventName, selector, eventTransformer) { + var _ref, + _this = this; + if (isFunction(selector)) { + _ref = [selector, null], eventTransformer = _ref[0], selector = _ref[1]; + } + return Bacon.fromBinder(function(handler) { + _this.on(eventName, selector, handler); + return function() { + return _this.off(eventName, selector, handler); + }; + }, eventTransformer); + } + }; + + if ((_ref = typeof jQuery !== "undefined" && jQuery !== null ? jQuery : typeof Zepto !== "undefined" && Zepto !== null ? Zepto : null) != null) { + _ref.fn.asEventStream = Bacon.$.asEventStream; + } + + Bacon.fromEventTarget = function(target, eventName, eventTransformer) { + var sub, unsub, _ref1, _ref2, _ref3, _ref4; + sub = (_ref1 = target.addEventListener) != null ? _ref1 : (_ref2 = target.addListener) != null ? _ref2 : target.bind; + unsub = (_ref3 = target.removeEventListener) != null ? _ref3 : (_ref4 = target.removeListener) != null ? _ref4 : target.unbind; + return Bacon.fromBinder(function(handler) { + sub.call(target, eventName, handler); + return function() { + return unsub.call(target, eventName, handler); + }; + }, eventTransformer); + }; + + Bacon.fromPromise = function(promise, abort) { + return Bacon.fromBinder(function(handler) { + promise.then(handler, function(e) { + return handler(new Error(e)); + }); + return function() { + if (abort) { + return typeof promise.abort === "function" ? promise.abort() : void 0; + } + }; + }, function(value) { + return [value, end()]; + }); + }; + + Bacon.noMore = [""]; + + Bacon.more = [""]; + + Bacon.later = function(delay, value) { + return Bacon.sequentially(delay, [value]); + }; + + Bacon.sequentially = function(delay, values) { + var index; + index = 0; + return Bacon.fromPoll(delay, function() { + var value; + value = values[index++]; + if (index < values.length) { + return value; + } else { + return [value, end()]; + } + }); + }; + + Bacon.repeatedly = function(delay, values) { + var index; + index = 0; + return Bacon.fromPoll(delay, function() { + return values[index++ % values.length]; + }); + }; + + liftCallback = function(wrapped) { + return function() { + var args, f, stream; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + stream = partiallyApplied(wrapped, [ + function(values, callback) { + return f.apply(null, __slice.call(values).concat([callback])); + } + ]); + return Bacon.combineAsArray(args).flatMap(stream); + }; + }; + + Bacon.fromCallback = liftCallback(function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Bacon.fromBinder(function(handler) { + makeFunction(f, args)(handler); + return nop; + }, function(value) { + return [value, end()]; + }); + }); + + Bacon.fromNodeCallback = liftCallback(function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Bacon.fromBinder(function(handler) { + makeFunction(f, args)(handler); + return nop; + }, function(error, value) { + if (error) { + return [new Error(error), end()]; + } + return [value, end()]; + }); + }); + + Bacon.fromPoll = function(delay, poll) { + return Bacon.fromBinder(function(handler) { + var id; + id = Bacon.scheduler.setInterval(handler, delay); + return function() { + return Bacon.scheduler.clearInterval(id); + }; + }, poll); + }; + + Bacon.interval = function(delay, value) { + if (value == null) { + value = {}; + } + return Bacon.fromPoll(delay, function() { + return next(value); + }); + }; + + Bacon.constant = function(value) { + return new Property(sendWrapped([value], initial), true); + }; + + Bacon.never = function() { + return Bacon.fromArray([]); + }; + + Bacon.once = function(value) { + return Bacon.fromArray([value]); + }; + + Bacon.fromArray = function(values) { + return new EventStream(sendWrapped(values, toEvent)); + }; + + sendWrapped = function(values, wrapper) { + return function(sink) { + var value, _i, _len; + for (_i = 0, _len = values.length; _i < _len; _i++) { + value = values[_i]; + sink(wrapper(value)); + } + sink(end()); + return nop; + }; + }; + + Bacon.mergeAll = function(streams) { + var next, stream, _i, _len, _ref1; + assertArray(streams); + stream = _.head(streams); + _ref1 = _.tail(streams); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + next = _ref1[_i]; + stream = stream.merge(next); + } + return stream; + }; + + Bacon.zipAsArray = function() { + var more, streams; + streams = arguments[0], more = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!(streams instanceof Array)) { + streams = [streams].concat(more); + } + return Bacon.zipWith(streams, Array); + }; + + Bacon.zipWith = function(streams, f) { + return new EventStream(function(sink) { + var bufs, handle, j, s, unsubAll, unsubs, unsubscribed, zipSink, _i, _len; + bufs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push([]); + } + return _results; + })(); + unsubscribed = false; + unsubs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(nop); + } + return _results; + })(); + unsubAll = (function() { + var _i, _len; + for (_i = 0, _len = unsubs.length; _i < _len; _i++) { + f = unsubs[_i]; + f(); + } + return unsubscribed = true; + }); + zipSink = function(e) { + var reply; + reply = sink(e); + if (reply === Bacon.noMore || e.isEnd()) { + unsubAll(); + } + return reply; + }; + handle = function(i) { + return function(e) { + var b, reply, vs; + if (e.isError()) { + return zipSink(e); + } else if (e.isInitial()) { + return Bacon.more; + } else { + bufs[i].push(e); + if (!e.isEnd() && _.all((function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = bufs.length; _i < _len; _i++) { + b = bufs[_i]; + _results.push(b.length); + } + return _results; + })())) { + vs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = bufs.length; _i < _len; _i++) { + b = bufs[_i]; + _results.push(b.shift().value()); + } + return _results; + })(); + reply = zipSink(e.apply(_.always(f.apply(null, vs)))); + } + if (_.any((function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = bufs.length; _i < _len; _i++) { + b = bufs[_i]; + _results.push(b.length && b[0].isEnd()); + } + return _results; + })())) { + reply = zipSink(end()); + } + return reply || Bacon.more; + } + }; + }; + for (j = _i = 0, _len = streams.length; _i < _len; j = ++_i) { + s = streams[j]; + unsubs[j] = (function(i) { + if (!unsubscribed) { + return s.subscribe(handle(i)); + } + })(j); + } + return unsubAll; + }); + }; + + Bacon.combineAsArray = function() { + var more, s, streams, values, + _this = this; + streams = arguments[0], more = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!(streams instanceof Array)) { + streams = [streams].concat(more); + } + if (streams.length) { + values = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(None); + } + return _results; + })(); + return new Property(function(sink) { + var checkEnd, combiningSink, ends, index, initialSent, sinkFor, stream, unsubAll, unsubs, unsubscribed, _i, _len; + unsubscribed = false; + unsubs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(nop); + } + return _results; + })(); + unsubAll = (function() { + var f, _i, _len; + for (_i = 0, _len = unsubs.length; _i < _len; _i++) { + f = unsubs[_i]; + f(); + } + return unsubscribed = true; + }); + ends = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(false); + } + return _results; + })(); + checkEnd = function() { + var reply; + if (_.all(ends)) { + reply = sink(end()); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } + }; + initialSent = false; + combiningSink = function(markEnd, setValue) { + return function(event) { + var reply, valueArrayF; + if (event.isEnd()) { + markEnd(); + checkEnd(); + return Bacon.noMore; + } else if (event.isError()) { + reply = sink(event); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } else { + setValue(event.value); + if (_.all(_.map((function(x) { + return x.isDefined; + }), values))) { + if (initialSent && event.isInitial()) { + return Bacon.more; + } else { + initialSent = true; + valueArrayF = function() { + var x, _i, _len, _results; + _results = []; + for (_i = 0, _len = values.length; _i < _len; _i++) { + x = values[_i]; + _results.push(x.get()()); + } + return _results; + }; + reply = sink(event.apply(valueArrayF)); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } + } else { + return Bacon.more; + } + } + }; + }; + sinkFor = function(index) { + return combiningSink((function() { + return ends[index] = true; + }), (function(x) { + return values[index] = new Some(x); + })); + }; + for (index = _i = 0, _len = streams.length; _i < _len; index = ++_i) { + stream = streams[index]; + if (!(stream instanceof Observable)) { + stream = Bacon.constant(stream); + } + if (!unsubscribed) { + unsubs[index] = stream.subscribeInternal(sinkFor(index)); + } + } + return unsubAll; + }); + } else { + return Bacon.constant([]); + } + }; + + Bacon.onValues = function() { + var f, streams, _i; + streams = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), f = arguments[_i++]; + return Bacon.combineAsArray(streams).onValues(f); + }; + + Bacon.combineWith = function() { + var f, streams; + f = arguments[0], streams = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Bacon.combineAsArray(streams).map(function(values) { + return f.apply(null, values); + }); + }; + + Bacon.combineTemplate = function(template) { + var applyStreamValue, combinator, compile, compileTemplate, constantValue, current, funcs, mkContext, setValue, streams; + funcs = []; + streams = []; + current = function(ctxStack) { + return ctxStack[ctxStack.length - 1]; + }; + setValue = function(ctxStack, key, value) { + return current(ctxStack)[key] = value; + }; + applyStreamValue = function(key, index) { + return function(ctxStack, values) { + return setValue(ctxStack, key, values[index]); + }; + }; + constantValue = function(key, value) { + return function(ctxStack, values) { + return setValue(ctxStack, key, value); + }; + }; + mkContext = function(template) { + if (template instanceof Array) { + return []; + } else { + return {}; + } + }; + compile = function(key, value) { + var popContext, pushContext; + if (value instanceof Observable) { + streams.push(value); + return funcs.push(applyStreamValue(key, streams.length - 1)); + } else if (value === Object(value) && typeof value !== "function") { + pushContext = function(key) { + return function(ctxStack, values) { + var newContext; + newContext = mkContext(value); + setValue(ctxStack, key, newContext); + return ctxStack.push(newContext); + }; + }; + popContext = function(ctxStack, values) { + return ctxStack.pop(); + }; + funcs.push(pushContext(key)); + compileTemplate(value); + return funcs.push(popContext); + } else { + return funcs.push(constantValue(key, value)); + } + }; + compileTemplate = function(template) { + return _.each(template, compile); + }; + compileTemplate(template); + combinator = function(values) { + var ctxStack, f, rootContext, _i, _len; + rootContext = mkContext(template); + ctxStack = [rootContext]; + for (_i = 0, _len = funcs.length; _i < _len; _i++) { + f = funcs[_i]; + f(ctxStack, values); + } + return rootContext; + }; + return Bacon.combineAsArray(streams).map(combinator); + }; + + Event = (function() { + + function Event() {} + + Event.prototype.isEvent = function() { + return true; + }; + + Event.prototype.isEnd = function() { + return false; + }; + + Event.prototype.isInitial = function() { + return false; + }; + + Event.prototype.isNext = function() { + return false; + }; + + Event.prototype.isError = function() { + return false; + }; + + Event.prototype.hasValue = function() { + return false; + }; + + Event.prototype.filter = function(f) { + return true; + }; + + Event.prototype.onDone = function(listener) { + return listener(); + }; + + return Event; + + })(); + + Next = (function(_super) { + + __extends(Next, _super); + + function Next(valueF, sourceEvent) { + var _this = this; + if (isFunction(valueF)) { + this.value = function() { + var v; + v = valueF(); + _this.value = _.always(v); + return v; + }; + } else { + this.value = _.always(valueF); + } + } + + Next.prototype.isNext = function() { + return true; + }; + + Next.prototype.hasValue = function() { + return true; + }; + + Next.prototype.fmap = function(f) { + var _this = this; + return this.apply(function() { + return f(_this.value()); + }); + }; + + Next.prototype.apply = function(value) { + return new Next(value); + }; + + Next.prototype.filter = function(f) { + return f(this.value()); + }; + + Next.prototype.describe = function() { + return this.value(); + }; + + return Next; + + })(Event); + + Initial = (function(_super) { + + __extends(Initial, _super); + + function Initial() { + return Initial.__super__.constructor.apply(this, arguments); + } + + Initial.prototype.isInitial = function() { + return true; + }; + + Initial.prototype.isNext = function() { + return false; + }; + + Initial.prototype.apply = function(value) { + return new Initial(value); + }; + + Initial.prototype.toNext = function() { + return new Next(this.value); + }; + + return Initial; + + })(Next); + + End = (function(_super) { + + __extends(End, _super); + + function End() { + return End.__super__.constructor.apply(this, arguments); + } + + End.prototype.isEnd = function() { + return true; + }; + + End.prototype.fmap = function() { + return this; + }; + + End.prototype.apply = function() { + return this; + }; + + End.prototype.describe = function() { + return ""; + }; + + return End; + + })(Event); + + Error = (function(_super) { + + __extends(Error, _super); + + function Error(error) { + this.error = error; + } + + Error.prototype.isError = function() { + return true; + }; + + Error.prototype.fmap = function() { + return this; + }; + + Error.prototype.apply = function() { + return this; + }; + + Error.prototype.describe = function() { + return " " + this.error; + }; + + return Error; + + })(Event); + + Observable = (function() { + + function Observable() { + this.combine = __bind(this.combine, this); + + this.flatMapLatest = __bind(this.flatMapLatest, this); + + this.fold = __bind(this.fold, this); + + this.scan = __bind(this.scan, this); + + this.takeUntil = __bind(this.takeUntil, this); + this.assign = this.onValue; + } + + Observable.prototype.onValue = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.subscribe(function(event) { + if (event.hasValue()) { + return f(event.value()); + } + }); + }; + + Observable.prototype.onValues = function(f) { + return this.onValue(function(args) { + return f.apply(null, args); + }); + }; + + Observable.prototype.onError = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.subscribe(function(event) { + if (event.isError()) { + return f(event.error); + } + }); + }; + + Observable.prototype.onEnd = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.subscribe(function(event) { + if (event.isEnd()) { + return f(); + } + }); + }; + + Observable.prototype.errors = function() { + return this.filter(function() { + return false; + }); + }; + + Observable.prototype.filter = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (f instanceof Property) { + return f.sampledBy(this, function(p, s) { + return [p, s]; + }).filter(function(_arg) { + var p, s; + p = _arg[0], s = _arg[1]; + return p; + }).map(function(_arg) { + var p, s; + p = _arg[0], s = _arg[1]; + return s; + }); + } else { + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.filter(f)) { + return this.push(event); + } else { + return Bacon.more; + } + }); + } + }; + + Observable.prototype.takeWhile = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.filter(f)) { + return this.push(event); + } else { + this.push(end()); + return Bacon.noMore; + } + }); + }; + + Observable.prototype.endOnError = function() { + return this.withHandler(function(event) { + if (event.isError()) { + this.push(event); + return this.push(end()); + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.take = function(count) { + if (count <= 0) { + return Bacon.never(); + } + return this.withHandler(function(event) { + if (!event.hasValue()) { + return this.push(event); + } else { + count--; + if (count > 0) { + return this.push(event); + } else { + this.push(event); + this.push(end()); + return Bacon.noMore; + } + } + }); + }; + + Observable.prototype.map = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + return this.push(event.fmap(f)); + }); + }; + + Observable.prototype.mapError = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.isError()) { + return this.push(next(f(event.error))); + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.mapEnd = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.isEnd()) { + this.push(next(f(event))); + this.push(end()); + return Bacon.noMore; + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.doAction = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.hasValue()) { + f(event.value()); + } + return this.push(event); + }); + }; + + Observable.prototype.takeUntil = function(stopper) { + var src; + src = this; + return this.withSubscribe(function(sink) { + var srcSink, stopperSink, unsubBoth, unsubSrc, unsubStopper, unsubscribed; + unsubscribed = false; + unsubSrc = nop; + unsubStopper = nop; + unsubBoth = function() { + unsubSrc(); + unsubStopper(); + return unsubscribed = true; + }; + srcSink = function(event) { + if (event.isEnd()) { + unsubStopper(); + sink(event); + return Bacon.noMore; + } else { + event.onDone(function() { + var reply; + if (!unsubscribed) { + reply = sink(event); + if (reply === Bacon.noMore) { + return unsubBoth(); + } + } + }); + return Bacon.more; + } + }; + stopperSink = function(event) { + if (event.isError()) { + return Bacon.more; + } else if (event.isEnd()) { + return Bacon.noMore; + } else { + unsubSrc(); + sink(end()); + return Bacon.noMore; + } + }; + unsubSrc = src.subscribe(srcSink); + if (!unsubscribed) { + unsubStopper = stopper.subscribe(stopperSink); + } + return unsubBoth; + }); + }; + + Observable.prototype.skip = function(count) { + return this.withHandler(function(event) { + if (!event.hasValue()) { + return this.push(event); + } else if (count > 0) { + count--; + return Bacon.more; + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.skipDuplicates = function(isEqual) { + if (isEqual == null) { + isEqual = function(a, b) { + return a === b; + }; + } + return this.withStateMachine(None, function(prev, event) { + if (!event.hasValue()) { + return [prev, [event]]; + } else if (prev === None || !isEqual(prev.get(), event.value())) { + return [new Some(event.value()), [event]]; + } else { + return [prev, []]; + } + }); + }; + + Observable.prototype.withStateMachine = function(initState, f) { + var state; + state = initState; + return this.withHandler(function(event) { + var fromF, newState, output, outputs, reply, _i, _len; + fromF = f(state, event); + newState = fromF[0], outputs = fromF[1]; + state = newState; + reply = Bacon.more; + for (_i = 0, _len = outputs.length; _i < _len; _i++) { + output = outputs[_i]; + reply = this.push(output); + if (reply === Bacon.noMore) { + return reply; + } + } + return reply; + }); + }; + + Observable.prototype.scan = function(seed, f) { + var acc, subscribe, + _this = this; + f = toCombinator(f); + acc = toOption(seed); + subscribe = function(sink) { + var initSent, reply, sendInit, unsub; + initSent = false; + unsub = nop; + reply = Bacon.more; + sendInit = function() { + if (!initSent) { + initSent = true; + return acc.forEach(function(value) { + reply = sink(initial(value)); + if (reply === Bacon.noMore) { + unsub(); + return unsub = nop; + } + }); + } + }; + unsub = _this.subscribe(function(event) { + if (event.hasValue()) { + if (initSent && event.isInitial()) { + return Bacon.more; + } else { + initSent = true; + acc = new Some(f(acc.getOrElse(void 0), event.value())); + return sink(event.apply(_.always(acc.get()))); + } + } else { + if (event.isEnd()) { + reply = sendInit(); + } + if (reply !== Bacon.noMore) { + return sink(event); + } + } + }); + sendInit(); + return unsub; + }; + return new Property(subscribe); + }; + + Observable.prototype.fold = function(seed, f) { + return this.scan(seed, f).sampledBy(this.filter(false).mapEnd().toProperty()); + }; + + Observable.prototype.zip = function(other, f) { + if (f == null) { + f = Array; + } + return Bacon.zipWith([this, other], f); + }; + + Observable.prototype.diff = function(start, f) { + f = toCombinator(f); + return this.scan([start], function(prevTuple, next) { + return [next, f(prevTuple[0], next)]; + }).filter(function(tuple) { + return tuple.length === 2; + }).map(function(tuple) { + return tuple[1]; + }); + }; + + Observable.prototype.flatMap = function(f, firstOnly) { + var root; + f = makeSpawner(f); + root = this; + return new EventStream(function(sink) { + var checkEnd, children, rootEnd, spawner, unbind, unsubRoot; + children = []; + rootEnd = false; + unsubRoot = function() {}; + unbind = function() { + var unsubChild, _i, _len; + unsubRoot(); + for (_i = 0, _len = children.length; _i < _len; _i++) { + unsubChild = children[_i]; + unsubChild(); + } + return children = []; + }; + checkEnd = function() { + if (rootEnd && (children.length === 0)) { + return sink(end()); + } + }; + spawner = function(event) { + var child, childEnded, handler, removeChild, unsubChild; + if (event.isEnd()) { + rootEnd = true; + return checkEnd(); + } else if (event.isError()) { + return sink(event); + } else if (firstOnly && children.length) { + return Bacon.more; + } else { + child = f(event.value()); + if (!(child instanceof Observable)) { + child = Bacon.once(child); + } + unsubChild = void 0; + childEnded = false; + removeChild = function() { + if (unsubChild != null) { + _.remove(unsubChild, children); + } + return checkEnd(); + }; + handler = function(event) { + var reply; + if (event.isEnd()) { + removeChild(); + childEnded = true; + return Bacon.noMore; + } else { + if (event instanceof Initial) { + event = event.toNext(); + } + reply = sink(event); + if (reply === Bacon.noMore) { + unbind(); + } + return reply; + } + }; + unsubChild = child.subscribe(handler); + if (!childEnded) { + return children.push(unsubChild); + } + } + }; + unsubRoot = root.subscribe(spawner); + return unbind; + }); + }; + + Observable.prototype.flatMapFirst = function(f) { + return this.flatMap(f, true); + }; + + Observable.prototype.flatMapLatest = function(f) { + var stream, + _this = this; + f = makeSpawner(f); + stream = this.toEventStream(); + return stream.flatMap(function(value) { + return f(value).takeUntil(stream); + }); + }; + + Observable.prototype.not = function() { + return this.map(function(x) { + return !x; + }); + }; + + Observable.prototype.log = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + this.subscribe(function(event) { + return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log.apply(console, __slice.call(args).concat([event.describe()])) : void 0 : void 0; + }); + return this; + }; + + Observable.prototype.slidingWindow = function(n, minValues) { + if (minValues == null) { + minValues = 0; + } + return this.scan([], (function(window, value) { + return window.concat([value]).slice(-n); + })).filter((function(values) { + return values.length >= minValues; + })); + }; + + Observable.prototype.combine = function(other, f) { + var combinator; + combinator = toCombinator(f); + return Bacon.combineAsArray(this, other).map(function(values) { + return combinator(values[0], values[1]); + }); + }; + + return Observable; + + })(); + + Observable.prototype.reduce = Observable.prototype.fold; + + EventStream = (function(_super) { + + __extends(EventStream, _super); + + function EventStream(subscribe) { + var dispatcher; + EventStream.__super__.constructor.call(this); + assertFunction(subscribe); + dispatcher = new Dispatcher(subscribe); + this.subscribe = dispatcher.subscribe; + this.subscribeInternal = this.subscribe; + this.hasSubscribers = dispatcher.hasSubscribers; + } + + EventStream.prototype.map = function() { + var args, p; + p = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (p instanceof Property) { + return p.sampledBy(this, former); + } else { + return EventStream.__super__.map.apply(this, [p].concat(__slice.call(args))); + } + }; + + EventStream.prototype.delay = function(delay) { + return this.flatMap(function(value) { + return Bacon.later(delay, value); + }); + }; + + EventStream.prototype.debounce = function(delay) { + return this.flatMapLatest(function(value) { + return Bacon.later(delay, value); + }); + }; + + EventStream.prototype.debounceImmediate = function(delay) { + return this.flatMapFirst(function(value) { + return Bacon.once(value).concat(Bacon.later(delay).filter(false)); + }); + }; + + EventStream.prototype.throttle = function(delay) { + return this.bufferWithTime(delay).map(function(values) { + return values[values.length - 1]; + }); + }; + + EventStream.prototype.bufferWithTime = function(delay) { + var schedule, + _this = this; + schedule = function(buffer) { + return buffer.schedule(); + }; + return this.buffer(delay, schedule, schedule); + }; + + EventStream.prototype.bufferWithCount = function(count) { + var flushOnCount; + flushOnCount = function(buffer) { + if (buffer.values.length === count) { + return buffer.flush(); + } + }; + return this.buffer(0, flushOnCount); + }; + + EventStream.prototype.buffer = function(delay, onInput, onFlush) { + var buffer, delayMs, reply; + if (onInput == null) { + onInput = (function() {}); + } + if (onFlush == null) { + onFlush = (function() {}); + } + buffer = { + scheduled: false, + end: null, + values: [], + flush: function() { + var reply; + this.scheduled = false; + if (this.values.length > 0) { + reply = this.push(next(this.values)); + this.values = []; + if (this.end != null) { + return this.push(this.end); + } else if (reply !== Bacon.noMore) { + return onFlush(this); + } + } else { + if (this.end != null) { + return this.push(this.end); + } + } + }, + schedule: function() { + var _this = this; + if (!this.scheduled) { + this.scheduled = true; + return delay(function() { + return _this.flush(); + }); + } + } + }; + reply = Bacon.more; + if (!isFunction(delay)) { + delayMs = delay; + delay = function(f) { + return Bacon.scheduler.setTimeout(f, delayMs); + }; + } + return this.withHandler(function(event) { + buffer.push = this.push; + if (event.isError()) { + reply = this.push(event); + } else if (event.isEnd()) { + buffer.end = event; + if (!buffer.scheduled) { + buffer.flush(); + } + } else { + buffer.values.push(event.value()); + onInput(buffer); + } + return reply; + }); + }; + + EventStream.prototype.merge = function(right) { + var left; + left = this; + return new EventStream(function(sink) { + var ends, smartSink, unsubBoth, unsubLeft, unsubRight, unsubscribed; + unsubLeft = nop; + unsubRight = nop; + unsubscribed = false; + unsubBoth = function() { + unsubLeft(); + unsubRight(); + return unsubscribed = true; + }; + ends = 0; + smartSink = function(event) { + var reply; + if (event.isEnd()) { + ends++; + if (ends === 2) { + return sink(end()); + } else { + return Bacon.more; + } + } else { + reply = sink(event); + if (reply === Bacon.noMore) { + unsubBoth(); + } + return reply; + } + }; + unsubLeft = left.subscribe(smartSink); + if (!unsubscribed) { + unsubRight = right.subscribe(smartSink); + } + return unsubBoth; + }); + }; + + EventStream.prototype.toProperty = function(initValue) { + if (arguments.length === 0) { + initValue = None; + } + return this.scan(initValue, latter); + }; + + EventStream.prototype.toEventStream = function() { + return this; + }; + + EventStream.prototype.concat = function(right) { + var left; + left = this; + return new EventStream(function(sink) { + var unsub; + unsub = left.subscribe(function(e) { + if (e.isEnd()) { + return unsub = right.subscribe(sink); + } else { + return sink(e); + } + }); + return function() { + return unsub(); + }; + }); + }; + + EventStream.prototype.awaiting = function(other) { + return this.map(true).merge(other.map(false)).toProperty(false); + }; + + EventStream.prototype.startWith = function(seed) { + return Bacon.once(seed).concat(this); + }; + + EventStream.prototype.withHandler = function(handler) { + var dispatcher; + dispatcher = new Dispatcher(this.subscribe, handler); + return new EventStream(dispatcher.subscribe); + }; + + EventStream.prototype.withSubscribe = function(subscribe) { + return new EventStream(subscribe); + }; + + return EventStream; + + })(Observable); + + Property = (function(_super) { + + __extends(Property, _super); + + function Property(subscribe, handler) { + this.toEventStream = __bind(this.toEventStream, this); + + this.toProperty = __bind(this.toProperty, this); + + this.changes = __bind(this.changes, this); + + this.sample = __bind(this.sample, this); + + var _this = this; + Property.__super__.constructor.call(this); + if (handler === true) { + this.subscribeInternal = subscribe; + } else { + this.subscribeInternal = new PropertyDispatcher(subscribe, handler).subscribe; + } + this.sampledBy = function(sampler, combinator) { + var lazyCombinator, myVal; + lazyCombinator = (combinator != null) ? (combinator = toCombinator(combinator), function(myVal, otherVal) { + return combinator(myVal.value(), otherVal.value()); + }) : function(myVal, otherVal) { + return myVal.value(); + }; + myVal = None; + subscribe = function(sink) { + var unsubBoth, unsubMe, unsubOther, unsubscribed; + unsubscribed = false; + unsubMe = nop; + unsubOther = nop; + unsubBoth = function() { + unsubMe(); + unsubOther(); + return unsubscribed = true; + }; + unsubMe = _this.subscribeInternal(function(event) { + if (event.hasValue()) { + return myVal = new Some(event); + } else if (event.isError()) { + return sink(event); + } + }); + unsubOther = sampler.subscribe(function(event) { + if (event.hasValue()) { + return myVal.forEach(function(myVal) { + return sink(event.apply(lazyCombinator(myVal, event))); + }); + } else { + if (event.isEnd()) { + unsubMe(); + } + return sink(event); + } + }); + return unsubBoth; + }; + if (sampler instanceof Property) { + return new Property(subscribe); + } else { + return new EventStream(subscribe); + } + }; + this.subscribe = function(sink) { + var LatestEvent, end, reply, unsub, value; + reply = Bacon.more; + LatestEvent = (function() { + + function LatestEvent() {} + + LatestEvent.prototype.set = function(event) { + return this.event = event; + }; + + LatestEvent.prototype.send = function() { + var event; + event = this.event; + this.event = null; + if ((event != null) && reply !== Bacon.noMore) { + reply = sink(event); + if (reply === Bacon.noMore) { + return unsub(); + } + } + }; + + return LatestEvent; + + })(); + value = new LatestEvent(); + end = new LatestEvent(); + unsub = nop; + unsub = _this.subscribeInternal(function(event) { + if (event.isError()) { + if (reply !== Bacon.noMore) { + reply = sink(event); + } + } else { + if (event.hasValue()) { + value.set(event); + } else if (event.isEnd()) { + end.set(event); + } + PropertyTransaction.onDone(function() { + value.send(); + return end.send(); + }); + } + return reply; + }); + return function() { + reply = Bacon.noMore; + return unsub(); + }; + }; + } + + Property.prototype.sample = function(interval) { + return this.sampledBy(Bacon.interval(interval, {})); + }; + + Property.prototype.changes = function() { + var _this = this; + return new EventStream(function(sink) { + return _this.subscribe(function(event) { + if (!event.isInitial()) { + return sink(event); + } + }); + }); + }; + + Property.prototype.withHandler = function(handler) { + return new Property(this.subscribeInternal, handler); + }; + + Property.prototype.withSubscribe = function(subscribe) { + return new Property(subscribe); + }; + + Property.prototype.toProperty = function() { + assertNoArguments(arguments); + return this; + }; + + Property.prototype.toEventStream = function() { + var _this = this; + return new EventStream(function(sink) { + return _this.subscribe(function(event) { + if (event.isInitial()) { + event = event.toNext(); + } + return sink(event); + }); + }); + }; + + Property.prototype.and = function(other) { + return this.combine(other, function(x, y) { + return x && y; + }); + }; + + Property.prototype.or = function(other) { + return this.combine(other, function(x, y) { + return x || y; + }); + }; + + Property.prototype.decode = function(cases) { + return this.combine(Bacon.combineTemplate(cases), function(key, values) { + return values[key]; + }); + }; + + Property.prototype.delay = function(delay) { + return this.delayChanges(function(changes) { + return changes.delay(delay); + }); + }; + + Property.prototype.debounce = function(delay) { + return this.delayChanges(function(changes) { + return changes.debounce(delay); + }); + }; + + Property.prototype.throttle = function(delay) { + return this.delayChanges(function(changes) { + return changes.throttle(delay); + }); + }; + + Property.prototype.delayChanges = function(f) { + return addPropertyInitValueToStream(this, f(this.changes())); + }; + + return Property; + + })(Observable); + + addPropertyInitValueToStream = function(property, stream) { + var getInitValue; + getInitValue = function(property) { + var value; + value = None; + property.subscribe(function(event) { + if (event.hasValue()) { + value = new Some(event.value()); + } + return Bacon.noMore; + }); + return value; + }; + return stream.toProperty(getInitValue(property)); + }; + + Dispatcher = (function() { + + function Dispatcher(subscribe, handleEvent) { + var addWaiter, done, ended, prevError, pushing, queue, removeSub, subscriptions, unsubscribeFromSource, waiters, + _this = this; + if (subscribe == null) { + subscribe = function() { + return nop; + }; + } + subscriptions = []; + queue = null; + pushing = false; + ended = false; + this.hasSubscribers = function() { + return subscriptions.length > 0; + }; + prevError = null; + unsubscribeFromSource = nop; + removeSub = function(subscription) { + return subscriptions = _.without(subscription, subscriptions); + }; + waiters = null; + done = function(event) { + var w, ws, _i, _len; + if (waiters != null) { + ws = waiters; + waiters = null; + for (_i = 0, _len = ws.length; _i < _len; _i++) { + w = ws[_i]; + w(); + } + } + return event.onDone = Event.prototype.onDone; + }; + addWaiter = function(listener) { + return waiters = (waiters || []).concat([listener]); + }; + this.push = function(event) { + var reply, sub, success, tmp, _i, _len; + if (!pushing) { + if (event === prevError) { + return; + } + if (event.isError()) { + prevError = event; + } + success = false; + try { + pushing = true; + event.onDone = addWaiter; + tmp = subscriptions; + for (_i = 0, _len = tmp.length; _i < _len; _i++) { + sub = tmp[_i]; + reply = sub.sink(event); + if (reply === Bacon.noMore || event.isEnd()) { + removeSub(sub); + } + } + success = true; + } finally { + pushing = false; + if (!success) { + queue = null; + } + } + success = true; + while (queue != null ? queue.length : void 0) { + event = _.head(queue); + queue = _.tail(queue); + _this.push(event); + } + done(event); + if (_this.hasSubscribers()) { + return Bacon.more; + } else { + return Bacon.noMore; + } + } else { + queue = (queue || []).concat([event]); + return Bacon.more; + } + }; + if (handleEvent == null) { + handleEvent = function(event) { + return this.push(event); + }; + } + this.handleEvent = function(event) { + if (event.isEnd()) { + ended = true; + } + return handleEvent.apply(_this, [event]); + }; + this.subscribe = function(sink) { + var subscription; + if (ended) { + sink(end()); + return nop; + } else { + assertFunction(sink); + subscription = { + sink: sink + }; + subscriptions = subscriptions.concat(subscription); + if (subscriptions.length === 1) { + unsubscribeFromSource = subscribe(_this.handleEvent); + } + assertFunction(unsubscribeFromSource); + return function() { + removeSub(subscription); + if (!_this.hasSubscribers()) { + return unsubscribeFromSource(); + } + }; + } + }; + } + + return Dispatcher; + + })(); + + PropertyDispatcher = (function(_super) { + + __extends(PropertyDispatcher, _super); + + function PropertyDispatcher(subscribe, handleEvent) { + var current, ended, push, + _this = this; + PropertyDispatcher.__super__.constructor.call(this, subscribe, handleEvent); + current = None; + push = this.push; + subscribe = this.subscribe; + ended = false; + this.push = function(event) { + if (event.isEnd()) { + ended = true; + } + if (event.hasValue()) { + current = new Some(event.value()); + } + return PropertyTransaction.inTransaction(function() { + return push.apply(_this, [event]); + }); + }; + this.subscribe = function(sink) { + var initSent, reply, shouldBounceInitialValue; + initSent = false; + shouldBounceInitialValue = function() { + return _this.hasSubscribers() || ended; + }; + reply = current.filter(shouldBounceInitialValue).map(function(val) { + return sink(initial(val)); + }); + if (reply.getOrElse(Bacon.more) === Bacon.noMore) { + return nop; + } else if (ended) { + sink(end()); + return nop; + } else { + return subscribe.apply(_this, [sink]); + } + }; + } + + return PropertyDispatcher; + + })(Dispatcher); + + PropertyTransaction = (function() { + var inTransaction, onDone, tx, txListeners; + txListeners = []; + tx = false; + onDone = function(f) { + if (tx) { + return txListeners.push(f); + } else { + return f(); + } + }; + inTransaction = function(f) { + var g, gs, _i, _len, _results; + if (tx) { + return f(); + } else { + tx = true; + try { + f(); + } finally { + tx = false; + } + gs = txListeners; + txListeners = []; + _results = []; + for (_i = 0, _len = gs.length; _i < _len; _i++) { + g = gs[_i]; + _results.push(g()); + } + return _results; + } + }; + return { + onDone: onDone, + inTransaction: inTransaction + }; + })(); + + Bus = (function(_super) { + + __extends(Bus, _super); + + function Bus() { + var ended, guardedSink, sink, subscribeAll, subscribeInput, subscriptions, unsubAll, unsubscribeInput, + _this = this; + sink = void 0; + subscriptions = []; + ended = false; + guardedSink = function(input) { + return function(event) { + if (event.isEnd()) { + unsubscribeInput(input); + return Bacon.noMore; + } else { + return sink(event); + } + }; + }; + unsubAll = function() { + var sub, _i, _len, _results; + _results = []; + for (_i = 0, _len = subscriptions.length; _i < _len; _i++) { + sub = subscriptions[_i]; + _results.push(typeof sub.unsub === "function" ? sub.unsub() : void 0); + } + return _results; + }; + subscribeInput = function(subscription) { + return subscription.unsub = subscription.input.subscribe(guardedSink(subscription.input)); + }; + unsubscribeInput = function(input) { + var i, sub, _i, _len; + for (i = _i = 0, _len = subscriptions.length; _i < _len; i = ++_i) { + sub = subscriptions[i]; + if (sub.input === input) { + if (typeof sub.unsub === "function") { + sub.unsub(); + } + subscriptions.splice(i, 1); + return; + } + } + }; + subscribeAll = function(newSink) { + var subscription, unsubFuncs, _i, _len, _ref1; + sink = newSink; + unsubFuncs = []; + _ref1 = cloneArray(subscriptions); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + subscription = _ref1[_i]; + subscribeInput(subscription); + } + return unsubAll; + }; + Bus.__super__.constructor.call(this, subscribeAll); + this.plug = function(input) { + var sub; + if (ended) { + return; + } + sub = { + input: input + }; + subscriptions.push(sub); + if ((sink != null)) { + subscribeInput(sub); + } + return function() { + return unsubscribeInput(input); + }; + }; + this.push = function(value) { + return typeof sink === "function" ? sink(next(value)) : void 0; + }; + this.error = function(error) { + return typeof sink === "function" ? sink(new Error(error)) : void 0; + }; + this.end = function() { + ended = true; + unsubAll(); + return typeof sink === "function" ? sink(end()) : void 0; + }; + } + + return Bus; + + })(EventStream); + + Some = (function() { + + function Some(value) { + this.value = value; + } + + Some.prototype.getOrElse = function() { + return this.value; + }; + + Some.prototype.get = function() { + return this.value; + }; + + Some.prototype.filter = function(f) { + if (f(this.value)) { + return new Some(this.value); + } else { + return None; + } + }; + + Some.prototype.map = function(f) { + return new Some(f(this.value)); + }; + + Some.prototype.forEach = function(f) { + return f(this.value); + }; + + Some.prototype.isDefined = true; + + Some.prototype.toArray = function() { + return [this.value]; + }; + + return Some; + + })(); + + None = { + getOrElse: function(value) { + return value; + }, + filter: function() { + return None; + }, + map: function() { + return None; + }, + forEach: function() {}, + isDefined: false, + toArray: function() { + return []; + } + }; + + Bacon.EventStream = EventStream; + + Bacon.Property = Property; + + Bacon.Observable = Observable; + + Bacon.Bus = Bus; + + Bacon.Initial = Initial; + + Bacon.Next = Next; + + Bacon.End = End; + + Bacon.Error = Error; + + nop = function() {}; + + latter = function(_, x) { + return x; + }; + + former = function(x, _) { + return x; + }; + + initial = function(value) { + return new Initial(_.always(value)); + }; + + next = function(value) { + return new Next(_.always(value)); + }; + + end = function() { + return new End(); + }; + + toEvent = function(x) { + if (x instanceof Event) { + return x; + } else { + return next(x); + } + }; + + cloneArray = function(xs) { + return xs.slice(0); + }; + + indexOf = Array.prototype.indexOf ? function(xs, x) { + return xs.indexOf(x); + } : function(xs, x) { + var i, y, _i, _len; + for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) { + y = xs[i]; + if (x === y) { + return i; + } + } + return -1; + }; + + assert = function(message, condition) { + if (!condition) { + throw message; + } + }; + + assertEvent = function(event) { + return assert("not an event : " + event, event instanceof Event && event.isEvent()); + }; + + assertFunction = function(f) { + return assert("not a function : " + f, isFunction(f)); + }; + + isFunction = function(f) { + return typeof f === "function"; + }; + + assertArray = function(xs) { + return assert("not an array : " + xs, xs instanceof Array); + }; + + assertNoArguments = function(args) { + return assert("no arguments supported", args.length === 0); + }; + + assertString = function(x) { + return assert("not a string : " + x, typeof x === "string"); + }; + + methodCall = function(obj, method, args) { + assertString(method); + if (args === void 0) { + args = []; + } + return function(value) { + return obj[method].apply(obj, args.concat([value])); + }; + }; + + partiallyApplied = function(f, applied) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return f.apply(null, applied.concat(args)); + }; + }; + + makeSpawner = function(f) { + if (f instanceof Observable) { + f = _.always(f); + } + assertFunction(f); + return f; + }; + + makeFunction = function(f, args) { + if (isFunction(f)) { + if (args.length) { + return partiallyApplied(f, args); + } else { + return f; + } + } else if (isFieldKey(f)) { + return toFieldExtractor(f, args); + } else if (typeof f === "object" && args.length) { + return methodCall(f, _.head(args), _.tail(args)); + } else { + return _.always(f); + } + }; + + isFieldKey = function(f) { + return (typeof f === "string") && f.length > 1 && f.charAt(0) === "."; + }; + + Bacon.isFieldKey = isFieldKey; + + toFieldExtractor = function(f, args) { + var partFuncs, parts; + parts = f.slice(1).split("."); + partFuncs = _.map(toSimpleExtractor(args), parts); + return function(value) { + var _i, _len; + for (_i = 0, _len = partFuncs.length; _i < _len; _i++) { + f = partFuncs[_i]; + value = f(value); + } + return value; + }; + }; + + toSimpleExtractor = function(args) { + return function(key) { + return function(value) { + var fieldValue; + if (!(value != null)) { + return void 0; + } else { + fieldValue = value[key]; + if (isFunction(fieldValue)) { + return fieldValue.apply(value, args); + } else { + return fieldValue; + } + } + }; + }; + }; + + toFieldKey = function(f) { + return f.slice(1); + }; + + toCombinator = function(f) { + var key; + if (isFunction(f)) { + return f; + } else if (isFieldKey(f)) { + key = toFieldKey(f); + return function(left, right) { + return left[key](right); + }; + } else { + return assert("not a function or a field key: " + f, false); + } + }; + + toOption = function(v) { + if (v instanceof Some || v === None) { + return v; + } else { + return new Some(v); + } + }; + + if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) { + if (typeof define === "function") { + define(function() { + return Bacon; + }); + } + } + + _ = { + head: function(xs) { + return xs[0]; + }, + always: function(x) { + return function() { + return x; + }; + }, + empty: function(xs) { + return xs.length === 0; + }, + tail: function(xs) { + return xs.slice(1, xs.length); + }, + filter: function(f, xs) { + var filtered, x, _i, _len; + filtered = []; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (f(x)) { + filtered.push(x); + } + } + return filtered; + }, + map: function(f, xs) { + var x, _i, _len, _results; + _results = []; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + _results.push(f(x)); + } + return _results; + }, + each: function(xs, f) { + var key, value, _results; + _results = []; + for (key in xs) { + value = xs[key]; + _results.push(f(key, value)); + } + return _results; + }, + toArray: function(xs) { + if (xs instanceof Array) { + return xs; + } else { + return [xs]; + } + }, + contains: function(xs, x) { + return indexOf(xs, x) !== -1; + }, + id: function(x) { + return x; + }, + last: function(xs) { + return xs[xs.length - 1]; + }, + all: function(xs) { + var x, _i, _len; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (!x) { + return false; + } + } + return true; + }, + any: function(xs) { + var x, _i, _len; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (x) { + return true; + } + } + return false; + }, + without: function(x, xs) { + return _.filter((function(y) { + return y !== x; + }), xs); + }, + remove: function(x, xs) { + var i; + i = indexOf(xs, x); + if (i >= 0) { + return xs.splice(i, 1); + } + } + }; + + Bacon._ = _; + + Bacon.scheduler = { + setTimeout: function(f, d) { + return setTimeout(f, d); + }, + setInterval: function(f, i) { + return setInterval(f, i); + }, + clearInterval: function(id) { + return clearInterval(id); + }, + now: function() { + return new Date().getTime(); + } + }; + +}).call(this); diff --git a/ajax/libs/bacon.js/0.4.1/Bacon.min.js b/ajax/libs/bacon.js/0.4.1/Bacon.min.js new file mode 100644 index 000000000..a639fc21c --- /dev/null +++ b/ajax/libs/bacon.js/0.4.1/Bacon.min.js @@ -0,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,q=[].slice,R={}.hasOwnProperty,U=function(e,t){function r(){this.constructor=e}for(var n in t)R.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},z=function(e,t){return function(){return e.apply(t,arguments)}};typeof module!="undefined"&&module!==null?(module.exports=e={},e.Bacon=e):(typeof require=="function"&&require.amd!=null&&define("bacon",[],function(){return e}),this.Bacon=e={}),e.fromBinder=function(t,n){return n==null&&(n=F.id),new o(function(r){var i;return i=t(function(){var t,o,u,a,f,l,c;t=1<=arguments.length?q.call(arguments,0):[],a=n.apply(null,t),a instanceof Array&&F.last(a)instanceof s||(a=[a]),c=[];for(f=0,l=a.length;f"],e.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"},t}(s),i=function(e){function t(e){this.error=e}return U(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" "+this.error},t}(s),l=function(){function t(){this.combine=z(this.combine,this),this.flatMapLatest=z(this.flatMapLatest,this),this.fold=z(this.fold,this),this.scan=z(this.scan,this),this.takeUntil=z(this.takeUntil,this),this.assign=this.onValue}return t.prototype.onValue=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t=N(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?q.call(arguments,1):[],t=N(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?q.call(arguments,1):[],t=N(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?q.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=N(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?q.call(arguments,1):[],n=N(n,t),this.withHandler(function(t){return t.filter(n)?this.push(t):(this.push(g()),e.noMore)})},t.prototype.endOnError=function(){return this.withHandler(function(e){return e.isError()?(this.push(e),this.push(g())):this.push(e)})},t.prototype.take=function(t){return t<=0?e.never():this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(this.push(n),this.push(g()),e.noMore)):this.push(n)})},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t=N(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?q.call(arguments,1):[],t=N(t,e),this.withHandler(function(e){return e.isError()?this.push(L(t(e.error))):this.push(e)})},t.prototype.mapEnd=function(){var t,n;return n=arguments[0],t=2<=arguments.length?q.call(arguments,1):[],n=N(n,t),this.withHandler(function(t){return t.isEnd()?(this.push(L(n(t))),this.push(g()),e.noMore):this.push(t)})},t.prototype.doAction=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t=N(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=A,a=A,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(g()),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 d(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=t})},t.prototype.combine=function(t,n){var r;return r=_(n),e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])})},t}(),l.prototype.reduce=l.prototype.fold,o=function(t){function r(e){var t;r.__super__.constructor.call(this),t=new n(e),this.subscribe=t.subscribe,this.subscribeInternal=this.subscribe,this.hasSubscribers=t.hasSubscribers}return U(r,t),r.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t instanceof c?t.sampledBy(this,y):r.__super__.map.apply(this,[t].concat(q.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.debounceImmediate=function(t){return this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))})},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(L(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,S(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,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=A,a=A,f=!1,o=function(){return u(),a(),f=!0},i=0,s=function(t){var n;return t.isEnd()?(i++,i===2?r(g()):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,x)},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,r){this.toEventStream=z(this.toEventStream,this),this.toProperty=z(this.toProperty,this),this.changes=z(this.changes,this),this.sample=z(this.sample,this);var i=this;n.__super__.constructor.call(this),r===!0?this.subscribeInternal=t:this.subscribeInternal=(new h(t,r)).subscribe,this.sampledBy=function(e,r){var s,u;return s=r!=null?(r=_(r),function(e,t){return r(e.value(),t.value())}):function(e,t){return e.value()},u=f,t=function(t){var n,r,o,a;return a=!1,r=A,o=A,n=function(){return r(),o(),a=!0},r=i.subscribeInternal(function(e){if(e.hasValue())return u=new d(e);if(e.isError())return t(e)}),o=e.subscribe(function(e){return e.hasValue()?u.forEach(function(n){return t(e.apply(s(n,e)))}):(e.isEnd()&&r(),t(e))}),n},e instanceof n?new n(t):new o(t)},this.subscribe=function(t){var n,r,s,o,u;return s=e.more,n=function(){function n(){}return n.prototype.set=function(e){return this.event=e},n.prototype.send=function(){var n;n=this.event,this.event=null;if(n!=null&&s!==e.noMore){s=t(n);if(s===e.noMore)return o()}},n}(),u=new n,r=new n,o=A,o=i.subscribeInternal(function(n){return n.isError()?s!==e.noMore&&(s=t(n)):(n.hasValue()?u.set(n):n.isEnd()&&r.set(n),p.onDone(function(){return u.send(),r.send()})),s}),function(){return s=e.noMore,o()}}}return U(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(this.subscribeInternal,e)},n.prototype.withSubscribe=function(e){return new n(e)},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 v(this,e(this.changes()))},n}(l),v=function(t,n){var r;return r=function(t){var n;return n=f,t.subscribe(function(t){return t.hasValue()&&(n=new d(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,d=this;t==null&&(t=function(){return A}),c=[],f=null,a=!1,o=!1,this.hasSubscribers=function(){return c.length>0},u=null,h=A,l=function(e){return c=F.without(e,c)},p=null,i=function(e){var t,n,r,i;if(p!=null){n=p,p=null;for(r=0,i=n.length;r1&&e.charAt(0)==="."},e.isFieldKey=E,P=function(e,t){var n,r;return r=e.slice(1).split("."),n=F.map(j(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)}},e._=F,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}}}).call(this); \ No newline at end of file diff --git a/ajax/libs/bacon.js/0.4.2/Bacon.js b/ajax/libs/bacon.js/0.4.2/Bacon.js new file mode 100644 index 000000000..2cdf8d92e --- /dev/null +++ b/ajax/libs/bacon.js/0.4.2/Bacon.js @@ -0,0 +1,2298 @@ +(function() { + var Bacon, Bus, Dispatcher, End, Error, Event, EventStream, Initial, Next, None, Observable, Property, PropertyDispatcher, PropertyTransaction, Some, addPropertyInitValueToStream, assert, assertArray, assertEvent, assertFunction, assertNoArguments, assertString, cloneArray, end, former, indexOf, initial, isFieldKey, isFunction, latter, liftCallback, makeFunction, makeSpawner, methodCall, next, nop, partiallyApplied, sendWrapped, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, _, _ref, + __slice = [].slice, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + if (typeof module !== "undefined" && module !== null) { + module.exports = Bacon = {}; + Bacon.Bacon = Bacon; + } else { + if (typeof require === 'function' && (require.amd != null)) { + define('bacon', [], function() { + return Bacon; + }); + } + this.Bacon = Bacon = {}; + } + + Bacon.fromBinder = function(binder, eventTransformer) { + if (eventTransformer == null) { + eventTransformer = _.id; + } + return new EventStream(function(sink) { + var unbinder; + return unbinder = binder(function() { + var args, event, reply, value, _i, _len, _results; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + value = eventTransformer.apply(null, args); + if (!(value instanceof Array && _.last(value) instanceof Event)) { + value = [value]; + } + _results = []; + for (_i = 0, _len = value.length; _i < _len; _i++) { + event = value[_i]; + reply = sink(event = toEvent(event)); + if (reply === Bacon.noMore || event.isEnd()) { + if (unbinder != null) { + _results.push(unbinder()); + } else { + _results.push(Bacon.scheduler.setTimeout((function() { + return unbinder(); + }), 0)); + } + } else { + _results.push(void 0); + } + } + return _results; + }); + }); + }; + + Bacon.$ = { + asEventStream: function(eventName, selector, eventTransformer) { + var _ref, + _this = this; + if (isFunction(selector)) { + _ref = [selector, null], eventTransformer = _ref[0], selector = _ref[1]; + } + return Bacon.fromBinder(function(handler) { + _this.on(eventName, selector, handler); + return function() { + return _this.off(eventName, selector, handler); + }; + }, eventTransformer); + } + }; + + if ((_ref = typeof jQuery !== "undefined" && jQuery !== null ? jQuery : typeof Zepto !== "undefined" && Zepto !== null ? Zepto : null) != null) { + _ref.fn.asEventStream = Bacon.$.asEventStream; + } + + Bacon.fromEventTarget = function(target, eventName, eventTransformer) { + var sub, unsub, _ref1, _ref2, _ref3, _ref4; + sub = (_ref1 = target.addEventListener) != null ? _ref1 : (_ref2 = target.addListener) != null ? _ref2 : target.bind; + unsub = (_ref3 = target.removeEventListener) != null ? _ref3 : (_ref4 = target.removeListener) != null ? _ref4 : target.unbind; + return Bacon.fromBinder(function(handler) { + sub.call(target, eventName, handler); + return function() { + return unsub.call(target, eventName, handler); + }; + }, eventTransformer); + }; + + Bacon.fromPromise = function(promise, abort) { + return Bacon.fromBinder(function(handler) { + promise.then(handler, function(e) { + return handler(new Error(e)); + }); + return function() { + if (abort) { + return typeof promise.abort === "function" ? promise.abort() : void 0; + } + }; + }, function(value) { + return [value, end()]; + }); + }; + + Bacon.noMore = [""]; + + Bacon.more = [""]; + + Bacon.later = function(delay, value) { + return Bacon.sequentially(delay, [value]); + }; + + Bacon.sequentially = function(delay, values) { + var index; + index = 0; + return Bacon.fromPoll(delay, function() { + var value; + value = values[index++]; + if (index < values.length) { + return value; + } else { + return [value, end()]; + } + }); + }; + + Bacon.repeatedly = function(delay, values) { + var index; + index = 0; + return Bacon.fromPoll(delay, function() { + return values[index++ % values.length]; + }); + }; + + liftCallback = function(wrapped) { + return function() { + var args, f, stream; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + stream = partiallyApplied(wrapped, [ + function(values, callback) { + return f.apply(null, __slice.call(values).concat([callback])); + } + ]); + return Bacon.combineAsArray(args).flatMap(stream); + }; + }; + + Bacon.fromCallback = liftCallback(function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Bacon.fromBinder(function(handler) { + makeFunction(f, args)(handler); + return nop; + }, function(value) { + return [value, end()]; + }); + }); + + Bacon.fromNodeCallback = liftCallback(function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Bacon.fromBinder(function(handler) { + makeFunction(f, args)(handler); + return nop; + }, function(error, value) { + if (error) { + return [new Error(error), end()]; + } + return [value, end()]; + }); + }); + + Bacon.fromPoll = function(delay, poll) { + return Bacon.fromBinder(function(handler) { + var id; + id = Bacon.scheduler.setInterval(handler, delay); + return function() { + return Bacon.scheduler.clearInterval(id); + }; + }, poll); + }; + + Bacon.interval = function(delay, value) { + if (value == null) { + value = {}; + } + return Bacon.fromPoll(delay, function() { + return next(value); + }); + }; + + Bacon.constant = function(value) { + return new Property(sendWrapped([value], initial), true); + }; + + Bacon.never = function() { + return Bacon.fromArray([]); + }; + + Bacon.once = function(value) { + return Bacon.fromArray([value]); + }; + + Bacon.fromArray = function(values) { + return new EventStream(sendWrapped(values, toEvent)); + }; + + sendWrapped = function(values, wrapper) { + return function(sink) { + var value, _i, _len; + for (_i = 0, _len = values.length; _i < _len; _i++) { + value = values[_i]; + sink(wrapper(value)); + } + sink(end()); + return nop; + }; + }; + + Bacon.mergeAll = function(streams) { + var next, stream, _i, _len, _ref1; + assertArray(streams); + stream = _.head(streams); + _ref1 = _.tail(streams); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + next = _ref1[_i]; + stream = stream.merge(next); + } + return stream; + }; + + Bacon.zipAsArray = function() { + var more, streams; + streams = arguments[0], more = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!(streams instanceof Array)) { + streams = [streams].concat(more); + } + return Bacon.zipWith(streams, Array); + }; + + Bacon.zipWith = function(streams, f) { + return new EventStream(function(sink) { + var bufs, handle, j, s, unsubAll, unsubs, unsubscribed, zipSink, _i, _len; + bufs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push([]); + } + return _results; + })(); + unsubscribed = false; + unsubs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(nop); + } + return _results; + })(); + unsubAll = (function() { + var _i, _len; + for (_i = 0, _len = unsubs.length; _i < _len; _i++) { + f = unsubs[_i]; + f(); + } + return unsubscribed = true; + }); + zipSink = function(e) { + var reply; + reply = sink(e); + if (reply === Bacon.noMore || e.isEnd()) { + unsubAll(); + } + return reply; + }; + handle = function(i) { + return function(e) { + var b, reply, vs; + if (e.isError()) { + return zipSink(e); + } else if (e.isInitial()) { + return Bacon.more; + } else { + bufs[i].push(e); + if (!e.isEnd() && _.all((function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = bufs.length; _i < _len; _i++) { + b = bufs[_i]; + _results.push(b.length); + } + return _results; + })())) { + vs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = bufs.length; _i < _len; _i++) { + b = bufs[_i]; + _results.push(b.shift().value()); + } + return _results; + })(); + reply = zipSink(e.apply(_.always(f.apply(null, vs)))); + } + if (_.any((function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = bufs.length; _i < _len; _i++) { + b = bufs[_i]; + _results.push(b.length && b[0].isEnd()); + } + return _results; + })())) { + reply = zipSink(end()); + } + return reply || Bacon.more; + } + }; + }; + for (j = _i = 0, _len = streams.length; _i < _len; j = ++_i) { + s = streams[j]; + unsubs[j] = (function(i) { + if (!unsubscribed) { + return s.subscribe(handle(i)); + } + })(j); + } + return unsubAll; + }); + }; + + Bacon.combineAsArray = function() { + var more, s, streams, values, + _this = this; + streams = arguments[0], more = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!(streams instanceof Array)) { + streams = [streams].concat(more); + } + if (streams.length) { + values = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(None); + } + return _results; + })(); + return new Property(function(sink) { + var checkEnd, combiningSink, ends, index, initialSent, sinkFor, stream, unsubAll, unsubs, unsubscribed, _i, _len; + unsubscribed = false; + unsubs = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(nop); + } + return _results; + })(); + unsubAll = (function() { + var f, _i, _len; + for (_i = 0, _len = unsubs.length; _i < _len; _i++) { + f = unsubs[_i]; + f(); + } + return unsubscribed = true; + }); + ends = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(false); + } + return _results; + })(); + checkEnd = function() { + var reply; + if (_.all(ends)) { + reply = sink(end()); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } + }; + initialSent = false; + combiningSink = function(markEnd, setValue) { + return function(event) { + var reply, valueArrayF; + if (event.isEnd()) { + markEnd(); + checkEnd(); + return Bacon.noMore; + } else if (event.isError()) { + reply = sink(event); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } else { + setValue(event.value); + if (_.all(_.map((function(x) { + return x.isDefined; + }), values))) { + if (initialSent && event.isInitial()) { + return Bacon.more; + } else { + initialSent = true; + valueArrayF = function() { + var x, _i, _len, _results; + _results = []; + for (_i = 0, _len = values.length; _i < _len; _i++) { + x = values[_i]; + _results.push(x.get()()); + } + return _results; + }; + reply = sink(event.apply(valueArrayF)); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } + } else { + return Bacon.more; + } + } + }; + }; + sinkFor = function(index) { + return combiningSink((function() { + return ends[index] = true; + }), (function(x) { + return values[index] = new Some(x); + })); + }; + for (index = _i = 0, _len = streams.length; _i < _len; index = ++_i) { + stream = streams[index]; + if (!(stream instanceof Observable)) { + stream = Bacon.constant(stream); + } + if (!unsubscribed) { + unsubs[index] = stream.subscribeInternal(sinkFor(index)); + } + } + return unsubAll; + }); + } else { + return Bacon.constant([]); + } + }; + + Bacon.onValues = function() { + var f, streams, _i; + streams = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), f = arguments[_i++]; + return Bacon.combineAsArray(streams).onValues(f); + }; + + Bacon.combineWith = function() { + var f, streams; + f = arguments[0], streams = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Bacon.combineAsArray(streams).map(function(values) { + return f.apply(null, values); + }); + }; + + Bacon.combineTemplate = function(template) { + var applyStreamValue, combinator, compile, compileTemplate, constantValue, current, funcs, mkContext, setValue, streams; + funcs = []; + streams = []; + current = function(ctxStack) { + return ctxStack[ctxStack.length - 1]; + }; + setValue = function(ctxStack, key, value) { + return current(ctxStack)[key] = value; + }; + applyStreamValue = function(key, index) { + return function(ctxStack, values) { + return setValue(ctxStack, key, values[index]); + }; + }; + constantValue = function(key, value) { + return function(ctxStack, values) { + return setValue(ctxStack, key, value); + }; + }; + mkContext = function(template) { + if (template instanceof Array) { + return []; + } else { + return {}; + } + }; + compile = function(key, value) { + var popContext, pushContext; + if (value instanceof Observable) { + streams.push(value); + return funcs.push(applyStreamValue(key, streams.length - 1)); + } else if (value === Object(value) && typeof value !== "function") { + pushContext = function(key) { + return function(ctxStack, values) { + var newContext; + newContext = mkContext(value); + setValue(ctxStack, key, newContext); + return ctxStack.push(newContext); + }; + }; + popContext = function(ctxStack, values) { + return ctxStack.pop(); + }; + funcs.push(pushContext(key)); + compileTemplate(value); + return funcs.push(popContext); + } else { + return funcs.push(constantValue(key, value)); + } + }; + compileTemplate = function(template) { + return _.each(template, compile); + }; + compileTemplate(template); + combinator = function(values) { + var ctxStack, f, rootContext, _i, _len; + rootContext = mkContext(template); + ctxStack = [rootContext]; + for (_i = 0, _len = funcs.length; _i < _len; _i++) { + f = funcs[_i]; + f(ctxStack, values); + } + return rootContext; + }; + return Bacon.combineAsArray(streams).map(combinator); + }; + + Event = (function() { + + function Event() {} + + Event.prototype.isEvent = function() { + return true; + }; + + Event.prototype.isEnd = function() { + return false; + }; + + Event.prototype.isInitial = function() { + return false; + }; + + Event.prototype.isNext = function() { + return false; + }; + + Event.prototype.isError = function() { + return false; + }; + + Event.prototype.hasValue = function() { + return false; + }; + + Event.prototype.filter = function(f) { + return true; + }; + + Event.prototype.onDone = function(listener) { + return listener(); + }; + + return Event; + + })(); + + Next = (function(_super) { + + __extends(Next, _super); + + function Next(valueF, sourceEvent) { + var _this = this; + if (isFunction(valueF)) { + this.value = function() { + var v; + v = valueF(); + _this.value = _.always(v); + return v; + }; + } else { + this.value = _.always(valueF); + } + } + + Next.prototype.isNext = function() { + return true; + }; + + Next.prototype.hasValue = function() { + return true; + }; + + Next.prototype.fmap = function(f) { + var _this = this; + return this.apply(function() { + return f(_this.value()); + }); + }; + + Next.prototype.apply = function(value) { + return new Next(value); + }; + + Next.prototype.filter = function(f) { + return f(this.value()); + }; + + Next.prototype.describe = function() { + return this.value(); + }; + + return Next; + + })(Event); + + Initial = (function(_super) { + + __extends(Initial, _super); + + function Initial() { + return Initial.__super__.constructor.apply(this, arguments); + } + + Initial.prototype.isInitial = function() { + return true; + }; + + Initial.prototype.isNext = function() { + return false; + }; + + Initial.prototype.apply = function(value) { + return new Initial(value); + }; + + Initial.prototype.toNext = function() { + return new Next(this.value); + }; + + return Initial; + + })(Next); + + End = (function(_super) { + + __extends(End, _super); + + function End() { + return End.__super__.constructor.apply(this, arguments); + } + + End.prototype.isEnd = function() { + return true; + }; + + End.prototype.fmap = function() { + return this; + }; + + End.prototype.apply = function() { + return this; + }; + + End.prototype.describe = function() { + return ""; + }; + + return End; + + })(Event); + + Error = (function(_super) { + + __extends(Error, _super); + + function Error(error) { + this.error = error; + } + + Error.prototype.isError = function() { + return true; + }; + + Error.prototype.fmap = function() { + return this; + }; + + Error.prototype.apply = function() { + return this; + }; + + Error.prototype.describe = function() { + return " " + this.error; + }; + + return Error; + + })(Event); + + Observable = (function() { + + function Observable() { + this.combine = __bind(this.combine, this); + + this.flatMapLatest = __bind(this.flatMapLatest, this); + + this.fold = __bind(this.fold, this); + + this.scan = __bind(this.scan, this); + + this.takeUntil = __bind(this.takeUntil, this); + this.assign = this.onValue; + } + + Observable.prototype.onValue = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.subscribe(function(event) { + if (event.hasValue()) { + return f(event.value()); + } + }); + }; + + Observable.prototype.onValues = function(f) { + return this.onValue(function(args) { + return f.apply(null, args); + }); + }; + + Observable.prototype.onError = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.subscribe(function(event) { + if (event.isError()) { + return f(event.error); + } + }); + }; + + Observable.prototype.onEnd = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.subscribe(function(event) { + if (event.isEnd()) { + return f(); + } + }); + }; + + Observable.prototype.errors = function() { + return this.filter(function() { + return false; + }); + }; + + Observable.prototype.filter = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (f instanceof Property) { + return f.sampledBy(this, function(p, s) { + return [p, s]; + }).filter(function(_arg) { + var p, s; + p = _arg[0], s = _arg[1]; + return p; + }).map(function(_arg) { + var p, s; + p = _arg[0], s = _arg[1]; + return s; + }); + } else { + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.filter(f)) { + return this.push(event); + } else { + return Bacon.more; + } + }); + } + }; + + Observable.prototype.takeWhile = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.filter(f)) { + return this.push(event); + } else { + this.push(end()); + return Bacon.noMore; + } + }); + }; + + Observable.prototype.endOnError = function() { + return this.withHandler(function(event) { + if (event.isError()) { + this.push(event); + return this.push(end()); + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.take = function(count) { + if (count <= 0) { + return Bacon.never(); + } + return this.withHandler(function(event) { + if (!event.hasValue()) { + return this.push(event); + } else { + count--; + if (count > 0) { + return this.push(event); + } else { + this.push(event); + this.push(end()); + return Bacon.noMore; + } + } + }); + }; + + Observable.prototype.map = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + return this.push(event.fmap(f)); + }); + }; + + Observable.prototype.mapError = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.isError()) { + return this.push(next(f(event.error))); + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.mapEnd = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.isEnd()) { + this.push(next(f(event))); + this.push(end()); + return Bacon.noMore; + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.doAction = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + f = makeFunction(f, args); + return this.withHandler(function(event) { + if (event.hasValue()) { + f(event.value()); + } + return this.push(event); + }); + }; + + Observable.prototype.takeUntil = function(stopper) { + var src; + src = this; + return this.withSubscribe(function(sink) { + var srcSink, stopperSink, unsubBoth, unsubSrc, unsubStopper, unsubscribed; + unsubscribed = false; + unsubSrc = nop; + unsubStopper = nop; + unsubBoth = function() { + unsubSrc(); + unsubStopper(); + return unsubscribed = true; + }; + srcSink = function(event) { + if (event.isEnd()) { + unsubStopper(); + sink(event); + return Bacon.noMore; + } else { + event.onDone(function() { + var reply; + if (!unsubscribed) { + reply = sink(event); + if (reply === Bacon.noMore) { + return unsubBoth(); + } + } + }); + return Bacon.more; + } + }; + stopperSink = function(event) { + if (event.isError()) { + return Bacon.more; + } else if (event.isEnd()) { + return Bacon.noMore; + } else { + unsubSrc(); + sink(end()); + return Bacon.noMore; + } + }; + unsubSrc = src.subscribe(srcSink); + if (!unsubscribed) { + unsubStopper = stopper.subscribe(stopperSink); + } + return unsubBoth; + }); + }; + + Observable.prototype.skip = function(count) { + return this.withHandler(function(event) { + if (!event.hasValue()) { + return this.push(event); + } else if (count > 0) { + count--; + return Bacon.more; + } else { + return this.push(event); + } + }); + }; + + Observable.prototype.skipDuplicates = function(isEqual) { + if (isEqual == null) { + isEqual = function(a, b) { + return a === b; + }; + } + return this.withStateMachine(None, function(prev, event) { + if (!event.hasValue()) { + return [prev, [event]]; + } else if (prev === None || !isEqual(prev.get(), event.value())) { + return [new Some(event.value()), [event]]; + } else { + return [prev, []]; + } + }); + }; + + Observable.prototype.withStateMachine = function(initState, f) { + var state; + state = initState; + return this.withHandler(function(event) { + var fromF, newState, output, outputs, reply, _i, _len; + fromF = f(state, event); + newState = fromF[0], outputs = fromF[1]; + state = newState; + reply = Bacon.more; + for (_i = 0, _len = outputs.length; _i < _len; _i++) { + output = outputs[_i]; + reply = this.push(output); + if (reply === Bacon.noMore) { + return reply; + } + } + return reply; + }); + }; + + Observable.prototype.scan = function(seed, f) { + var acc, subscribe, + _this = this; + f = toCombinator(f); + acc = toOption(seed); + subscribe = function(sink) { + var initSent, reply, sendInit, unsub; + initSent = false; + unsub = nop; + reply = Bacon.more; + sendInit = function() { + if (!initSent) { + initSent = true; + return acc.forEach(function(value) { + reply = sink(initial(value)); + if (reply === Bacon.noMore) { + unsub(); + return unsub = nop; + } + }); + } + }; + unsub = _this.subscribe(function(event) { + if (event.hasValue()) { + if (initSent && event.isInitial()) { + return Bacon.more; + } else { + initSent = true; + acc = new Some(f(acc.getOrElse(void 0), event.value())); + return sink(event.apply(_.always(acc.get()))); + } + } else { + if (event.isEnd()) { + reply = sendInit(); + } + if (reply !== Bacon.noMore) { + return sink(event); + } + } + }); + sendInit(); + return unsub; + }; + return new Property(subscribe); + }; + + Observable.prototype.fold = function(seed, f) { + return this.scan(seed, f).sampledBy(this.filter(false).mapEnd().toProperty()); + }; + + Observable.prototype.zip = function(other, f) { + if (f == null) { + f = Array; + } + return Bacon.zipWith([this, other], f); + }; + + Observable.prototype.diff = function(start, f) { + f = toCombinator(f); + return this.scan([start], function(prevTuple, next) { + return [next, f(prevTuple[0], next)]; + }).filter(function(tuple) { + return tuple.length === 2; + }).map(function(tuple) { + return tuple[1]; + }); + }; + + Observable.prototype.flatMap = function(f, firstOnly) { + var root; + f = makeSpawner(f); + root = this; + return new EventStream(function(sink) { + var checkEnd, children, rootEnd, spawner, unbind, unsubRoot; + children = []; + rootEnd = false; + unsubRoot = function() {}; + unbind = function() { + var unsubChild, _i, _len; + unsubRoot(); + for (_i = 0, _len = children.length; _i < _len; _i++) { + unsubChild = children[_i]; + unsubChild(); + } + return children = []; + }; + checkEnd = function() { + if (rootEnd && (children.length === 0)) { + return sink(end()); + } + }; + spawner = function(event) { + var child, childEnded, handler, removeChild, unsubChild; + if (event.isEnd()) { + rootEnd = true; + return checkEnd(); + } else if (event.isError()) { + return sink(event); + } else if (firstOnly && children.length) { + return Bacon.more; + } else { + child = f(event.value()); + if (!(child instanceof Observable)) { + child = Bacon.once(child); + } + unsubChild = void 0; + childEnded = false; + removeChild = function() { + if (unsubChild != null) { + _.remove(unsubChild, children); + } + return checkEnd(); + }; + handler = function(event) { + var reply; + if (event.isEnd()) { + removeChild(); + childEnded = true; + return Bacon.noMore; + } else { + if (event instanceof Initial) { + event = event.toNext(); + } + reply = sink(event); + if (reply === Bacon.noMore) { + unbind(); + } + return reply; + } + }; + unsubChild = child.subscribe(handler); + if (!childEnded) { + return children.push(unsubChild); + } + } + }; + unsubRoot = root.subscribe(spawner); + return unbind; + }); + }; + + Observable.prototype.flatMapFirst = function(f) { + return this.flatMap(f, true); + }; + + Observable.prototype.flatMapLatest = function(f) { + var stream, + _this = this; + f = makeSpawner(f); + stream = this.toEventStream(); + return stream.flatMap(function(value) { + return f(value).takeUntil(stream); + }); + }; + + Observable.prototype.not = function() { + return this.map(function(x) { + return !x; + }); + }; + + Observable.prototype.log = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + this.subscribe(function(event) { + return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log.apply(console, __slice.call(args).concat([event.describe()])) : void 0 : void 0; + }); + return this; + }; + + Observable.prototype.slidingWindow = function(n, minValues) { + if (minValues == null) { + minValues = 0; + } + return this.scan([], (function(window, value) { + return window.concat([value]).slice(-n); + })).filter((function(values) { + return values.length >= minValues; + })); + }; + + Observable.prototype.combine = function(other, f) { + var combinator; + combinator = toCombinator(f); + return Bacon.combineAsArray(this, other).map(function(values) { + return combinator(values[0], values[1]); + }); + }; + + return Observable; + + })(); + + Observable.prototype.reduce = Observable.prototype.fold; + + EventStream = (function(_super) { + + __extends(EventStream, _super); + + function EventStream(subscribe) { + var dispatcher; + EventStream.__super__.constructor.call(this); + assertFunction(subscribe); + dispatcher = new Dispatcher(subscribe); + this.subscribe = dispatcher.subscribe; + this.subscribeInternal = this.subscribe; + this.hasSubscribers = dispatcher.hasSubscribers; + } + + EventStream.prototype.map = function() { + var args, p; + p = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (p instanceof Property) { + return p.sampledBy(this, former); + } else { + return EventStream.__super__.map.apply(this, [p].concat(__slice.call(args))); + } + }; + + EventStream.prototype.delay = function(delay) { + return this.flatMap(function(value) { + return Bacon.later(delay, value); + }); + }; + + EventStream.prototype.debounce = function(delay) { + return this.flatMapLatest(function(value) { + return Bacon.later(delay, value); + }); + }; + + EventStream.prototype.debounceImmediate = function(delay) { + return this.flatMapFirst(function(value) { + return Bacon.once(value).concat(Bacon.later(delay).filter(false)); + }); + }; + + EventStream.prototype.throttle = function(delay) { + return this.bufferWithTime(delay).map(function(values) { + return values[values.length - 1]; + }); + }; + + EventStream.prototype.bufferWithTime = function(delay) { + return this.bufferWithTimeOrCount(delay, Number.MAX_VALUE); + }; + + EventStream.prototype.bufferWithCount = function(count) { + return this.bufferWithTimeOrCount(void 0, count); + }; + + EventStream.prototype.bufferWithTimeOrCount = function(delay, count) { + var flushOrSchedule; + flushOrSchedule = function(buffer) { + if (buffer.values.length === count) { + return buffer.flush(); + } else if (delay !== void 0) { + return buffer.schedule(); + } + }; + return this.buffer(delay, flushOrSchedule, flushOrSchedule); + }; + + EventStream.prototype.buffer = function(delay, onInput, onFlush) { + var buffer, delayMs, reply; + if (onInput == null) { + onInput = (function() {}); + } + if (onFlush == null) { + onFlush = (function() {}); + } + buffer = { + scheduled: false, + end: null, + values: [], + flush: function() { + var reply; + this.scheduled = false; + if (this.values.length > 0) { + reply = this.push(next(this.values)); + this.values = []; + if (this.end != null) { + return this.push(this.end); + } else if (reply !== Bacon.noMore) { + return onFlush(this); + } + } else { + if (this.end != null) { + return this.push(this.end); + } + } + }, + schedule: function() { + var _this = this; + if (!this.scheduled) { + this.scheduled = true; + return delay(function() { + return _this.flush(); + }); + } + } + }; + reply = Bacon.more; + if (!isFunction(delay)) { + delayMs = delay; + delay = function(f) { + return Bacon.scheduler.setTimeout(f, delayMs); + }; + } + return this.withHandler(function(event) { + buffer.push = this.push; + if (event.isError()) { + reply = this.push(event); + } else if (event.isEnd()) { + buffer.end = event; + if (!buffer.scheduled) { + buffer.flush(); + } + } else { + buffer.values.push(event.value()); + onInput(buffer); + } + return reply; + }); + }; + + EventStream.prototype.merge = function(right) { + var left; + left = this; + return new EventStream(function(sink) { + var ends, smartSink, unsubBoth, unsubLeft, unsubRight, unsubscribed; + unsubLeft = nop; + unsubRight = nop; + unsubscribed = false; + unsubBoth = function() { + unsubLeft(); + unsubRight(); + return unsubscribed = true; + }; + ends = 0; + smartSink = function(event) { + var reply; + if (event.isEnd()) { + ends++; + if (ends === 2) { + return sink(end()); + } else { + return Bacon.more; + } + } else { + reply = sink(event); + if (reply === Bacon.noMore) { + unsubBoth(); + } + return reply; + } + }; + unsubLeft = left.subscribe(smartSink); + if (!unsubscribed) { + unsubRight = right.subscribe(smartSink); + } + return unsubBoth; + }); + }; + + EventStream.prototype.toProperty = function(initValue) { + if (arguments.length === 0) { + initValue = None; + } + return this.scan(initValue, latter); + }; + + EventStream.prototype.toEventStream = function() { + return this; + }; + + EventStream.prototype.concat = function(right) { + var left; + left = this; + return new EventStream(function(sink) { + var unsub; + unsub = left.subscribe(function(e) { + if (e.isEnd()) { + return unsub = right.subscribe(sink); + } else { + return sink(e); + } + }); + return function() { + return unsub(); + }; + }); + }; + + EventStream.prototype.awaiting = function(other) { + return this.map(true).merge(other.map(false)).toProperty(false); + }; + + EventStream.prototype.startWith = function(seed) { + return Bacon.once(seed).concat(this); + }; + + EventStream.prototype.withHandler = function(handler) { + var dispatcher; + dispatcher = new Dispatcher(this.subscribe, handler); + return new EventStream(dispatcher.subscribe); + }; + + EventStream.prototype.withSubscribe = function(subscribe) { + return new EventStream(subscribe); + }; + + return EventStream; + + })(Observable); + + Property = (function(_super) { + + __extends(Property, _super); + + function Property(subscribe, handler) { + this.toEventStream = __bind(this.toEventStream, this); + + this.toProperty = __bind(this.toProperty, this); + + this.changes = __bind(this.changes, this); + + this.sample = __bind(this.sample, this); + + var _this = this; + Property.__super__.constructor.call(this); + if (handler === true) { + this.subscribeInternal = subscribe; + } else { + this.subscribeInternal = new PropertyDispatcher(subscribe, handler).subscribe; + } + this.sampledBy = function(sampler, combinator) { + var lazyCombinator, myVal; + lazyCombinator = (combinator != null) ? (combinator = toCombinator(combinator), function(myVal, otherVal) { + return combinator(myVal.value(), otherVal.value()); + }) : function(myVal, otherVal) { + return myVal.value(); + }; + myVal = None; + subscribe = function(sink) { + var unsubBoth, unsubMe, unsubOther, unsubscribed; + unsubscribed = false; + unsubMe = nop; + unsubOther = nop; + unsubBoth = function() { + unsubMe(); + unsubOther(); + return unsubscribed = true; + }; + unsubMe = _this.subscribeInternal(function(event) { + if (event.hasValue()) { + return myVal = new Some(event); + } else if (event.isError()) { + return sink(event); + } + }); + unsubOther = sampler.subscribe(function(event) { + if (event.hasValue()) { + return myVal.forEach(function(myVal) { + return sink(event.apply(lazyCombinator(myVal, event))); + }); + } else { + if (event.isEnd()) { + unsubMe(); + } + return sink(event); + } + }); + return unsubBoth; + }; + if (sampler instanceof Property) { + return new Property(subscribe); + } else { + return new EventStream(subscribe); + } + }; + this.subscribe = function(sink) { + var LatestEvent, end, reply, unsub, value; + reply = Bacon.more; + LatestEvent = (function() { + + function LatestEvent() {} + + LatestEvent.prototype.set = function(event) { + return this.event = event; + }; + + LatestEvent.prototype.send = function() { + var event; + event = this.event; + this.event = null; + if ((event != null) && reply !== Bacon.noMore) { + reply = sink(event); + if (reply === Bacon.noMore) { + return unsub(); + } + } + }; + + return LatestEvent; + + })(); + value = new LatestEvent(); + end = new LatestEvent(); + unsub = nop; + unsub = _this.subscribeInternal(function(event) { + if (event.isError()) { + if (reply !== Bacon.noMore) { + reply = sink(event); + } + } else { + if (event.hasValue()) { + value.set(event); + } else if (event.isEnd()) { + end.set(event); + } + PropertyTransaction.onDone(function() { + value.send(); + return end.send(); + }); + } + return reply; + }); + return function() { + reply = Bacon.noMore; + return unsub(); + }; + }; + } + + Property.prototype.sample = function(interval) { + return this.sampledBy(Bacon.interval(interval, {})); + }; + + Property.prototype.changes = function() { + var _this = this; + return new EventStream(function(sink) { + return _this.subscribe(function(event) { + if (!event.isInitial()) { + return sink(event); + } + }); + }); + }; + + Property.prototype.withHandler = function(handler) { + return new Property(this.subscribeInternal, handler); + }; + + Property.prototype.withSubscribe = function(subscribe) { + return new Property(subscribe); + }; + + Property.prototype.toProperty = function() { + assertNoArguments(arguments); + return this; + }; + + Property.prototype.toEventStream = function() { + var _this = this; + return new EventStream(function(sink) { + return _this.subscribe(function(event) { + if (event.isInitial()) { + event = event.toNext(); + } + return sink(event); + }); + }); + }; + + Property.prototype.and = function(other) { + return this.combine(other, function(x, y) { + return x && y; + }); + }; + + Property.prototype.or = function(other) { + return this.combine(other, function(x, y) { + return x || y; + }); + }; + + Property.prototype.decode = function(cases) { + return this.combine(Bacon.combineTemplate(cases), function(key, values) { + return values[key]; + }); + }; + + Property.prototype.delay = function(delay) { + return this.delayChanges(function(changes) { + return changes.delay(delay); + }); + }; + + Property.prototype.debounce = function(delay) { + return this.delayChanges(function(changes) { + return changes.debounce(delay); + }); + }; + + Property.prototype.throttle = function(delay) { + return this.delayChanges(function(changes) { + return changes.throttle(delay); + }); + }; + + Property.prototype.delayChanges = function(f) { + return addPropertyInitValueToStream(this, f(this.changes())); + }; + + return Property; + + })(Observable); + + addPropertyInitValueToStream = function(property, stream) { + var getInitValue; + getInitValue = function(property) { + var value; + value = None; + property.subscribe(function(event) { + if (event.hasValue()) { + value = new Some(event.value()); + } + return Bacon.noMore; + }); + return value; + }; + return stream.toProperty(getInitValue(property)); + }; + + Dispatcher = (function() { + + function Dispatcher(subscribe, handleEvent) { + var addWaiter, done, ended, prevError, pushing, queue, removeSub, subscriptions, unsubscribeFromSource, waiters, + _this = this; + if (subscribe == null) { + subscribe = function() { + return nop; + }; + } + subscriptions = []; + queue = null; + pushing = false; + ended = false; + this.hasSubscribers = function() { + return subscriptions.length > 0; + }; + prevError = null; + unsubscribeFromSource = nop; + removeSub = function(subscription) { + return subscriptions = _.without(subscription, subscriptions); + }; + waiters = null; + done = function(event) { + var w, ws, _i, _len; + if (waiters != null) { + ws = waiters; + waiters = null; + for (_i = 0, _len = ws.length; _i < _len; _i++) { + w = ws[_i]; + w(); + } + } + return event.onDone = Event.prototype.onDone; + }; + addWaiter = function(listener) { + return waiters = (waiters || []).concat([listener]); + }; + this.push = function(event) { + var reply, sub, success, tmp, _i, _len; + if (!pushing) { + if (event === prevError) { + return; + } + if (event.isError()) { + prevError = event; + } + success = false; + try { + pushing = true; + event.onDone = addWaiter; + tmp = subscriptions; + for (_i = 0, _len = tmp.length; _i < _len; _i++) { + sub = tmp[_i]; + reply = sub.sink(event); + if (reply === Bacon.noMore || event.isEnd()) { + removeSub(sub); + } + } + success = true; + } finally { + pushing = false; + if (!success) { + queue = null; + } + } + success = true; + while (queue != null ? queue.length : void 0) { + event = _.head(queue); + queue = _.tail(queue); + _this.push(event); + } + done(event); + if (_this.hasSubscribers()) { + return Bacon.more; + } else { + return Bacon.noMore; + } + } else { + queue = (queue || []).concat([event]); + return Bacon.more; + } + }; + if (handleEvent == null) { + handleEvent = function(event) { + return this.push(event); + }; + } + this.handleEvent = function(event) { + if (event.isEnd()) { + ended = true; + } + return handleEvent.apply(_this, [event]); + }; + this.subscribe = function(sink) { + var subscription; + if (ended) { + sink(end()); + return nop; + } else { + assertFunction(sink); + subscription = { + sink: sink + }; + subscriptions = subscriptions.concat(subscription); + if (subscriptions.length === 1) { + unsubscribeFromSource = subscribe(_this.handleEvent); + } + assertFunction(unsubscribeFromSource); + return function() { + removeSub(subscription); + if (!_this.hasSubscribers()) { + return unsubscribeFromSource(); + } + }; + } + }; + } + + return Dispatcher; + + })(); + + PropertyDispatcher = (function(_super) { + + __extends(PropertyDispatcher, _super); + + function PropertyDispatcher(subscribe, handleEvent) { + var current, ended, push, + _this = this; + PropertyDispatcher.__super__.constructor.call(this, subscribe, handleEvent); + current = None; + push = this.push; + subscribe = this.subscribe; + ended = false; + this.push = function(event) { + if (event.isEnd()) { + ended = true; + } + if (event.hasValue()) { + current = new Some(event.value()); + } + return PropertyTransaction.inTransaction(function() { + return push.apply(_this, [event]); + }); + }; + this.subscribe = function(sink) { + var initSent, reply, shouldBounceInitialValue; + initSent = false; + shouldBounceInitialValue = function() { + return _this.hasSubscribers() || ended; + }; + reply = current.filter(shouldBounceInitialValue).map(function(val) { + return sink(initial(val)); + }); + if (reply.getOrElse(Bacon.more) === Bacon.noMore) { + return nop; + } else if (ended) { + sink(end()); + return nop; + } else { + return subscribe.apply(_this, [sink]); + } + }; + } + + return PropertyDispatcher; + + })(Dispatcher); + + PropertyTransaction = (function() { + var inTransaction, onDone, tx, txListeners; + txListeners = []; + tx = false; + onDone = function(f) { + if (tx) { + return txListeners.push(f); + } else { + return f(); + } + }; + inTransaction = function(f) { + var g, gs, _i, _len, _results; + if (tx) { + return f(); + } else { + tx = true; + try { + f(); + } finally { + tx = false; + } + gs = txListeners; + txListeners = []; + _results = []; + for (_i = 0, _len = gs.length; _i < _len; _i++) { + g = gs[_i]; + _results.push(g()); + } + return _results; + } + }; + return { + onDone: onDone, + inTransaction: inTransaction + }; + })(); + + Bus = (function(_super) { + + __extends(Bus, _super); + + function Bus() { + var ended, guardedSink, sink, subscribeAll, subscribeInput, subscriptions, unsubAll, unsubscribeInput, + _this = this; + sink = void 0; + subscriptions = []; + ended = false; + guardedSink = function(input) { + return function(event) { + if (event.isEnd()) { + unsubscribeInput(input); + return Bacon.noMore; + } else { + return sink(event); + } + }; + }; + unsubAll = function() { + var sub, _i, _len, _results; + _results = []; + for (_i = 0, _len = subscriptions.length; _i < _len; _i++) { + sub = subscriptions[_i]; + _results.push(typeof sub.unsub === "function" ? sub.unsub() : void 0); + } + return _results; + }; + subscribeInput = function(subscription) { + return subscription.unsub = subscription.input.subscribe(guardedSink(subscription.input)); + }; + unsubscribeInput = function(input) { + var i, sub, _i, _len; + for (i = _i = 0, _len = subscriptions.length; _i < _len; i = ++_i) { + sub = subscriptions[i]; + if (sub.input === input) { + if (typeof sub.unsub === "function") { + sub.unsub(); + } + subscriptions.splice(i, 1); + return; + } + } + }; + subscribeAll = function(newSink) { + var subscription, unsubFuncs, _i, _len, _ref1; + sink = newSink; + unsubFuncs = []; + _ref1 = cloneArray(subscriptions); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + subscription = _ref1[_i]; + subscribeInput(subscription); + } + return unsubAll; + }; + Bus.__super__.constructor.call(this, subscribeAll); + this.plug = function(input) { + var sub; + if (ended) { + return; + } + sub = { + input: input + }; + subscriptions.push(sub); + if ((sink != null)) { + subscribeInput(sub); + } + return function() { + return unsubscribeInput(input); + }; + }; + this.push = function(value) { + return typeof sink === "function" ? sink(next(value)) : void 0; + }; + this.error = function(error) { + return typeof sink === "function" ? sink(new Error(error)) : void 0; + }; + this.end = function() { + ended = true; + unsubAll(); + return typeof sink === "function" ? sink(end()) : void 0; + }; + } + + return Bus; + + })(EventStream); + + Some = (function() { + + function Some(value) { + this.value = value; + } + + Some.prototype.getOrElse = function() { + return this.value; + }; + + Some.prototype.get = function() { + return this.value; + }; + + Some.prototype.filter = function(f) { + if (f(this.value)) { + return new Some(this.value); + } else { + return None; + } + }; + + Some.prototype.map = function(f) { + return new Some(f(this.value)); + }; + + Some.prototype.forEach = function(f) { + return f(this.value); + }; + + Some.prototype.isDefined = true; + + Some.prototype.toArray = function() { + return [this.value]; + }; + + return Some; + + })(); + + None = { + getOrElse: function(value) { + return value; + }, + filter: function() { + return None; + }, + map: function() { + return None; + }, + forEach: function() {}, + isDefined: false, + toArray: function() { + return []; + } + }; + + Bacon.EventStream = EventStream; + + Bacon.Property = Property; + + Bacon.Observable = Observable; + + Bacon.Bus = Bus; + + Bacon.Initial = Initial; + + Bacon.Next = Next; + + Bacon.End = End; + + Bacon.Error = Error; + + nop = function() {}; + + latter = function(_, x) { + return x; + }; + + former = function(x, _) { + return x; + }; + + initial = function(value) { + return new Initial(_.always(value)); + }; + + next = function(value) { + return new Next(_.always(value)); + }; + + end = function() { + return new End(); + }; + + toEvent = function(x) { + if (x instanceof Event) { + return x; + } else { + return next(x); + } + }; + + cloneArray = function(xs) { + return xs.slice(0); + }; + + indexOf = Array.prototype.indexOf ? function(xs, x) { + return xs.indexOf(x); + } : function(xs, x) { + var i, y, _i, _len; + for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) { + y = xs[i]; + if (x === y) { + return i; + } + } + return -1; + }; + + assert = function(message, condition) { + if (!condition) { + throw message; + } + }; + + assertEvent = function(event) { + return assert("not an event : " + event, event instanceof Event && event.isEvent()); + }; + + assertFunction = function(f) { + return assert("not a function : " + f, isFunction(f)); + }; + + isFunction = function(f) { + return typeof f === "function"; + }; + + assertArray = function(xs) { + return assert("not an array : " + xs, xs instanceof Array); + }; + + assertNoArguments = function(args) { + return assert("no arguments supported", args.length === 0); + }; + + assertString = function(x) { + return assert("not a string : " + x, typeof x === "string"); + }; + + methodCall = function(obj, method, args) { + assertString(method); + if (args === void 0) { + args = []; + } + return function(value) { + return obj[method].apply(obj, args.concat([value])); + }; + }; + + partiallyApplied = function(f, applied) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return f.apply(null, applied.concat(args)); + }; + }; + + makeSpawner = function(f) { + if (f instanceof Observable) { + f = _.always(f); + } + assertFunction(f); + return f; + }; + + makeFunction = function(f, args) { + if (isFunction(f)) { + if (args.length) { + return partiallyApplied(f, args); + } else { + return f; + } + } else if (isFieldKey(f)) { + return toFieldExtractor(f, args); + } else if (typeof f === "object" && args.length) { + return methodCall(f, _.head(args), _.tail(args)); + } else { + return _.always(f); + } + }; + + isFieldKey = function(f) { + return (typeof f === "string") && f.length > 1 && f.charAt(0) === "."; + }; + + Bacon.isFieldKey = isFieldKey; + + toFieldExtractor = function(f, args) { + var partFuncs, parts; + parts = f.slice(1).split("."); + partFuncs = _.map(toSimpleExtractor(args), parts); + return function(value) { + var _i, _len; + for (_i = 0, _len = partFuncs.length; _i < _len; _i++) { + f = partFuncs[_i]; + value = f(value); + } + return value; + }; + }; + + toSimpleExtractor = function(args) { + return function(key) { + return function(value) { + var fieldValue; + if (!(value != null)) { + return void 0; + } else { + fieldValue = value[key]; + if (isFunction(fieldValue)) { + return fieldValue.apply(value, args); + } else { + return fieldValue; + } + } + }; + }; + }; + + toFieldKey = function(f) { + return f.slice(1); + }; + + toCombinator = function(f) { + var key; + if (isFunction(f)) { + return f; + } else if (isFieldKey(f)) { + key = toFieldKey(f); + return function(left, right) { + return left[key](right); + }; + } else { + return assert("not a function or a field key: " + f, false); + } + }; + + toOption = function(v) { + if (v instanceof Some || v === None) { + return v; + } else { + return new Some(v); + } + }; + + if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) { + if (typeof define === "function") { + define(function() { + return Bacon; + }); + } + } + + _ = { + head: function(xs) { + return xs[0]; + }, + always: function(x) { + return function() { + return x; + }; + }, + empty: function(xs) { + return xs.length === 0; + }, + tail: function(xs) { + return xs.slice(1, xs.length); + }, + filter: function(f, xs) { + var filtered, x, _i, _len; + filtered = []; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (f(x)) { + filtered.push(x); + } + } + return filtered; + }, + map: function(f, xs) { + var x, _i, _len, _results; + _results = []; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + _results.push(f(x)); + } + return _results; + }, + each: function(xs, f) { + var key, value, _results; + _results = []; + for (key in xs) { + value = xs[key]; + _results.push(f(key, value)); + } + return _results; + }, + toArray: function(xs) { + if (xs instanceof Array) { + return xs; + } else { + return [xs]; + } + }, + contains: function(xs, x) { + return indexOf(xs, x) !== -1; + }, + id: function(x) { + return x; + }, + last: function(xs) { + return xs[xs.length - 1]; + }, + all: function(xs) { + var x, _i, _len; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (!x) { + return false; + } + } + return true; + }, + any: function(xs) { + var x, _i, _len; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (x) { + return true; + } + } + return false; + }, + without: function(x, xs) { + return _.filter((function(y) { + return y !== x; + }), xs); + }, + remove: function(x, xs) { + var i; + i = indexOf(xs, x); + if (i >= 0) { + return xs.splice(i, 1); + } + } + }; + + Bacon._ = _; + + Bacon.scheduler = { + setTimeout: function(f, d) { + return setTimeout(f, d); + }, + setInterval: function(f, i) { + return setInterval(f, i); + }, + clearInterval: function(id) { + return clearInterval(id); + }, + now: function() { + return new Date().getTime(); + } + }; + +}).call(this); diff --git a/ajax/libs/bacon.js/0.4.2/Bacon.min.js b/ajax/libs/bacon.js/0.4.2/Bacon.min.js new file mode 100644 index 000000000..37523ebdd --- /dev/null +++ b/ajax/libs/bacon.js/0.4.2/Bacon.min.js @@ -0,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,q=[].slice,R={}.hasOwnProperty,U=function(e,t){function r(){this.constructor=e}for(var n in t)R.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},z=function(e,t){return function(){return e.apply(t,arguments)}};typeof module!="undefined"&&module!==null?(module.exports=e={},e.Bacon=e):(typeof require=="function"&&require.amd!=null&&define("bacon",[],function(){return e}),this.Bacon=e={}),e.fromBinder=function(t,n){return n==null&&(n=F.id),new o(function(r){var i;return i=t(function(){var t,o,u,a,f,l,c;t=1<=arguments.length?q.call(arguments,0):[],a=n.apply(null,t),a instanceof Array&&F.last(a)instanceof s||(a=[a]),c=[];for(f=0,l=a.length;f"],e.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"},t}(s),i=function(e){function t(e){this.error=e}return U(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" "+this.error},t}(s),l=function(){function t(){this.combine=z(this.combine,this),this.flatMapLatest=z(this.flatMapLatest,this),this.fold=z(this.fold,this),this.scan=z(this.scan,this),this.takeUntil=z(this.takeUntil,this),this.assign=this.onValue}return t.prototype.onValue=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t=N(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?q.call(arguments,1):[],t=N(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?q.call(arguments,1):[],t=N(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?q.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=N(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?q.call(arguments,1):[],n=N(n,t),this.withHandler(function(t){return t.filter(n)?this.push(t):(this.push(g()),e.noMore)})},t.prototype.endOnError=function(){return this.withHandler(function(e){return e.isError()?(this.push(e),this.push(g())):this.push(e)})},t.prototype.take=function(t){return t<=0?e.never():this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(this.push(n),this.push(g()),e.noMore)):this.push(n)})},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t=N(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?q.call(arguments,1):[],t=N(t,e),this.withHandler(function(e){return e.isError()?this.push(L(t(e.error))):this.push(e)})},t.prototype.mapEnd=function(){var t,n;return n=arguments[0],t=2<=arguments.length?q.call(arguments,1):[],n=N(n,t),this.withHandler(function(t){return t.isEnd()?(this.push(L(n(t))),this.push(g()),e.noMore):this.push(t)})},t.prototype.doAction=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t=N(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=A,a=A,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(g()),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 d(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=t})},t.prototype.combine=function(t,n){var r;return r=_(n),e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])})},t}(),l.prototype.reduce=l.prototype.fold,o=function(t){function r(e){var t;r.__super__.constructor.call(this),t=new n(e),this.subscribe=t.subscribe,this.subscribeInternal=this.subscribe,this.hasSubscribers=t.hasSubscribers}return U(r,t),r.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?q.call(arguments,1):[],t instanceof c?t.sampledBy(this,y):r.__super__.map.apply(this,[t].concat(q.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.debounceImmediate=function(t){return this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))})},r.prototype.throttle=function(e){return this.bufferWithTime(e).map(function(e){return e[e.length-1]})},r.prototype.bufferWithTime=function(e){return this.bufferWithTimeOrCount(e,Number.MAX_VALUE)},r.prototype.bufferWithCount=function(e){return this.bufferWithTimeOrCount(void 0,e)},r.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},this.buffer(e,n,n)},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(L(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,S(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,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=A,a=A,f=!1,o=function(){return u(),a(),f=!0},i=0,s=function(t){var n;return t.isEnd()?(i++,i===2?r(g()):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,x)},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,r){this.toEventStream=z(this.toEventStream,this),this.toProperty=z(this.toProperty,this),this.changes=z(this.changes,this),this.sample=z(this.sample,this);var i=this;n.__super__.constructor.call(this),r===!0?this.subscribeInternal=t:this.subscribeInternal=(new h(t,r)).subscribe,this.sampledBy=function(e,r){var s,u;return s=r!=null?(r=_(r),function(e,t){return r(e.value(),t.value())}):function(e,t){return e.value()},u=f,t=function(t){var n,r,o,a;return a=!1,r=A,o=A,n=function(){return r(),o(),a=!0},r=i.subscribeInternal(function(e){if(e.hasValue())return u=new d(e);if(e.isError())return t(e)}),o=e.subscribe(function(e){return e.hasValue()?u.forEach(function(n){return t(e.apply(s(n,e)))}):(e.isEnd()&&r(),t(e))}),n},e instanceof n?new n(t):new o(t)},this.subscribe=function(t){var n,r,s,o,u;return s=e.more,n=function(){function n(){}return n.prototype.set=function(e){return this.event=e},n.prototype.send=function(){var n;n=this.event,this.event=null;if(n!=null&&s!==e.noMore){s=t(n);if(s===e.noMore)return o()}},n}(),u=new n,r=new n,o=A,o=i.subscribeInternal(function(n){return n.isError()?s!==e.noMore&&(s=t(n)):(n.hasValue()?u.set(n):n.isEnd()&&r.set(n),p.onDone(function(){return u.send(),r.send()})),s}),function(){return s=e.noMore,o()}}}return U(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(this.subscribeInternal,e)},n.prototype.withSubscribe=function(e){return new n(e)},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 v(this,e(this.changes()))},n}(l),v=function(t,n){var r;return r=function(t){var n;return n=f,t.subscribe(function(t){return t.hasValue()&&(n=new d(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,d=this;t==null&&(t=function(){return A}),c=[],f=null,a=!1,o=!1,this.hasSubscribers=function(){return c.length>0},u=null,h=A,l=function(e){return c=F.without(e,c)},p=null,i=function(e){var t,n,r,i;if(p!=null){n=p,p=null;for(r=0,i=n.length;r1&&e.charAt(0)==="."},e.isFieldKey=E,P=function(e,t){var n,r;return r=e.slice(1).split("."),n=F.map(j(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)}},e._=F,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}}}).call(this); \ No newline at end of file diff --git a/ajax/libs/bacon.js/package.json b/ajax/libs/bacon.js/package.json index 4bc82c802..ef1f4c024 100644 --- a/ajax/libs/bacon.js/package.json +++ b/ajax/libs/bacon.js/package.json @@ -1,7 +1,7 @@ { "name": "bacon.js", "filename": "Bacon.min.js", - "version": "0.3.15", + "version": "0.4.2", "author": "Juha Paananen", "description": "A small functional reactive programming lib for JavaScript.", "homepage": "http://baconjs.blogspot.com",