diff --git a/ajax/libs/bacon.js/0.7.7/bacon.js b/ajax/libs/bacon.js/0.7.7/bacon.js new file mode 100644 index 000000000..102a6fc4e --- /dev/null +++ b/ajax/libs/bacon.js/0.7.7/bacon.js @@ -0,0 +1,2898 @@ +(function() { + var Bacon, BufferingSource, Bus, CompositeUnsubscribe, Desc, Dispatcher, End, Error, Event, EventStream, Initial, Next, None, Observable, Property, PropertyDispatcher, Some, Source, UpdateBarrier, addPropertyInitValueToStream, assert, assertArray, assertEventStream, assertFunction, assertNoArguments, assertString, cloneArray, compositeUnsubscribe, containsDuplicateDeps, convertArgsToFunction, describe, end, eventIdCounter, flatMap_, former, idCounter, initial, isArray, isFieldKey, isFunction, isObservable, latterF, liftCallback, makeFunction, makeFunctionArgs, makeFunction_, makeObservable, makeSpawner, next, nop, partiallyApplied, recursionDepth, registerObs, spys, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, withDescription, withMethodCallSupport, _, _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); }; }; + + Bacon = { + toString: function() { + return "Bacon"; + } + }; + + Bacon.version = '0.7.7'; + + Bacon.fromBinder = function(binder, eventTransformer) { + if (eventTransformer == null) { + eventTransformer = _.id; + } + return new EventStream(describe(Bacon, "fromBinder", binder, eventTransformer), function(sink) { + var unbinder; + return unbinder = binder(function() { + var args, event, reply, value, _i, _len; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + value = eventTransformer.apply(null, args); + if (!(isArray(value) && _.last(value) instanceof Event)) { + value = [value]; + } + reply = Bacon.more; + 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) { + unbinder(); + } else { + Bacon.scheduler.setTimeout((function() { + return unbinder(); + }), 0); + } + return reply; + } + } + return reply; + }); + }); + }; + + Bacon.$ = { + asEventStream: function(eventName, selector, eventTransformer) { + var _ref; + if (isFunction(selector)) { + _ref = [selector, null], eventTransformer = _ref[0], selector = _ref[1]; + } + return withDescription(this, "asEventStream", eventName, Bacon.fromBinder((function(_this) { + return function(handler) { + _this.on(eventName, selector, handler); + return function() { + return _this.off(eventName, selector, handler); + }; + }; + })(this), 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 withDescription(Bacon, "fromEventTarget", target, eventName, Bacon.fromBinder(function(handler) { + sub.call(target, eventName, handler); + return function() { + return unsub.call(target, eventName, handler); + }; + }, eventTransformer)); + }; + + Bacon.fromPromise = function(promise, abort) { + return withDescription(Bacon, "fromPromise", promise, 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 withDescription(Bacon, "later", delay, value, Bacon.sequentially(delay, [value])); + }; + + Bacon.sequentially = function(delay, values) { + var index; + index = 0; + return withDescription(Bacon, "sequentially", delay, values, Bacon.fromPoll(delay, function() { + var value; + value = values[index++]; + if (index < values.length) { + return value; + } else if (index === values.length) { + return [value, end()]; + } else { + return end(); + } + })); + }; + + Bacon.repeatedly = function(delay, values) { + var index; + index = 0; + return withDescription(Bacon, "repeatedly", delay, values, Bacon.fromPoll(delay, function() { + return values[index++ % values.length]; + })); + }; + + Bacon.spy = function(spy) { + return spys.push(spy); + }; + + spys = []; + + registerObs = function(obs) { + var spy, _i, _len, _results; + if (spys.length) { + if (!registerObs.running) { + try { + registerObs.running = true; + _results = []; + for (_i = 0, _len = spys.length; _i < _len; _i++) { + spy = spys[_i]; + _results.push(spy(obs)); + } + return _results; + } finally { + delete registerObs.running; + } + } + } + }; + + withMethodCallSupport = function(wrapped) { + return function() { + var args, context, f, methodName; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (typeof f === "object" && args.length) { + context = f; + methodName = args[0]; + f = function() { + return context[methodName].apply(context, arguments); + }; + args = args.slice(1); + } + return wrapped.apply(null, [f].concat(__slice.call(args))); + }; + }; + + liftCallback = function(desc, wrapped) { + return withMethodCallSupport(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 withDescription.apply(null, [Bacon, desc, f].concat(__slice.call(args), [Bacon.combineAsArray(args).flatMap(stream)])); + }); + }; + + Bacon.fromCallback = liftCallback("fromCallback", 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("fromNodeCallback", 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 withDescription(Bacon, "fromPoll", delay, poll, 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 withDescription(Bacon, "interval", delay, value, Bacon.fromPoll(delay, function() { + return next(value); + })); + }; + + Bacon.constant = function(value) { + return new Property(describe(Bacon, "constant", value), function(sink) { + sink(initial(value)); + sink(end()); + return nop; + }); + }; + + Bacon.never = function() { + return withDescription(Bacon, "never", Bacon.fromArray([])); + }; + + Bacon.once = function(value) { + return withDescription(Bacon, "once", value, Bacon.fromArray([value])); + }; + + Bacon.fromArray = function(values) { + assertArray(values); + values = cloneArray(values); + return new EventStream(describe(Bacon, "fromArray", values), function(sink) { + var send, unsubd; + unsubd = false; + send = function() { + var reply, value; + if (_.empty(values)) { + return sink(end()); + } else { + value = values.splice(0, 1)[0]; + reply = sink(toEvent(value)); + if ((reply !== Bacon.noMore) && !unsubd) { + return send(); + } + } + }; + send(); + return function() { + return unsubd = true; + }; + }); + }; + + Bacon.mergeAll = function() { + var streams; + streams = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (isArray(streams[0])) { + streams = streams[0]; + } + return withDescription.apply(null, [Bacon, "mergeAll"].concat(__slice.call(streams), [_.fold(streams, Bacon.never(), (function(a, b) { + return a.merge(b); + }))])); + }; + + Bacon.zipAsArray = function() { + var streams; + streams = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (isArray(streams[0])) { + streams = streams[0]; + } + return withDescription.apply(null, [Bacon, "zipAsArray"].concat(__slice.call(streams), [Bacon.zipWith(streams, function() { + var xs; + xs = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return xs; + })])); + }; + + Bacon.zipWith = function() { + var f, streams, _ref1; + f = arguments[0], streams = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!isFunction(f)) { + _ref1 = [f, streams[0]], streams = _ref1[0], f = _ref1[1]; + } + streams = _.map((function(s) { + return s.toEventStream(); + }), streams); + return withDescription.apply(null, [Bacon, "zipWith", f].concat(__slice.call(streams), [Bacon.when(streams, f)])); + }; + + Bacon.groupSimultaneous = function() { + var s, sources, streams; + streams = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (streams.length === 1 && isArray(streams[0])) { + streams = streams[0]; + } + sources = (function() { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = streams.length; _i < _len; _i++) { + s = streams[_i]; + _results.push(new BufferingSource(s)); + } + return _results; + })(); + return withDescription.apply(null, [Bacon, "groupSimultaneous"].concat(__slice.call(streams), [Bacon.when(sources, (function() { + var xs; + xs = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return xs; + }))])); + }; + + Bacon.combineAsArray = function() { + var index, s, sources, stream, streams, _i, _len; + streams = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (streams.length === 1 && isArray(streams[0])) { + streams = streams[0]; + } + for (index = _i = 0, _len = streams.length; _i < _len; index = ++_i) { + stream = streams[index]; + if (!(isObservable(stream))) { + streams[index] = Bacon.constant(stream); + } + } + if (streams.length) { + sources = (function() { + var _j, _len1, _results; + _results = []; + for (_j = 0, _len1 = streams.length; _j < _len1; _j++) { + s = streams[_j]; + _results.push(new Source(s, true, false, s.subscribeInternal)); + } + return _results; + })(); + return withDescription.apply(null, [Bacon, "combineAsArray"].concat(__slice.call(streams), [Bacon.when(sources, (function() { + var xs; + xs = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return xs; + })).toProperty()])); + } 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 withDescription.apply(null, [Bacon, "combineWith", f].concat(__slice.call(streams), [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) { + return setValue(ctxStack, key, value); + }; + }; + mkContext = function(template) { + if (isArray(template)) { + return []; + } else { + return {}; + } + }; + compile = function(key, value) { + var popContext, pushContext; + if (isObservable(value)) { + streams.push(value); + return funcs.push(applyStreamValue(key, streams.length - 1)); + } else if (value === Object(value) && typeof value !== "function" && !(value instanceof RegExp) && !(value instanceof Date)) { + pushContext = function(key) { + return function(ctxStack) { + var newContext; + newContext = mkContext(value); + setValue(ctxStack, key, newContext); + return ctxStack.push(newContext); + }; + }; + popContext = function(ctxStack) { + 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 withDescription(Bacon, "combineTemplate", template, Bacon.combineAsArray(streams).map(combinator)); + }; + + eventIdCounter = 0; + + Event = (function() { + function Event() { + this.id = ++eventIdCounter; + } + + 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() { + return true; + }; + + Event.prototype.inspect = function() { + return this.toString(); + }; + + return Event; + + })(); + + Next = (function(_super) { + __extends(Next, _super); + + function Next(valueF) { + Next.__super__.constructor.call(this); + if (isFunction(valueF)) { + this.value = _.cached(valueF); + } else { + this.value = _.always(valueF); + } + } + + Next.prototype.isNext = function() { + return true; + }; + + Next.prototype.hasValue = function() { + return true; + }; + + Next.prototype.fmap = function(f) { + return this.apply((function(_this) { + return function() { + return f(_this.value()); + }; + })(this)); + }; + + Next.prototype.apply = function(value) { + return new Next(value); + }; + + Next.prototype.filter = function(f) { + return f(this.value()); + }; + + Next.prototype.toString = function() { + return _.toString(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.toString = 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.toString = function() { + return " " + _.toString(this.error); + }; + + return Error; + + })(Event); + + idCounter = 0; + + Observable = (function() { + function Observable(desc) { + 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.id = ++idCounter; + this.assign = this.onValue; + withDescription(desc, this); + } + + Observable.prototype.onValue = function() { + var f; + f = makeFunctionArgs(arguments); + 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 f; + f = makeFunctionArgs(arguments); + return this.subscribe(function(event) { + if (event.isError()) { + return f(event.error); + } + }); + }; + + Observable.prototype.onEnd = function() { + var f; + f = makeFunctionArgs(arguments); + return this.subscribe(function(event) { + if (event.isEnd()) { + return f(); + } + }); + }; + + Observable.prototype.errors = function() { + return withDescription(this, "errors", this.filter(function() { + return false; + })); + }; + + Observable.prototype.filter = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return convertArgsToFunction(this, f, args, function(f) { + return withDescription(this, "filter", f, 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) : []; + return convertArgsToFunction(this, f, args, function(f) { + return withDescription(this, "takeWhile", f, this.withHandler(function(event) { + if (event.filter(f)) { + return this.push(event); + } else { + this.push(end()); + return Bacon.noMore; + } + })); + }); + }; + + Observable.prototype.endOnError = function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (f == null) { + f = true; + } + return convertArgsToFunction(this, f, args, function(f) { + return withDescription(this, "endOnError", this.withHandler(function(event) { + if (event.isError() && f(event.error)) { + this.push(event); + return this.push(end()); + } else { + return this.push(event); + } + })); + }); + }; + + Observable.prototype.take = function(count) { + if (count <= 0) { + return Bacon.never(); + } + return withDescription(this, "take", count, this.withHandler(function(event) { + if (!event.hasValue()) { + return this.push(event); + } else { + count--; + if (count > 0) { + return this.push(event); + } else { + if (count === 0) { + this.push(event); + } + this.push(end()); + return Bacon.noMore; + } + } + })); + }; + + Observable.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 convertArgsToFunction(this, p, args, function(f) { + return withDescription(this, "map", f, this.withHandler(function(event) { + return this.push(event.fmap(f)); + })); + }); + } + }; + + Observable.prototype.mapError = function() { + var f; + f = makeFunctionArgs(arguments); + return withDescription(this, "mapError", f, this.withHandler(function(event) { + if (event.isError()) { + return this.push(next(f(event.error))); + } else { + return this.push(event); + } + })); + }; + + Observable.prototype.mapEnd = function() { + var f; + f = makeFunctionArgs(arguments); + return withDescription(this, "mapEnd", f, 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 f; + f = makeFunctionArgs(arguments); + return withDescription(this, "doAction", f, this.withHandler(function(event) { + if (event.hasValue()) { + f(event.value()); + } + return this.push(event); + })); + }; + + Observable.prototype.skip = function(count) { + return withDescription(this, "skip", count, 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 withDescription(this, "skipDuplicates", this.withStateMachine(None, function(prev, event) { + if (!event.hasValue()) { + return [prev, [event]]; + } else if (event.isInitial() || prev === None || !isEqual(prev.get(), event.value())) { + return [new Some(event.value()), [event]]; + } else { + return [prev, []]; + } + })); + }; + + Observable.prototype.skipErrors = function() { + return withDescription(this, "skipErrors", this.withHandler(function(event) { + if (event.isError()) { + return Bacon.more; + } else { + return this.push(event); + } + })); + }; + + Observable.prototype.withStateMachine = function(initState, f) { + var state; + state = initState; + return withDescription(this, "withStateMachine", initState, f, 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, lazyF) { + var acc, f_, resultProperty, root, subscribe; + f_ = toCombinator(f); + f = lazyF ? f_ : function(x, y) { + return f_(x(), y()); + }; + acc = toOption(seed).map(function(x) { + return _.always(x); + }); + root = this; + subscribe = (function(_this) { + return function(sink) { + var initSent, reply, sendInit, unsub; + initSent = false; + unsub = nop; + reply = Bacon.more; + sendInit = function() { + if (!initSent) { + return acc.forEach(function(valueF) { + initSent = true; + reply = sink(new Initial(valueF)); + if (reply === Bacon.noMore) { + unsub(); + return unsub = nop; + } + }); + } + }; + unsub = _this.subscribeInternal(function(event) { + var next, prev; + if (event.hasValue()) { + if (initSent && event.isInitial()) { + return Bacon.more; + } else { + if (!event.isInitial()) { + sendInit(); + } + initSent = true; + prev = acc.getOrElse(function() { + return void 0; + }); + next = _.cached(function() { + return f(prev, event.value); + }); + acc = new Some(next); + return sink(event.apply(next)); + } + } else { + if (event.isEnd()) { + reply = sendInit(); + } + if (reply !== Bacon.noMore) { + return sink(event); + } + } + }); + UpdateBarrier.whenDoneWith(resultProperty, sendInit); + return unsub; + }; + })(this); + return resultProperty = new Property(describe(this, "scan", seed, f), subscribe); + }; + + Observable.prototype.fold = function(seed, f) { + return withDescription(this, "fold", seed, f, this.scan(seed, f).sampledBy(this.filter(false).mapEnd().toProperty())); + }; + + Observable.prototype.zip = function(other, f) { + if (f == null) { + f = Array; + } + return withDescription(this, "zip", other, Bacon.zipWith([this, other], f)); + }; + + Observable.prototype.diff = function(start, f) { + f = toCombinator(f); + return withDescription(this, "diff", start, f, 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() { + return flatMap_(this, makeSpawner(arguments)); + }; + + Observable.prototype.flatMapFirst = function() { + return flatMap_(this, makeSpawner(arguments), true); + }; + + Observable.prototype.flatMapLatest = function() { + var f, stream; + f = makeSpawner(arguments); + stream = this.toEventStream(); + return withDescription(this, "flatMapLatest", f, stream.flatMap((function(_this) { + return function(value) { + return makeObservable(f(value)).takeUntil(stream); + }; + })(this))); + }; + + Observable.prototype.not = function() { + return withDescription(this, "not", 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.toString()])) : void 0 : void 0; + }); + return this; + }; + + Observable.prototype.slidingWindow = function(n, minValues) { + if (minValues == null) { + minValues = 0; + } + return withDescription(this, "slidingWindow", n, minValues, 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 withDescription(this, "combine", other, f, Bacon.combineAsArray(this, other).map(function(values) { + return combinator(values[0], values[1]); + })); + }; + + Observable.prototype.decode = function(cases) { + return withDescription(this, "decode", cases, this.combine(Bacon.combineTemplate(cases), function(key, values) { + return values[key]; + })); + }; + + Observable.prototype.awaiting = function(other) { + return withDescription(this, "awaiting", other, Bacon.groupSimultaneous(this, other).map(function(_arg) { + var myValues, otherValues; + myValues = _arg[0], otherValues = _arg[1]; + return otherValues.length === 0; + }).toProperty(false).skipDuplicates()); + }; + + Observable.prototype.name = function(name) { + this.toString = function() { + return name; + }; + return this; + }; + + Observable.prototype.withDescription = function() { + return describe.apply(null, arguments).apply(this); + }; + + return Observable; + + })(); + + Observable.prototype.reduce = Observable.prototype.fold; + + flatMap_ = function(root, f, firstOnly) { + return new EventStream(describe(root, "flatMap" + (firstOnly ? "First" : ""), f), function(sink) { + var checkEnd, composite; + composite = new CompositeUnsubscribe(); + checkEnd = function(unsub) { + unsub(); + if (composite.empty()) { + return sink(end()); + } + }; + composite.add(function(__, unsubRoot) { + return root.subscribeInternal(function(event) { + var child; + if (event.isEnd()) { + return checkEnd(unsubRoot); + } else if (event.isError()) { + return sink(event); + } else if (firstOnly && composite.count() > 1) { + return Bacon.more; + } else { + if (composite.unsubscribed) { + return Bacon.noMore; + } + child = makeObservable(f(event.value())); + return composite.add(function(unsubAll, unsubMe) { + return child.subscribeInternal(function(event) { + var reply; + if (event.isEnd()) { + checkEnd(unsubMe); + return Bacon.noMore; + } else { + if (event instanceof Initial) { + event = event.toNext(); + } + reply = sink(event); + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + } + }); + }); + } + }); + }); + return composite.unsubscribe; + }); + }; + + EventStream = (function(_super) { + __extends(EventStream, _super); + + function EventStream(desc, subscribe) { + this.takeUntil = __bind(this.takeUntil, this); + this.sampledBy = __bind(this.sampledBy, this); + var dispatcher; + if (isFunction(desc)) { + subscribe = desc; + desc = []; + } + EventStream.__super__.constructor.call(this, desc); + assertFunction(subscribe); + dispatcher = new Dispatcher(subscribe); + this.subscribeInternal = dispatcher.subscribe; + this.subscribe = UpdateBarrier.wrappedSubscribe(this); + this.hasSubscribers = dispatcher.hasSubscribers; + registerObs(this); + } + + EventStream.prototype.delay = function(delay) { + return withDescription(this, "delay", delay, this.flatMap(function(value) { + return Bacon.later(delay, value); + })); + }; + + EventStream.prototype.debounce = function(delay) { + return withDescription(this, "debounce", delay, this.flatMapLatest(function(value) { + return Bacon.later(delay, value); + })); + }; + + EventStream.prototype.debounceImmediate = function(delay) { + return withDescription(this, "debounceImmediate", delay, this.flatMapFirst(function(value) { + return Bacon.once(value).concat(Bacon.later(delay).filter(false)); + })); + }; + + EventStream.prototype.throttle = function(delay) { + return withDescription(this, "throttle", delay, this.bufferWithTime(delay).map(function(values) { + return values[values.length - 1]; + })); + }; + + EventStream.prototype.bufferWithTime = function(delay) { + return withDescription(this, "bufferWithTime", delay, this.bufferWithTimeOrCount(delay, Number.MAX_VALUE)); + }; + + EventStream.prototype.bufferWithCount = function(count) { + return withDescription(this, "bufferWithCount", count, 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 withDescription(this, "bufferWithTimeOrCount", delay, count, 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() { + if (!this.scheduled) { + this.scheduled = true; + return delay((function(_this) { + return function() { + return _this.flush(); + }; + })(this)); + } + } + }; + reply = Bacon.more; + if (!isFunction(delay)) { + delayMs = delay; + delay = function(f) { + return Bacon.scheduler.setTimeout(f, delayMs); + }; + } + return withDescription(this, "buffer", 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; + assertEventStream(right); + left = this; + return new EventStream(describe(left, "merge", right), function(sink) { + var ends, smartSink; + ends = 0; + smartSink = function(obs) { + return function(unsubBoth) { + return obs.subscribeInternal(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; + } + }); + }; + }; + return compositeUnsubscribe(smartSink(left), smartSink(right)); + }); + }; + + EventStream.prototype.toProperty = function(initValue) { + if (arguments.length === 0) { + initValue = None; + } + return withDescription(this, "toProperty", initValue, this.scan(initValue, latterF, true)); + }; + + EventStream.prototype.toEventStream = function() { + return this; + }; + + EventStream.prototype.sampledBy = function(sampler, combinator) { + return withDescription(this, "sampledBy", sampler, combinator, this.toProperty().sampledBy(sampler, combinator)); + }; + + EventStream.prototype.concat = function(right) { + var left; + left = this; + return new EventStream(describe(left, "concat", right), function(sink) { + var unsubLeft, unsubRight; + unsubRight = nop; + unsubLeft = left.subscribeInternal(function(e) { + if (e.isEnd()) { + return unsubRight = right.subscribeInternal(sink); + } else { + return sink(e); + } + }); + return function() { + unsubLeft(); + return unsubRight(); + }; + }); + }; + + EventStream.prototype.takeUntil = function(stopper) { + var endMarker; + endMarker = {}; + return withDescription(this, "takeUntil", stopper, Bacon.groupSimultaneous(this.mapEnd(endMarker), stopper.skipErrors()).withHandler(function(event) { + var data, reply, value, _i, _len, _ref1; + if (!event.hasValue()) { + return this.push(event); + } else { + _ref1 = event.value(), data = _ref1[0], stopper = _ref1[1]; + if (stopper.length) { + return this.push(end()); + } else { + reply = Bacon.more; + for (_i = 0, _len = data.length; _i < _len; _i++) { + value = data[_i]; + if (value === endMarker) { + reply = this.push(end()); + } else { + reply = this.push(next(value)); + } + } + return reply; + } + } + })); + }; + + EventStream.prototype.skipUntil = function(starter) { + var started; + started = starter.take(1).map(true).toProperty(false); + return withDescription(this, "skipUntil", starter, this.filter(started)); + }; + + EventStream.prototype.skipWhile = function() { + var args, f, ok; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + ok = false; + return convertArgsToFunction(this, f, args, function(f) { + return withDescription(this, "skipWhile", f, this.withHandler(function(event) { + if (ok || !event.hasValue() || !f(event.value())) { + if (event.hasValue()) { + ok = true; + } + return this.push(event); + } else { + return Bacon.more; + } + })); + }); + }; + + EventStream.prototype.startWith = function(seed) { + return withDescription(this, "startWith", seed, Bacon.once(seed).concat(this)); + }; + + EventStream.prototype.withHandler = function(handler) { + var dispatcher; + dispatcher = new Dispatcher(this.subscribeInternal, handler); + return new EventStream(describe(this, "withHandler", handler), dispatcher.subscribe); + }; + + return EventStream; + + })(Observable); + + Property = (function(_super) { + __extends(Property, _super); + + function Property(desc, 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); + if (isFunction(desc)) { + handler = subscribe; + subscribe = desc; + desc = []; + } + Property.__super__.constructor.call(this, desc); + assertFunction(subscribe); + if (handler === true) { + this.subscribeInternal = subscribe; + } else { + this.subscribeInternal = new PropertyDispatcher(this, subscribe, handler).subscribe; + } + this.sampledBy = (function(_this) { + return function(sampler, combinator) { + var lazy, result, samplerSource, stream, thisSource; + if (combinator != null) { + combinator = toCombinator(combinator); + } else { + lazy = true; + combinator = function(f) { + return f(); + }; + } + thisSource = new Source(_this, false, false, _this.subscribeInternal, lazy); + samplerSource = new Source(sampler, true, false, sampler.subscribeInternal, lazy); + stream = Bacon.when([thisSource, samplerSource], combinator); + result = sampler instanceof Property ? stream.toProperty() : stream; + return withDescription(_this, "sampledBy", sampler, combinator, result); + }; + })(this); + this.subscribe = UpdateBarrier.wrappedSubscribe(this); + registerObs(this); + } + + Property.prototype.sample = function(interval) { + return withDescription(this, "sample", interval, this.sampledBy(Bacon.interval(interval, {}))); + }; + + Property.prototype.changes = function() { + return new EventStream(describe(this, "changes"), (function(_this) { + return function(sink) { + return _this.subscribeInternal(function(event) { + if (!event.isInitial()) { + return sink(event); + } + }); + }; + })(this)); + }; + + Property.prototype.withHandler = function(handler) { + return new Property(describe(this, "withHandler", handler), this.subscribeInternal, handler); + }; + + Property.prototype.toProperty = function() { + assertNoArguments(arguments); + return this; + }; + + Property.prototype.toEventStream = function() { + return new EventStream(describe(this, "toEventStream"), (function(_this) { + return function(sink) { + return _this.subscribeInternal(function(event) { + if (event.isInitial()) { + event = event.toNext(); + } + return sink(event); + }); + }; + })(this)); + }; + + Property.prototype.and = function(other) { + return withDescription(this, "and", other, this.combine(other, function(x, y) { + return x && y; + })); + }; + + Property.prototype.or = function(other) { + return withDescription(this, "or", other, this.combine(other, function(x, y) { + return x || y; + })); + }; + + Property.prototype.delay = function(delay) { + return this.delayChanges("delay", delay, function(changes) { + return changes.delay(delay); + }); + }; + + Property.prototype.debounce = function(delay) { + return this.delayChanges("debounce", delay, function(changes) { + return changes.debounce(delay); + }); + }; + + Property.prototype.throttle = function(delay) { + return this.delayChanges("throttle", delay, function(changes) { + return changes.throttle(delay); + }); + }; + + Property.prototype.delayChanges = function() { + var desc, f, _i; + desc = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), f = arguments[_i++]; + return withDescription.apply(null, [this].concat(__slice.call(desc), [addPropertyInitValueToStream(this, f(this.changes()))])); + }; + + Property.prototype.takeUntil = function(stopper) { + var changes; + changes = this.changes().takeUntil(stopper); + return withDescription(this, "takeUntil", stopper, addPropertyInitValueToStream(this, changes)); + }; + + Property.prototype.startWith = function(value) { + return withDescription(this, "startWith", value, this.scan(value, function(prev, next) { + return next; + })); + }; + + return Property; + + })(Observable); + + convertArgsToFunction = function(obs, f, args, method) { + var sampled; + if (f instanceof Property) { + sampled = f.sampledBy(obs, function(p, s) { + return [p, s]; + }); + return method.apply(sampled, [ + 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 method.apply(obs, [f]); + } + }; + + addPropertyInitValueToStream = function(property, stream) { + var justInitValue; + justInitValue = new EventStream(describe(property, "justInitValue"), function(sink) { + var unsub, value; + value = null; + unsub = property.subscribeInternal(function(event) { + if (event.hasValue()) { + value = event; + } + return Bacon.noMore; + }); + UpdateBarrier.whenDoneWith(justInitValue, function() { + if (value != null) { + sink(value); + } + return sink(end()); + }); + return unsub; + }); + return justInitValue.concat(stream).toProperty(); + }; + + Dispatcher = (function() { + function Dispatcher(subscribe, handleEvent) { + var done, ended, prevError, pushIt, pushing, queue, removeSub, subscriptions, unsubscribeFromSource, waiters; + 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() { + var w, ws, _i, _len, _results; + if (waiters != null) { + ws = waiters; + waiters = null; + _results = []; + for (_i = 0, _len = ws.length; _i < _len; _i++) { + w = ws[_i]; + _results.push(w()); + } + return _results; + } + }; + pushIt = 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; + 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 { + unsubscribeFromSource(); + return Bacon.noMore; + } + } else { + queue = (queue || []).concat([event]); + return Bacon.more; + } + }; + this.push = (function(_this) { + return function(event) { + return UpdateBarrier.inTransaction(event, _this, pushIt, [event]); + }; + })(this); + if (handleEvent == null) { + handleEvent = function(event) { + return this.push(event); + }; + } + this.handleEvent = (function(_this) { + return function(event) { + if (event.isEnd()) { + ended = true; + } + return handleEvent.apply(_this, [event]); + }; + })(this); + this.subscribe = (function(_this) { + return function(sink) { + var subscription, unsubSrc; + if (ended) { + sink(end()); + return nop; + } else { + assertFunction(sink); + subscription = { + sink: sink + }; + subscriptions = subscriptions.concat(subscription); + if (subscriptions.length === 1) { + unsubSrc = subscribe(_this.handleEvent); + unsubscribeFromSource = function() { + unsubSrc(); + return unsubscribeFromSource = nop; + }; + } + assertFunction(unsubscribeFromSource); + return function() { + removeSub(subscription); + if (!_this.hasSubscribers()) { + return unsubscribeFromSource(); + } + }; + } + }; + })(this); + } + + return Dispatcher; + + })(); + + PropertyDispatcher = (function(_super) { + __extends(PropertyDispatcher, _super); + + function PropertyDispatcher(p, subscribe, handleEvent) { + var current, currentValueRootId, ended, push; + PropertyDispatcher.__super__.constructor.call(this, subscribe, handleEvent); + current = None; + currentValueRootId = void 0; + push = this.push; + subscribe = this.subscribe; + ended = false; + this.push = (function(_this) { + return function(event) { + if (event.isEnd()) { + ended = true; + } + if (event.hasValue()) { + current = new Some(event); + currentValueRootId = UpdateBarrier.currentEventId(); + } + return push.apply(_this, [event]); + }; + })(this); + this.subscribe = (function(_this) { + return function(sink) { + var dispatchingId, initSent, maybeSubSource, reply, valId; + initSent = false; + reply = Bacon.more; + maybeSubSource = function() { + if (reply === Bacon.noMore) { + return nop; + } else if (ended) { + sink(end()); + return nop; + } else { + return subscribe.apply(this, [sink]); + } + }; + if (current.isDefined && (_this.hasSubscribers() || ended)) { + dispatchingId = UpdateBarrier.currentEventId(); + valId = currentValueRootId; + if (!ended && valId && dispatchingId && dispatchingId !== valId) { + UpdateBarrier.whenDoneWith(p, function() { + if (currentValueRootId === valId) { + return sink(initial(current.get().value())); + } + }); + return maybeSubSource(); + } else { + UpdateBarrier.inTransaction(void 0, _this, (function() { + return reply = sink(initial(current.get().value())); + }), []); + return maybeSubSource(); + } + } else { + return maybeSubSource(); + } + }; + })(this); + } + + return PropertyDispatcher; + + })(Dispatcher); + + Bus = (function(_super) { + __extends(Bus, _super); + + function Bus() { + var ended, guardedSink, sink, subscribeAll, subscribeInput, subscriptions, unsubAll, unsubscribeInput; + sink = void 0; + subscriptions = []; + ended = false; + guardedSink = (function(_this) { + return function(input) { + return function(event) { + if (event.isEnd()) { + unsubscribeInput(input); + return Bacon.noMore; + } else { + if (event.hasValue()) { + event.value(); + } + return sink(event); + } + }; + }; + })(this); + 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.subscribeInternal(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(_this) { + return function(newSink) { + var subscription, _i, _len, _ref1; + sink = newSink; + _ref1 = cloneArray(subscriptions); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + subscription = _ref1[_i]; + subscribeInput(subscription); + } + return unsubAll; + }; + })(this); + Bus.__super__.constructor.call(this, describe(Bacon, "Bus"), subscribeAll); + this.plug = (function(_this) { + return function(input) { + var sub; + if (ended) { + return; + } + sub = { + input: input + }; + subscriptions.push(sub); + if ((sink != null)) { + subscribeInput(sub); + } + return function() { + return unsubscribeInput(input); + }; + }; + })(this); + this.push = (function(_this) { + return function(value) { + return typeof sink === "function" ? sink(next(value)) : void 0; + }; + })(this); + this.error = (function(_this) { + return function(error) { + return typeof sink === "function" ? sink(new Error(error)) : void 0; + }; + })(this); + this.end = (function(_this) { + return function() { + ended = true; + unsubAll(); + return typeof sink === "function" ? sink(end()) : void 0; + }; + })(this); + } + + return Bus; + + })(EventStream); + + Source = (function() { + function Source(obs, sync, consume, subscribe, lazy, queue) { + var invoke; + this.obs = obs; + this.sync = sync; + this.subscribe = subscribe; + if (lazy == null) { + lazy = false; + } + if (queue == null) { + queue = []; + } + invoke = lazy ? _.id : function(f) { + return f(); + }; + if (this.subscribe == null) { + this.subscribe = obs.subscribeInternal; + } + this.markEnded = function() { + return this.ended = true; + }; + this.toString = this.obs.toString; + if (consume) { + this.consume = function() { + return invoke(queue.shift()); + }; + this.push = function(x) { + return queue.push(x); + }; + this.mayHave = function(c) { + return !this.ended || queue.length >= c; + }; + this.hasAtLeast = function(c) { + return queue.length >= c; + }; + this.flatten = false; + } else { + this.consume = function() { + return invoke(queue[0]); + }; + this.push = function(x) { + return queue = [x]; + }; + this.mayHave = function() { + return true; + }; + this.hasAtLeast = function() { + return queue.length; + }; + this.flatten = true; + } + } + + return Source; + + })(); + + BufferingSource = (function(_super) { + __extends(BufferingSource, _super); + + function BufferingSource(obs) { + var queue; + this.obs = obs; + queue = []; + BufferingSource.__super__.constructor.call(this, this.obs, true, false, this.obs.subscribeInternal, false, queue); + this.consume = function() { + var values; + values = queue; + queue = []; + return values; + }; + this.push = function(x) { + return queue.push(x()); + }; + this.hasAtLeast = function() { + return true; + }; + } + + return BufferingSource; + + })(Source); + + Source.fromObservable = function(s) { + if (s instanceof Source) { + return s; + } else if (s instanceof Property) { + return new Source(s, false, false); + } else { + return new Source(s, true, true); + } + }; + + describe = function() { + var args, context, method; + context = arguments[0], method = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; + if ((context || method) instanceof Desc) { + return context || method; + } else { + return new Desc(context, method, args); + } + }; + + Desc = (function() { + function Desc(context, method, args) { + var collectDeps, dependsOn, findDeps, flatDeps; + findDeps = function(x) { + if (isArray(x)) { + return _.flatMap(findDeps, x); + } else if (isObservable(x)) { + return [x]; + } else if (x instanceof Source) { + return [x.obs]; + } else { + return []; + } + }; + flatDeps = null; + collectDeps = function(o) { + var dep, deps, _i, _len, _results; + deps = o.internalDeps(); + _results = []; + for (_i = 0, _len = deps.length; _i < _len; _i++) { + dep = deps[_i]; + flatDeps[dep.id] = true; + _results.push(collectDeps(dep)); + } + return _results; + }; + dependsOn = function(b) { + if (flatDeps == null) { + flatDeps = {}; + collectDeps(this); + } + return flatDeps[b.id]; + }; + this.apply = function(obs) { + var deps; + deps = _.cached((function() { + return findDeps([context].concat(args)); + })); + obs.internalDeps = obs.internalDeps || deps; + obs.dependsOn = dependsOn; + obs.deps = deps; + obs.toString = function() { + return _.toString(context) + "." + _.toString(method) + "(" + _.map(_.toString, args) + ")"; + }; + obs.inspect = function() { + return obs.toString(); + }; + obs.desc = function() { + return { + context: context, + method: method, + args: args + }; + }; + return obs; + }; + } + + return Desc; + + })(); + + withDescription = function() { + var desc, obs, _i; + desc = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), obs = arguments[_i++]; + return describe.apply(null, desc).apply(obs); + }; + + Bacon.when = function() { + var f, i, index, ix, len, needsBarrier, pat, patSources, pats, patterns, resultStream, s, sources, usage, _i, _j, _len, _len1, _ref1; + patterns = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (patterns.length === 0) { + return Bacon.never(); + } + len = patterns.length; + usage = "when: expecting arguments in the form (Observable+,function)+"; + assert(usage, len % 2 === 0); + sources = []; + pats = []; + i = 0; + while (i < len) { + patSources = _.toArray(patterns[i]); + f = patterns[i + 1]; + pat = { + f: (isFunction(f) ? f : (function() { + return f; + })), + ixs: [] + }; + for (_i = 0, _len = patSources.length; _i < _len; _i++) { + s = patSources[_i]; + assert(isObservable(s), usage); + index = _.indexOf(sources, s); + if (index < 0) { + sources.push(s); + index = sources.length - 1; + } + _ref1 = pat.ixs; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + ix = _ref1[_j]; + if (ix.index === index) { + ix.count++; + } + } + pat.ixs.push({ + index: index, + count: 1 + }); + } + if (patSources.length > 0) { + pats.push(pat); + } + i = i + 2; + } + if (!sources.length) { + return Bacon.never(); + } + sources = _.map(Source.fromObservable, sources); + needsBarrier = (_.any(sources, function(s) { + return s.flatten; + })) && (containsDuplicateDeps(_.map((function(s) { + return s.obs; + }), sources))); + return resultStream = new EventStream(describe.apply(null, [Bacon, "when"].concat(__slice.call(patterns))), function(sink) { + var cannotMatch, cannotSync, ends, match, nonFlattened, part, triggers; + triggers = []; + ends = false; + match = function(p) { + var _k, _len2, _ref2; + _ref2 = p.ixs; + for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { + i = _ref2[_k]; + if (!sources[i.index].hasAtLeast(i.count)) { + return false; + } + } + return true; + }; + cannotSync = function(source) { + return !source.sync || source.ended; + }; + cannotMatch = function(p) { + var _k, _len2, _ref2; + _ref2 = p.ixs; + for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { + i = _ref2[_k]; + if (!sources[i.index].mayHave(i.count)) { + return true; + } + } + }; + nonFlattened = function(trigger) { + return !trigger.source.flatten; + }; + part = function(source) { + return function(unsubAll) { + var flush, flushLater, flushWhileTriggers; + flushLater = function() { + return UpdateBarrier.whenDoneWith(resultStream, flush); + }; + flushWhileTriggers = function() { + var p, reply, trigger, val, _k, _len2; + if (triggers.length > 0) { + reply = Bacon.more; + trigger = triggers.pop(); + for (_k = 0, _len2 = pats.length; _k < _len2; _k++) { + p = pats[_k]; + if (match(p)) { + val = function() { + return p.f.apply(p, (function() { + var _l, _len3, _ref2, _results; + _ref2 = p.ixs; + _results = []; + for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) { + i = _ref2[_l]; + _results.push(sources[i.index].consume()); + } + return _results; + })()); + }; + reply = sink(trigger.e.apply(val)); + if (triggers.length && needsBarrier) { + triggers = _.filter(nonFlattened, triggers); + } + if (reply === Bacon.noMore) { + return reply; + } else { + return flushWhileTriggers(); + } + } + } + } else { + return Bacon.more; + } + }; + flush = function() { + var reply; + reply = flushWhileTriggers(); + if (ends) { + ends = false; + if (_.all(sources, cannotSync) || _.all(pats, cannotMatch)) { + reply = Bacon.noMore; + sink(end()); + } + } + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply; + }; + return source.subscribe(function(e) { + var reply; + if (e.isEnd()) { + ends = true; + source.markEnded(); + flushLater(); + } else if (e.isError()) { + reply = sink(e); + } else { + source.push(e.value); + if (source.sync) { + triggers.push({ + source: source, + e: e + }); + if (needsBarrier) { + flushLater(); + } else { + flush(); + } + } + } + if (reply === Bacon.noMore) { + unsubAll(); + } + return reply || Bacon.more; + }); + }; + }; + return compositeUnsubscribe.apply(null, (function() { + var _k, _len2, _results; + _results = []; + for (_k = 0, _len2 = sources.length; _k < _len2; _k++) { + s = sources[_k]; + _results.push(part(s)); + } + return _results; + })()); + }); + }; + + containsDuplicateDeps = function(observables, state) { + var checkObservable; + if (state == null) { + state = []; + } + checkObservable = function(obs) { + var deps; + if (Bacon._.contains(state, obs)) { + return true; + } else { + deps = obs.internalDeps(); + if (deps.length) { + state.push(obs); + return Bacon._.any(deps, checkObservable); + } else { + state.push(obs); + return false; + } + } + }; + return Bacon._.any(observables, checkObservable); + }; + + Bacon.update = function() { + var i, initial, lateBindFirst, patterns; + initial = arguments[0], patterns = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + lateBindFirst = function(f) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return function(i) { + return f.apply(null, [i].concat(args)); + }; + }; + }; + i = patterns.length - 1; + while (i > 0) { + if (!(patterns[i] instanceof Function)) { + patterns[i] = (function(x) { + return function() { + return x; + }; + })(patterns[i]); + } + patterns[i] = lateBindFirst(patterns[i]); + i = i - 2; + } + return withDescription.apply(null, [Bacon, "update", initial].concat(__slice.call(patterns), [Bacon.when.apply(Bacon, patterns).scan(initial, (function(x, f) { + return f(x); + }))])); + }; + + compositeUnsubscribe = function() { + var ss; + ss = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return new CompositeUnsubscribe(ss).unsubscribe; + }; + + CompositeUnsubscribe = (function() { + function CompositeUnsubscribe(ss) { + var s, _i, _len; + if (ss == null) { + ss = []; + } + this.empty = __bind(this.empty, this); + this.count = __bind(this.count, this); + this.unsubscribe = __bind(this.unsubscribe, this); + this.add = __bind(this.add, this); + this.unsubscribed = false; + this.subscriptions = []; + this.starting = []; + for (_i = 0, _len = ss.length; _i < _len; _i++) { + s = ss[_i]; + this.add(s); + } + } + + CompositeUnsubscribe.prototype.add = function(subscription) { + var ended, unsub, unsubMe; + if (this.unsubscribed) { + return; + } + ended = false; + unsub = nop; + this.starting.push(subscription); + unsubMe = (function(_this) { + return function() { + if (_this.unsubscribed) { + return; + } + ended = true; + _this.remove(unsub); + return _.remove(subscription, _this.starting); + }; + })(this); + unsub = subscription(this.unsubscribe, unsubMe); + if (!(this.unsubscribed || ended)) { + this.subscriptions.push(unsub); + } + _.remove(subscription, this.starting); + return unsub; + }; + + CompositeUnsubscribe.prototype.remove = function(unsub) { + if (this.unsubscribed) { + return; + } + if ((_.remove(unsub, this.subscriptions)) !== void 0) { + return unsub(); + } + }; + + CompositeUnsubscribe.prototype.unsubscribe = function() { + var s, _i, _len, _ref1; + if (this.unsubscribed) { + return; + } + this.unsubscribed = true; + _ref1 = this.subscriptions; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + s = _ref1[_i]; + s(); + } + this.subscriptions = []; + return this.starting = []; + }; + + CompositeUnsubscribe.prototype.count = function() { + if (this.unsubscribed) { + return 0; + } + return this.subscriptions.length + this.starting.length; + }; + + CompositeUnsubscribe.prototype.empty = function() { + return this.count() === 0; + }; + + return CompositeUnsubscribe; + + })(); + + Bacon.CompositeUnsubscribe = CompositeUnsubscribe; + + 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]; + }; + + Some.prototype.inspect = function() { + return "Some(" + this.value + ")"; + }; + + Some.prototype.toString = function() { + return this.inspect(); + }; + + return Some; + + })(); + + None = { + getOrElse: function(value) { + return value; + }, + filter: function() { + return None; + }, + map: function() { + return None; + }, + forEach: function() {}, + isDefined: false, + toArray: function() { + return []; + }, + inspect: function() { + return "None"; + }, + toString: function() { + return this.inspect(); + } + }; + + UpdateBarrier = (function() { + var afterTransaction, afters, currentEventId, findIndependent, flush, inTransaction, independent, rootEvent, waiters, whenDoneWith, wrappedSubscribe; + rootEvent = void 0; + waiters = []; + afters = []; + afterTransaction = function(f) { + if (rootEvent) { + return afters.push(f); + } else { + return f(); + } + }; + independent = function(waiter) { + return !_.any(waiters, (function(other) { + return waiter.obs.dependsOn(other.obs); + })); + }; + whenDoneWith = function(obs, f) { + if (rootEvent) { + return waiters.push({ + obs: obs, + f: f + }); + } else { + return f(); + } + }; + findIndependent = function() { + while (!independent(waiters[0])) { + waiters.push(waiters.splice(0, 1)[0]); + } + return waiters.splice(0, 1)[0]; + }; + flush = function() { + var _results; + _results = []; + while (waiters.length) { + _results.push(findIndependent().f()); + } + return _results; + }; + inTransaction = function(event, context, f, args) { + var result; + if (rootEvent) { + return f.apply(context, args); + } else { + rootEvent = event; + try { + result = f.apply(context, args); + flush(); + } finally { + rootEvent = void 0; + while (afters.length) { + f = afters.splice(0, 1)[0]; + f(); + } + } + return result; + } + }; + currentEventId = function() { + if (rootEvent) { + return rootEvent.id; + } else { + return void 0; + } + }; + wrappedSubscribe = function(obs) { + return function(sink) { + var doUnsub, unsub, unsubd; + unsubd = false; + doUnsub = function() {}; + unsub = function() { + unsubd = true; + return doUnsub(); + }; + if (!unsubd) { + doUnsub = obs.subscribeInternal(function(event) { + return afterTransaction(function() { + var reply; + if (!unsubd) { + reply = sink(event); + if (reply === Bacon.noMore) { + return unsub(); + } + } + }); + }); + } + return unsub; + }; + }; + return { + whenDoneWith: whenDoneWith, + inTransaction: inTransaction, + currentEventId: currentEventId, + wrappedSubscribe: wrappedSubscribe + }; + })(); + + 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() {}; + + latterF = 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); + }; + + assert = function(message, condition) { + if (!condition) { + throw message; + } + }; + + assertEventStream = function(event) { + if (!(event instanceof EventStream)) { + throw "not an EventStream : " + event; + } + }; + + assertFunction = function(f) { + return assert("not a function : " + f, isFunction(f)); + }; + + isFunction = function(f) { + return typeof f === "function"; + }; + + isArray = function(xs) { + return xs instanceof Array; + }; + + isObservable = function(x) { + return x instanceof Observable; + }; + + assertArray = function(xs) { + if (!isArray(xs)) { + throw "not an array : " + xs; + } + }; + + assertNoArguments = function(args) { + return assert("no arguments supported", args.length === 0); + }; + + assertString = function(x) { + if (typeof x !== "string") { + throw "not a string : " + x; + } + }; + + 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(args) { + if (args.length === 1 && isObservable(args[0])) { + return _.always(args[0]); + } else { + return makeFunctionArgs(args); + } + }; + + makeFunctionArgs = function(args) { + args = Array.prototype.slice.call(args); + return makeFunction_.apply(null, args); + }; + + makeFunction_ = withMethodCallSupport(function() { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (isFunction(f)) { + if (args.length) { + return partiallyApplied(f, args); + } else { + return f; + } + } else if (isFieldKey(f)) { + return toFieldExtractor(f, args); + } else { + return _.always(f); + } + }); + + makeFunction = function(f, args) { + return makeFunction_.apply(null, [f].concat(__slice.call(args))); + }; + + makeObservable = function(x) { + if (isObservable(x)) { + return x; + } else { + return Bacon.once(x); + } + }; + + 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); + } + }; + + _ = { + 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; + }, + indexWhere: function(xs, f) { + var i, y, _i, _len; + for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) { + y = xs[i]; + if (f(y)) { + return i; + } + } + return -1; + }, + head: function(xs) { + return xs[0]; + }, + always: function(x) { + return function() { + return x; + }; + }, + negate: function(f) { + return function(x) { + return !f(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 (isArray(xs)) { + 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, f) { + var x, _i, _len; + if (f == null) { + f = _.id; + } + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (!f(x)) { + return false; + } + } + return true; + }, + any: function(xs, f) { + var x, _i, _len; + if (f == null) { + f = _.id; + } + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + if (f(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); + } + }, + fold: function(xs, seed, f) { + var x, _i, _len; + for (_i = 0, _len = xs.length; _i < _len; _i++) { + x = xs[_i]; + seed = f(seed, x); + } + return seed; + }, + flatMap: function(f, xs) { + return _.fold(xs, [], (function(ys, x) { + return ys.concat(f(x)); + })); + }, + cached: function(f) { + var value; + value = None; + return function() { + if (value === None) { + value = f(); + f = null; + } + return value; + }; + }, + toString: function(obj) { + var ex, internals, key, value; + try { + recursionDepth++; + if (obj == null) { + return "undefined"; + } else if (isFunction(obj)) { + return "function"; + } else if (isArray(obj)) { + if (recursionDepth > 5) { + return "[..]"; + } + return "[" + _.map(_.toString, obj).toString() + "]"; + } else if (((obj != null ? obj.toString : void 0) != null) && obj.toString !== Object.prototype.toString) { + return obj.toString(); + } else if (typeof obj === "object") { + if (recursionDepth > 5) { + return "{..}"; + } + internals = (function() { + var _results; + _results = []; + for (key in obj) { + if (!__hasProp.call(obj, key)) continue; + value = (function() { + try { + return obj[key]; + } catch (_error) { + ex = _error; + return ex; + } + })(); + _results.push(_.toString(key) + ":" + _.toString(value)); + } + return _results; + })(); + return "{" + internals + "}"; + } else { + return obj; + } + } finally { + recursionDepth--; + } + } + }; + + recursionDepth = 0; + + 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(); + } + }; + + if (typeof module !== "undefined" && module !== null) { + module.exports = Bacon; + Bacon.Bacon = Bacon; + } else { + if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) { + define([], function() { + return Bacon; + }); + } + this.Bacon = Bacon; + } + +}).call(this); diff --git a/ajax/libs/bacon.js/0.7.7/bacon.min.js b/ajax/libs/bacon.js/0.7.7/bacon.min.js new file mode 100644 index 000000000..4a6cbb750 --- /dev/null +++ b/ajax/libs/bacon.js/0.7.7/bacon.min.js @@ -0,0 +1,2 @@ +(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,ab,bb,cb,db,eb=[].slice,fb={}.hasOwnProperty,gb=function(a,b){function c(){this.constructor=a}for(var d in b)fb.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},hb=function(a,b){return function(){return a.apply(b,arguments)}};a={toString:function(){return"Bacon"}},a.version="0.7.7",a.fromBinder=function(b,c){return null==c&&(c=cb.id),new j(y(a,"fromBinder",b,c),function(d){var e;return e=b(function(){var b,f,g,h,j,k;for(b=1<=arguments.length?eb.call(arguments,0):[],h=c.apply(null,b),F(h)&&cb.last(h)instanceof i||(h=[h]),g=a.more,j=0,k=h.length;k>j;j++)if(f=h[j],g=d(f=X(f)),g===a.noMore||f.isEnd())return null!=e?e():a.scheduler.setTimeout(function(){return e()},0),g;return g})})},a.$={asEventStream:function(b,c,d){var e;return H(c)&&(e=[c,null],d=e[0],c=e[1]),ab(this,"asEventStream",b,a.fromBinder(function(a){return function(d){return a.on(b,c,d),function(){return a.off(b,c,d)}}}(this),d))}},null!=(db="undefined"!=typeof jQuery&&null!==jQuery?jQuery:"undefined"!=typeof Zepto&&null!==Zepto?Zepto:null)&&(db.fn.asEventStream=a.$.asEventStream),a.fromEventTarget=function(b,c,d){var e,f,g,h,i,j;return e=null!=(g=b.addEventListener)?g:null!=(h=b.addListener)?h:b.bind,f=null!=(i=b.removeEventListener)?i:null!=(j=b.removeListener)?j:b.unbind,ab(a,"fromEventTarget",b,c,a.fromBinder(function(a){return e.call(b,c,a),function(){return f.call(b,c,a)}},d))},a.fromPromise=function(b,c){return ab(a,"fromPromise",b,a.fromBinder(function(a){return b.then(a,function(b){return a(new h(b))}),function(){return c?"function"==typeof b.abort?b.abort():void 0:void 0}},function(a){return[a,z()]}))},a.noMore=[""],a.more=[""],a.later=function(b,c){return ab(a,"later",b,c,a.sequentially(b,[c]))},a.sequentially=function(b,c){var d;return d=0,ab(a,"sequentially",b,c,a.fromPoll(b,function(){var a;return a=c[d++],dc;c++)b=V[c],e.push(b(a));return e}finally{delete U.running}},bb=function(a){return function(){var b,c,d,e;return d=arguments[0],b=2<=arguments.length?eb.call(arguments,1):[],"object"==typeof d&&b.length&&(c=d,e=b[0],d=function(){return c[e].apply(c,arguments)},b=b.slice(1)),a.apply(null,[d].concat(eb.call(b)))}},K=function(b,c){return bb(function(){var d,e,f;return e=arguments[0],d=2<=arguments.length?eb.call(arguments,1):[],f=S(c,[function(a,b){return e.apply(null,eb.call(a).concat([b]))}]),ab.apply(null,[a,b,e].concat(eb.call(d),[a.combineAsArray(d).flatMap(f)]))})},a.fromCallback=K("fromCallback",function(){var b,c;return c=arguments[0],b=2<=arguments.length?eb.call(arguments,1):[],a.fromBinder(function(a){return L(c,b)(a),R},function(a){return[a,z()]})}),a.fromNodeCallback=K("fromNodeCallback",function(){var b,c;return c=arguments[0],b=2<=arguments.length?eb.call(arguments,1):[],a.fromBinder(function(a){return L(c,b)(a),R},function(a,b){return a?[new h(a),z()]:[b,z()]})}),a.fromPoll=function(b,c){return ab(a,"fromPoll",b,c,a.fromBinder(function(c){var d;return d=a.scheduler.setInterval(c,b),function(){return a.scheduler.clearInterval(d)}},c))},a.interval=function(b,c){return null==c&&(c={}),ab(a,"interval",b,c,a.fromPoll(b,function(){return Q(c)}))},a.constant=function(b){return new o(y(a,"constant",b),function(a){return a(E(b)),a(z()),R})},a.never=function(){return ab(a,"never",a.fromArray([]))},a.once=function(b){return ab(a,"once",b,a.fromArray([b]))},a.fromArray=function(b){return b=u(b),new j(y(a,"fromArray",b),function(c){var d,e;return e=!1,d=function(){var f,g;return cb.empty(b)?c(z()):(g=b.splice(0,1)[0],f=c(X(g)),f===a.noMore||e?void 0:d())},d(),function(){return e=!0}})},a.mergeAll=function(){var b;return b=1<=arguments.length?eb.call(arguments,0):[],F(b[0])&&(b=b[0]),ab.apply(null,[a,"mergeAll"].concat(eb.call(b),[cb.fold(b,a.never(),function(a,b){return a.merge(b)})]))},a.zipAsArray=function(){var b;return b=1<=arguments.length?eb.call(arguments,0):[],F(b[0])&&(b=b[0]),ab.apply(null,[a,"zipAsArray"].concat(eb.call(b),[a.zipWith(b,function(){var a;return a=1<=arguments.length?eb.call(arguments,0):[]})]))},a.zipWith=function(){var b,c,d;return b=arguments[0],c=2<=arguments.length?eb.call(arguments,1):[],H(b)||(d=[b,c[0]],c=d[0],b=d[1]),c=cb.map(function(a){return a.toEventStream()},c),ab.apply(null,[a,"zipWith",b].concat(eb.call(c),[a.when(c,b)]))},a.groupSimultaneous=function(){var c,d,e;return e=1<=arguments.length?eb.call(arguments,0):[],1===e.length&&F(e[0])&&(e=e[0]),d=function(){var a,d,f;for(f=[],a=0,d=e.length;d>a;a++)c=e[a],f.push(new b(c));return f}(),ab.apply(null,[a,"groupSimultaneous"].concat(eb.call(e),[a.when(d,function(){var a;return a=1<=arguments.length?eb.call(arguments,0):[]})]))},a.combineAsArray=function(){var b,c,d,e,f,g,h;for(f=1<=arguments.length?eb.call(arguments,0):[],1===f.length&&F(f[0])&&(f=f[0]),b=g=0,h=f.length;h>g;b=++g)e=f[b],I(e)||(f[b]=a.constant(e));return f.length?(d=function(){var a,b,d;for(d=[],a=0,b=f.length;b>a;a++)c=f[a],d.push(new r(c,!0,!1,c.subscribeInternal));return d}(),ab.apply(null,[a,"combineAsArray"].concat(eb.call(f),[a.when(d,function(){var a;return a=1<=arguments.length?eb.call(arguments,0):[]}).toProperty()]))):a.constant([])},a.onValues=function(){var b,c,d;return c=2<=arguments.length?eb.call(arguments,0,d=arguments.length-1):(d=0,[]),b=arguments[d++],a.combineAsArray(c).onValues(b)},a.combineWith=function(){var b,c;return b=arguments[0],c=2<=arguments.length?eb.call(arguments,1):[],ab.apply(null,[a,"combineWith",b].concat(eb.call(c),[a.combineAsArray(c).map(function(a){return b.apply(null,a)})]))},a.combineTemplate=function(b){var c,d,e,f,g,h,i,j,k,l;return i=[],l=[],h=function(a){return a[a.length-1]},k=function(a,b,c){return h(a)[b]=c},c=function(a,b){return function(c,d){return k(c,a,d[b])}},g=function(a,b){return function(c){return k(c,a,b)}},j=function(a){return F(a)?[]:{}},e=function(a,b){var d,e;return I(b)?(l.push(b),i.push(c(a,l.length-1))):b!==Object(b)||"function"==typeof b||b instanceof RegExp||b instanceof Date?i.push(g(a,b)):(e=function(a){return function(c){var d;return d=j(b),k(c,a,d),c.push(d)}},d=function(a){return a.pop()},i.push(e(a)),f(b),i.push(d))},f=function(a){return cb.each(a,e)},f(b),d=function(a){var c,d,e,f,g;for(e=j(b),c=[e],f=0,g=i.length;g>f;f++)(d=i[f])(c,a);return e},ab(a,"combineTemplate",b,a.combineAsArray(l).map(d))},A=0,i=function(){function a(){this.id=++A}return a.prototype.isEvent=function(){return!0},a.prototype.isEnd=function(){return!1},a.prototype.isInitial=function(){return!1},a.prototype.isNext=function(){return!1},a.prototype.isError=function(){return!1},a.prototype.hasValue=function(){return!1},a.prototype.filter=function(){return!0},a.prototype.inspect=function(){return this.toString()},a}(),l=function(a){function b(a){b.__super__.constructor.call(this),this.value=H(a)?cb.cached(a):cb.always(a)}return gb(b,a),b.prototype.isNext=function(){return!0},b.prototype.hasValue=function(){return!0},b.prototype.fmap=function(a){return this.apply(function(b){return function(){return a(b.value())}}(this))},b.prototype.apply=function(a){return new b(a)},b.prototype.filter=function(a){return a(this.value())},b.prototype.toString=function(){return cb.toString(this.value())},b}(i),k=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return gb(b,a),b.prototype.isInitial=function(){return!0},b.prototype.isNext=function(){return!1},b.prototype.apply=function(a){return new b(a)},b.prototype.toNext=function(){return new l(this.value)},b}(l),g=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return gb(b,a),b.prototype.isEnd=function(){return!0},b.prototype.fmap=function(){return this},b.prototype.apply=function(){return this},b.prototype.toString=function(){return""},b}(i),h=function(a){function b(a){this.error=a}return gb(b,a),b.prototype.isError=function(){return!0},b.prototype.fmap=function(){return this},b.prototype.apply=function(){return this},b.prototype.toString=function(){return" "+cb.toString(this.error)},b}(i),D=0,n=function(){function b(a){this.combine=hb(this.combine,this),this.flatMapLatest=hb(this.flatMapLatest,this),this.fold=hb(this.fold,this),this.scan=hb(this.scan,this),this.id=++D,this.assign=this.onValue,ab(a,this)}return b.prototype.onValue=function(){var a;return a=M(arguments),this.subscribe(function(b){return b.hasValue()?a(b.value()):void 0})},b.prototype.onValues=function(a){return this.onValue(function(b){return a.apply(null,b)})},b.prototype.onError=function(){var a;return a=M(arguments),this.subscribe(function(b){return b.isError()?a(b.error):void 0})},b.prototype.onEnd=function(){var a;return a=M(arguments),this.subscribe(function(b){return b.isEnd()?a():void 0})},b.prototype.errors=function(){return ab(this,"errors",this.filter(function(){return!1}))},b.prototype.filter=function(){var b,c;return c=arguments[0],b=2<=arguments.length?eb.call(arguments,1):[],x(this,c,b,function(b){return ab(this,"filter",b,this.withHandler(function(c){return c.filter(b)?this.push(c):a.more}))})},b.prototype.takeWhile=function(){var b,c;return c=arguments[0],b=2<=arguments.length?eb.call(arguments,1):[],x(this,c,b,function(b){return ab(this,"takeWhile",b,this.withHandler(function(c){return c.filter(b)?this.push(c):(this.push(z()),a.noMore)}))})},b.prototype.endOnError=function(){var a,b;return b=arguments[0],a=2<=arguments.length?eb.call(arguments,1):[],null==b&&(b=!0),x(this,b,a,function(a){return ab(this,"endOnError",this.withHandler(function(b){return b.isError()&&a(b.error)?(this.push(b),this.push(z())):this.push(b)}))})},b.prototype.take=function(b){return 0>=b?a.never():ab(this,"take",b,this.withHandler(function(c){return c.hasValue()?(b--,b>0?this.push(c):(0===b&&this.push(c),this.push(z()),a.noMore)):this.push(c)}))},b.prototype.map=function(){var a,b;return b=arguments[0],a=2<=arguments.length?eb.call(arguments,1):[],b instanceof o?b.sampledBy(this,C):x(this,b,a,function(a){return ab(this,"map",a,this.withHandler(function(b){return this.push(b.fmap(a))}))})},b.prototype.mapError=function(){var a;return a=M(arguments),ab(this,"mapError",a,this.withHandler(function(b){return this.push(b.isError()?Q(a(b.error)):b)}))},b.prototype.mapEnd=function(){var b;return b=M(arguments),ab(this,"mapEnd",b,this.withHandler(function(c){return c.isEnd()?(this.push(Q(b(c))),this.push(z()),a.noMore):this.push(c)}))},b.prototype.doAction=function(){var a;return a=M(arguments),ab(this,"doAction",a,this.withHandler(function(b){return b.hasValue()&&a(b.value()),this.push(b)}))},b.prototype.skip=function(b){return ab(this,"skip",b,this.withHandler(function(c){return c.hasValue()?b>0?(b--,a.more):this.push(c):this.push(c)}))},b.prototype.skipDuplicates=function(a){return null==a&&(a=function(a,b){return a===b}),ab(this,"skipDuplicates",this.withStateMachine(m,function(b,c){return c.hasValue()?c.isInitial()||b===m||!a(b.get(),c.value())?[new q(c.value()),[c]]:[b,[]]:[b,[c]]}))},b.prototype.skipErrors=function(){return ab(this,"skipErrors",this.withHandler(function(b){return b.isError()?a.more:this.push(b)}))},b.prototype.withStateMachine=function(b,c){var d;return d=b,ab(this,"withStateMachine",b,c,this.withHandler(function(b){var e,f,g,h,i,j,k;for(e=c(d,b),f=e[0],h=e[1],d=f,i=a.more,j=0,k=h.length;k>j;j++)if(g=h[j],i=this.push(g),i===a.noMore)return i;return i}))},b.prototype.scan=function(b,c,d){var e,f,g,h,i;return f=W(c),c=d?f:function(a,b){return f(a(),b())},e=$(b).map(function(a){return cb.always(a)}),h=this,i=function(b){return function(d){var f,h,i,j;return f=!1,j=R,h=a.more,i=function(){return f?void 0:e.forEach(function(b){return f=!0,h=d(new k(b)),h===a.noMore?(j(),j=R):void 0})},j=b.subscribeInternal(function(b){var g,j;return b.hasValue()?f&&b.isInitial()?a.more:(b.isInitial()||i(),f=!0,j=e.getOrElse(function(){return void 0}),g=cb.cached(function(){return c(j,b.value)}),e=new q(g),d(b.apply(g))):(b.isEnd()&&(h=i()),h!==a.noMore?d(b):void 0)}),s.whenDoneWith(g,i),j}}(this),g=new o(y(this,"scan",b,c),i)},b.prototype.fold=function(a,b){return ab(this,"fold",a,b,this.scan(a,b).sampledBy(this.filter(!1).mapEnd().toProperty()))},b.prototype.zip=function(b,c){return null==c&&(c=Array),ab(this,"zip",b,a.zipWith([this,b],c))},b.prototype.diff=function(a,b){return b=W(b),ab(this,"diff",a,b,this.scan([a],function(a,c){return[c,b(a[0],c)]}).filter(function(a){return 2===a.length}).map(function(a){return a[1]}))},b.prototype.flatMap=function(){return B(this,P(arguments))},b.prototype.flatMapFirst=function(){return B(this,P(arguments),!0)},b.prototype.flatMapLatest=function(){var a,b;return a=P(arguments),b=this.toEventStream(),ab(this,"flatMapLatest",a,b.flatMap(function(){return function(c){return O(a(c)).takeUntil(b)}}(this)))},b.prototype.not=function(){return ab(this,"not",this.map(function(a){return!a}))},b.prototype.log=function(){var a;return a=1<=arguments.length?eb.call(arguments,0):[],this.subscribe(function(b){return"undefined"!=typeof console&&null!==console?"function"==typeof console.log?console.log.apply(console,eb.call(a).concat([b.toString()])):void 0:void 0}),this},b.prototype.slidingWindow=function(a,b){return null==b&&(b=0),ab(this,"slidingWindow",a,b,this.scan([],function(b,c){return b.concat([c]).slice(-a)}).filter(function(a){return a.length>=b}))},b.prototype.combine=function(b,c){var d;return d=W(c),ab(this,"combine",b,c,a.combineAsArray(this,b).map(function(a){return d(a[0],a[1])}))},b.prototype.decode=function(b){return ab(this,"decode",b,this.combine(a.combineTemplate(b),function(a,b){return b[a]}))},b.prototype.awaiting=function(b){return ab(this,"awaiting",b,a.groupSimultaneous(this,b).map(function(a){var b,c;return b=a[0],c=a[1],0===c.length}).toProperty(!1).skipDuplicates())},b.prototype.name=function(a){return this.toString=function(){return a},this},b.prototype.withDescription=function(){return y.apply(null,arguments).apply(this)},b}(),n.prototype.reduce=n.prototype.fold,B=function(b,c,e){return new j(y(b,"flatMap"+(e?"First":""),c),function(f){var g,h;return h=new d,g=function(a){return a(),h.empty()?f(z()):void 0},h.add(function(d,i){return b.subscribeInternal(function(b){var d;return b.isEnd()?g(i):b.isError()?f(b):e&&h.count()>1?a.more:h.unsubscribed?a.noMore:(d=O(c(b.value())),h.add(function(b,c){return d.subscribeInternal(function(d){var e;return d.isEnd()?(g(c),a.noMore):(d instanceof k&&(d=d.toNext()),e=f(d),e===a.noMore&&b(),e)})}))})}),h.unsubscribe})},j=function(b){function c(a,b){this.takeUntil=hb(this.takeUntil,this),this.sampledBy=hb(this.sampledBy,this);var d;H(a)&&(b=a,a=[]),c.__super__.constructor.call(this,a),d=new f(b),this.subscribeInternal=d.subscribe,this.subscribe=s.wrappedSubscribe(this),this.hasSubscribers=d.hasSubscribers,U(this)}return gb(c,b),c.prototype.delay=function(b){return ab(this,"delay",b,this.flatMap(function(c){return a.later(b,c)}))},c.prototype.debounce=function(b){return ab(this,"debounce",b,this.flatMapLatest(function(c){return a.later(b,c)}))},c.prototype.debounceImmediate=function(b){return ab(this,"debounceImmediate",b,this.flatMapFirst(function(c){return a.once(c).concat(a.later(b).filter(!1))}))},c.prototype.throttle=function(a){return ab(this,"throttle",a,this.bufferWithTime(a).map(function(a){return a[a.length-1]}))},c.prototype.bufferWithTime=function(a){return ab(this,"bufferWithTime",a,this.bufferWithTimeOrCount(a,Number.MAX_VALUE))},c.prototype.bufferWithCount=function(a){return ab(this,"bufferWithCount",a,this.bufferWithTimeOrCount(void 0,a))},c.prototype.bufferWithTimeOrCount=function(a,b){var c;return c=function(c){return c.values.length===b?c.flush():void 0!==a?c.schedule():void 0},ab(this,"bufferWithTimeOrCount",a,b,this.buffer(a,c,c))},c.prototype.buffer=function(b,c,d){var e,f,g;return null==c&&(c=function(){}),null==d&&(d=function(){}),e={scheduled:!1,end:null,values:[],flush:function(){var b;if(this.scheduled=!1,this.values.length>0){if(b=this.push(Q(this.values)),this.values=[],null!=this.end)return this.push(this.end);if(b!==a.noMore)return d(this)}else if(null!=this.end)return this.push(this.end)},schedule:function(){return this.scheduled?void 0:(this.scheduled=!0,b(function(a){return function(){return a.flush()}}(this)))}},g=a.more,H(b)||(f=b,b=function(b){return a.scheduler.setTimeout(b,f)}),ab(this,"buffer",this.withHandler(function(a){return e.push=this.push,a.isError()?g=this.push(a):a.isEnd()?(e.end=a,e.scheduled||e.flush()):(e.values.push(a.value()),c(e)),g}))},c.prototype.merge=function(b){var d;return d=this,new c(y(d,"merge",b),function(c){var e,f;return e=0,f=function(b){return function(d){return b.subscribeInternal(function(b){var f;return b.isEnd()?(e++,2===e?c(z()):a.more):(f=c(b),f===a.noMore&&d(),f)})}},v(f(d),f(b))})},c.prototype.toProperty=function(a){return 0===arguments.length&&(a=m),ab(this,"toProperty",a,this.scan(a,J,!0))},c.prototype.toEventStream=function(){return this},c.prototype.sampledBy=function(a,b){return ab(this,"sampledBy",a,b,this.toProperty().sampledBy(a,b))},c.prototype.concat=function(a){var b;return b=this,new c(y(b,"concat",a),function(c){var d,e;return e=R,d=b.subscribeInternal(function(b){return b.isEnd()?e=a.subscribeInternal(c):c(b)}),function(){return d(),e()}})},c.prototype.takeUntil=function(b){var c;return c={},ab(this,"takeUntil",b,a.groupSimultaneous(this.mapEnd(c),b.skipErrors()).withHandler(function(d){var e,f,g,h,i,j;if(d.hasValue()){if(j=d.value(),e=j[0],b=j[1],b.length)return this.push(z());for(f=a.more,h=0,i=e.length;i>h;h++)g=e[h],f=this.push(g===c?z():Q(g));return f}return this.push(d)}))},c.prototype.skipUntil=function(a){var b;return b=a.take(1).map(!0).toProperty(!1),ab(this,"skipUntil",a,this.filter(b))},c.prototype.skipWhile=function(){var b,c,d;return c=arguments[0],b=2<=arguments.length?eb.call(arguments,1):[],d=!1,x(this,c,b,function(b){return ab(this,"skipWhile",b,this.withHandler(function(c){return!d&&c.hasValue()&&b(c.value())?a.more:(c.hasValue()&&(d=!0),this.push(c))}))})},c.prototype.startWith=function(b){return ab(this,"startWith",b,a.once(b).concat(this))},c.prototype.withHandler=function(a){var b;return b=new f(this.subscribeInternal,a),new c(y(this,"withHandler",a),b.subscribe)},c}(n),o=function(b){function c(b,d,e){this.toEventStream=hb(this.toEventStream,this),this.toProperty=hb(this.toProperty,this),this.changes=hb(this.changes,this),this.sample=hb(this.sample,this),H(b)&&(e=d,d=b,b=[]),c.__super__.constructor.call(this,b),this.subscribeInternal=e===!0?d:new p(this,d,e).subscribe,this.sampledBy=function(b){return function(d,e){var f,g,h,i,j;return null!=e?e=W(e):(f=!0,e=function(a){return a()}),j=new r(b,!1,!1,b.subscribeInternal,f),h=new r(d,!0,!1,d.subscribeInternal,f),i=a.when([j,h],e),g=d instanceof c?i.toProperty():i,ab(b,"sampledBy",d,e,g)}}(this),this.subscribe=s.wrappedSubscribe(this),U(this)}return gb(c,b),c.prototype.sample=function(b){return ab(this,"sample",b,this.sampledBy(a.interval(b,{})))},c.prototype.changes=function(){return new j(y(this,"changes"),function(a){return function(b){return a.subscribeInternal(function(a){return a.isInitial()?void 0:b(a)})}}(this))},c.prototype.withHandler=function(a){return new c(y(this,"withHandler",a),this.subscribeInternal,a)},c.prototype.toProperty=function(){return this},c.prototype.toEventStream=function(){return new j(y(this,"toEventStream"),function(a){return function(b){return a.subscribeInternal(function(a){return a.isInitial()&&(a=a.toNext()),b(a)})}}(this))},c.prototype.and=function(a){return ab(this,"and",a,this.combine(a,function(a,b){return a&&b}))},c.prototype.or=function(a){return ab(this,"or",a,this.combine(a,function(a,b){return a||b}))},c.prototype.delay=function(a){return this.delayChanges("delay",a,function(b){return b.delay(a)})},c.prototype.debounce=function(a){return this.delayChanges("debounce",a,function(b){return b.debounce(a)})},c.prototype.throttle=function(a){return this.delayChanges("throttle",a,function(b){return b.throttle(a)})},c.prototype.delayChanges=function(){var a,b,c;return a=2<=arguments.length?eb.call(arguments,0,c=arguments.length-1):(c=0,[]),b=arguments[c++],ab.apply(null,[this].concat(eb.call(a),[t(this,b(this.changes()))]))},c.prototype.takeUntil=function(a){var b;return b=this.changes().takeUntil(a),ab(this,"takeUntil",a,t(this,b))},c.prototype.startWith=function(a){return ab(this,"startWith",a,this.scan(a,function(a,b){return b}))},c}(n),x=function(a,b,c,d){var e;return b instanceof o?(e=b.sampledBy(a,function(a,b){return[a,b]}),d.apply(e,[function(a){var b,c;return b=a[0],c=a[1],b}]).map(function(a){var b,c;return b=a[0],c=a[1]})):(b=L(b,c),d.apply(a,[b]))},t=function(b,c){var d;return d=new j(y(b,"justInitValue"),function(c){var e,f;return f=null,e=b.subscribeInternal(function(b){return b.hasValue()&&(f=b),a.noMore}),s.whenDoneWith(d,function(){return null!=f&&c(f),c(z())}),e}),d.concat(c).toProperty()},f=function(){function b(b,c){var d,e,f,g,h,i,j,k,l,m;null==b&&(b=function(){return R}),k=[],i=null,h=!1,e=!1,this.hasSubscribers=function(){return k.length>0},f=null,l=R,j=function(a){return k=cb.without(a,k)},m=null,d=function(){var a,b,c,d,e;if(null!=m){for(b=m,m=null,e=[],c=0,d=b.length;d>c;c++)a=b[c],e.push(a());return e}},g=function(b){var c,e,g,m,n,o;if(h)return i=(i||[]).concat([b]),a.more;if(b!==f){b.isError()&&(f=b),g=!1;try{for(h=!0,m=k,n=0,o=m.length;o>n;n++)e=m[n],c=e.sink(b),(c===a.noMore||b.isEnd())&&j(e);g=!0}finally{h=!1,g||(i=null)}for(g=!0;null!=i?i.length:void 0;)b=cb.head(i),i=cb.tail(i),this.push(b);return d(b),this.hasSubscribers()?a.more:(l(),a.noMore)}},this.push=function(a){return function(b){return s.inTransaction(b,a,g,[b])}}(this),null==c&&(c=function(a){return this.push(a)}),this.handleEvent=function(a){return function(b){return b.isEnd()&&(e=!0),c.apply(a,[b])}}(this),this.subscribe=function(a){return function(c){var d,f;return e?(c(z()),R):(d={sink:c},k=k.concat(d),1===k.length&&(f=b(a.handleEvent),l=function(){return f(),l=R}),function(){return j(d),a.hasSubscribers()?void 0:l()})}}(this)}return b}(),p=function(b){function c(b,d,e){var f,g,h,i;c.__super__.constructor.call(this,d,e),f=m,g=void 0,i=this.push,d=this.subscribe,h=!1,this.push=function(a){return function(b){return b.isEnd()&&(h=!0),b.hasValue()&&(f=new q(b),g=s.currentEventId()),i.apply(a,[b])}}(this),this.subscribe=function(c){return function(e){var i,j,k,l,m;return j=!1,l=a.more,k=function(){return l===a.noMore?R:h?(e(z()),R):d.apply(this,[e])},f.isDefined&&(c.hasSubscribers()||h)?(i=s.currentEventId(),m=g,!h&&m&&i&&i!==m?(s.whenDoneWith(b,function(){return g===m?e(E(f.get().value())):void 0}),k()):(s.inTransaction(void 0,c,function(){return l=e(E(f.get().value()))},[]),k())):k()}}(this)}return gb(c,b),c}(f),c=function(b){function c(){var b,d,e,f,g,i,j,k;e=void 0,i=[],b=!1,d=function(){return function(b){return function(c){return c.isEnd()?(k(b),a.noMore):(c.hasValue()&&c.value(),e(c))}}}(this),j=function(){var a,b,c,d;for(d=[],b=0,c=i.length;c>b;b++)a=i[b],d.push("function"==typeof a.unsub?a.unsub():void 0);return d},g=function(a){return a.unsub=a.input.subscribeInternal(d(a.input))},k=function(a){var b,c,d,e;for(b=d=0,e=i.length;e>d;b=++d)if(c=i[b],c.input===a)return"function"==typeof c.unsub&&c.unsub(),void i.splice(b,1)},f=function(){return function(a){var b,c,d,f;for(e=a,f=u(i),c=0,d=f.length;d>c;c++)b=f[c],g(b);return j}}(this),c.__super__.constructor.call(this,y(a,"Bus"),f),this.plug=function(){return function(a){var c;if(!b)return c={input:a},i.push(c),null!=e&&g(c),function(){return k(a)}}}(this),this.push=function(){return function(a){return"function"==typeof e?e(Q(a)):void 0}}(this),this.error=function(){return function(a){return"function"==typeof e?e(new h(a)):void 0}}(this),this.end=function(){return function(){return b=!0,j(),"function"==typeof e?e(z()):void 0}}(this)}return gb(c,b),c}(j),r=function(){function a(a,b,c,d,e,f){var g;this.obs=a,this.sync=b,this.subscribe=d,null==e&&(e=!1),null==f&&(f=[]),g=e?cb.id:function(a){return a()},null==this.subscribe&&(this.subscribe=a.subscribeInternal),this.markEnded=function(){return this.ended=!0},this.toString=this.obs.toString,c?(this.consume=function(){return g(f.shift())},this.push=function(a){return f.push(a)},this.mayHave=function(a){return!this.ended||f.length>=a},this.hasAtLeast=function(a){return f.length>=a},this.flatten=!1):(this.consume=function(){return g(f[0])},this.push=function(a){return f=[a]},this.mayHave=function(){return!0},this.hasAtLeast=function(){return f.length},this.flatten=!0)}return a}(),b=function(a){function b(a){var c;this.obs=a,c=[],b.__super__.constructor.call(this,this.obs,!0,!1,this.obs.subscribeInternal,!1,c),this.consume=function(){var a;return a=c,c=[],a},this.push=function(a){return c.push(a())},this.hasAtLeast=function(){return!0}}return gb(b,a),b}(r),r.fromObservable=function(a){return a instanceof r?a:a instanceof o?new r(a,!1,!1):new r(a,!0,!0)},y=function(){var a,b,c;return b=arguments[0],c=arguments[1],a=3<=arguments.length?eb.call(arguments,2):[],(b||c)instanceof e?b||c:new e(b,c,a)},e=function(){function a(a,b,c){var d,e,f,g;f=function(a){return F(a)?cb.flatMap(f,a):I(a)?[a]:a instanceof r?[a.obs]:[]},g=null,d=function(a){var b,c,e,f,h;for(c=a.internalDeps(),h=[],e=0,f=c.length;f>e;e++)b=c[e],g[b.id]=!0,h.push(d(b));return h},e=function(a){return null==g&&(g={},d(this)),g[a.id]},this.apply=function(d){var g;return g=cb.cached(function(){return f([a].concat(c))}),d.internalDeps=d.internalDeps||g,d.dependsOn=e,d.deps=g,d.toString=function(){return cb.toString(a)+"."+cb.toString(b)+"("+cb.map(cb.toString,c)+")"},d.inspect=function(){return d.toString()},d.desc=function(){return{context:a,method:b,args:c}},d}}return a}(),ab=function(){var a,b,c;return a=2<=arguments.length?eb.call(arguments,0,c=arguments.length-1):(c=0,[]),b=arguments[c++],y.apply(null,a).apply(b)},a.when=function(){var b,c,d,e,f,g,h,i,k,l,m,n,o,p,q,t,u,x,A;if(l=1<=arguments.length?eb.call(arguments,0):[],0===l.length)return a.never();for(f=l.length,p="when: expecting arguments in the form (Observable+,function)+",o=[],k=[],c=0;f>c;){for(i=cb.toArray(l[c]),b=l[c+1],h={f:H(b)?b:function(){return b},ixs:[]},q=0,u=i.length;u>q;q++){for(n=i[q],d=cb.indexOf(o,n),0>d&&(o.push(n),d=o.length-1),A=h.ixs,t=0,x=A.length;x>t;t++)e=A[t],e.index===d&&e.count++;h.ixs.push({index:d,count:1})}i.length>0&&k.push(h),c+=2}return o.length?(o=cb.map(r.fromObservable,o),g=cb.any(o,function(a){return a.flatten})&&w(cb.map(function(a){return a.obs},o)),m=new j(y.apply(null,[a,"when"].concat(eb.call(l))),function(b){var d,e,f,h,i,j,l;return l=[],f=!1,h=function(a){var b,d,e;for(e=a.ixs,b=0,d=e.length;d>b;b++)if(c=e[b],!o[c.index].hasAtLeast(c.count))return!1;return!0},e=function(a){return!a.sync||a.ended},d=function(a){var b,d,e;for(e=a.ixs,b=0,d=e.length;d>b;b++)if(c=e[b],!o[c.index].mayHave(c.count))return!0},i=function(a){return!a.source.flatten},j=function(j){return function(n){var p,q,r;return q=function(){return s.whenDoneWith(m,p)},r=function(){var d,e,f,j,m,n;if(!(l.length>0))return a.more;for(e=a.more,f=l.pop(),m=0,n=k.length;n>m;m++)if(d=k[m],h(d))return j=function(){return d.f.apply(d,function(){var a,b,e,f;for(e=d.ixs,f=[],a=0,b=e.length;b>a;a++)c=e[a],f.push(o[c.index].consume());return f}())},e=b(f.e.apply(j)),l.length&&g&&(l=cb.filter(i,l)),e===a.noMore?e:r()},p=function(){var c;return c=r(),f&&(f=!1,(cb.all(o,e)||cb.all(k,d))&&(c=a.noMore,b(z()))),c===a.noMore&&n(),c},j.subscribe(function(c){var d;return c.isEnd()?(f=!0,j.markEnded(),q()):c.isError()?d=b(c):(j.push(c.value),j.sync&&(l.push({source:j,e:c}),g?q():p())),d===a.noMore&&n(),d||a.more})}},v.apply(null,function(){var a,b,c;for(c=[],a=0,b=o.length;b>a;a++)n=o[a],c.push(j(n));return c}())})):a.never()},w=function(b,c){var d;return null==c&&(c=[]),d=function(b){var e;return a._.contains(c,b)?!0:(e=b.internalDeps(),e.length?(c.push(b),a._.any(e,d)):(c.push(b),!1))},a._.any(b,d)},a.update=function(){var b,c,d,e;for(c=arguments[0],e=2<=arguments.length?eb.call(arguments,1):[],d=function(a){return function(){var b;return b=1<=arguments.length?eb.call(arguments,0):[],function(c){return a.apply(null,[c].concat(b))}}},b=e.length-1;b>0;)e[b]instanceof Function||(e[b]=function(a){return function(){return a}}(e[b])),e[b]=d(e[b]),b-=2;return ab.apply(null,[a,"update",c].concat(eb.call(e),[a.when.apply(a,e).scan(c,function(a,b){return b(a)})]))},v=function(){var a;return a=1<=arguments.length?eb.call(arguments,0):[],new d(a).unsubscribe},d=function(){function a(a){var b,c,d;for(null==a&&(a=[]),this.empty=hb(this.empty,this),this.count=hb(this.count,this),this.unsubscribe=hb(this.unsubscribe,this),this.add=hb(this.add,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[],c=0,d=a.length;d>c;c++)b=a[c],this.add(b)}return a.prototype.add=function(a){var b,c,d;if(!this.unsubscribed)return b=!1,c=R,this.starting.push(a),d=function(d){return function(){return d.unsubscribed?void 0:(b=!0,d.remove(c),cb.remove(a,d.starting))}}(this),c=a(this.unsubscribe,d),this.unsubscribed||b||this.subscriptions.push(c),cb.remove(a,this.starting),c},a.prototype.remove=function(a){return this.unsubscribed?void 0:void 0!==cb.remove(a,this.subscriptions)?a():void 0},a.prototype.unsubscribe=function(){var a,b,c,d;if(!this.unsubscribed){for(this.unsubscribed=!0,d=this.subscriptions,b=0,c=d.length;c>b;b++)(a=d[b])();return this.subscriptions=[],this.starting=[]}},a.prototype.count=function(){return this.unsubscribed?0:this.subscriptions.length+this.starting.length},a.prototype.empty=function(){return 0===this.count()},a}(),a.CompositeUnsubscribe=d,q=function(){function a(a){this.value=a}return a.prototype.getOrElse=function(){return this.value},a.prototype.get=function(){return this.value},a.prototype.filter=function(b){return b(this.value)?new a(this.value):m},a.prototype.map=function(b){return new a(b(this.value))},a.prototype.forEach=function(a){return a(this.value)},a.prototype.isDefined=!0,a.prototype.toArray=function(){return[this.value]},a.prototype.inspect=function(){return"Some("+this.value+")"},a.prototype.toString=function(){return this.inspect()},a}(),m={getOrElse:function(a){return a},filter:function(){return m},map:function(){return m},forEach:function(){},isDefined:!1,toArray:function(){return[]},inspect:function(){return"None"},toString:function(){return this.inspect()}},s=function(){var b,c,d,e,f,g,h,i,j,k,l;return i=void 0,j=[],c=[],b=function(a){return i?c.push(a):a()},h=function(a){return!cb.any(j,function(b){return a.obs.dependsOn(b.obs)})},k=function(a,b){return i?j.push({obs:a,f:b}):b()},e=function(){for(;!h(j[0]);)j.push(j.splice(0,1)[0]);return j.splice(0,1)[0]},f=function(){var a;for(a=[];j.length;)a.push(e().f());return a},g=function(a,b,d,e){var g;if(i)return d.apply(b,e);i=a;try{g=d.apply(b,e),f()}finally{for(i=void 0;c.length;)(d=c.splice(0,1)[0])()}return g},d=function(){return i?i.id:void 0},l=function(c){return function(d){var e,f,g;return g=!1,e=function(){},f=function(){return g=!0,e()},g||(e=c.subscribeInternal(function(c){return b(function(){var b;return g||(b=d(c),b!==a.noMore)?void 0:f()})})),f}},{whenDoneWith:k,inTransaction:g,currentEventId:d,wrappedSubscribe:l}}(),a.EventStream=j,a.Property=o,a.Observable=n,a.Bus=c,a.Initial=k,a.Next=l,a.End=g,a.Error=h,R=function(){},J=function(a,b){return b()},C=function(a){return a},E=function(a){return new k(cb.always(a))},Q=function(a){return new l(cb.always(a))},z=function(){return new g},X=function(a){return a instanceof i?a:Q(a)},u=function(a){return a.slice(0)},H=function(a){return"function"==typeof a},F=function(a){return a instanceof Array},I=function(a){return a instanceof n},S=function(a,b){return function(){var c;return c=1<=arguments.length?eb.call(arguments,0):[],a.apply(null,b.concat(c)) +}},P=function(a){return 1===a.length&&I(a[0])?cb.always(a[0]):M(a)},M=function(a){return a=Array.prototype.slice.call(a),N.apply(null,a)},N=bb(function(){var a,b;return b=arguments[0],a=2<=arguments.length?eb.call(arguments,1):[],H(b)?a.length?S(b,a):b:G(b)?Y(b,a):cb.always(b)}),L=function(a,b){return N.apply(null,[a].concat(eb.call(b)))},O=function(b){return I(b)?b:a.once(b)},G=function(a){return"string"==typeof a&&a.length>1&&"."===a.charAt(0)},a.isFieldKey=G,Y=function(a,b){var c,d;return d=a.slice(1).split("."),c=cb.map(_(b),d),function(b){var d,e;for(d=0,e=c.length;e>d;d++)a=c[d],b=a(b);return b}},_=function(a){return function(b){return function(c){var d;return null==c?void 0:(d=c[b],H(d)?d.apply(c,a):d)}}},Z=function(a){return a.slice(1)},W=function(a){var b;return H(a)?a:G(a)?(b=Z(a),function(a,c){return a[b](c)}):void 0},$=function(a){return a instanceof q||a===m?a:new q(a)},cb={indexOf:Array.prototype.indexOf?function(a,b){return a.indexOf(b)}:function(a,b){var c,d,e,f;for(c=e=0,f=a.length;f>e;c=++e)if(d=a[c],b===d)return c;return-1},indexWhere:function(a,b){var c,d,e,f;for(c=e=0,f=a.length;f>e;c=++e)if(d=a[c],b(d))return c;return-1},head:function(a){return a[0]},always:function(a){return function(){return a}},negate:function(a){return function(b){return!a(b)}},empty:function(a){return 0===a.length},tail:function(a){return a.slice(1,a.length)},filter:function(a,b){var c,d,e,f;for(c=[],e=0,f=b.length;f>e;e++)d=b[e],a(d)&&c.push(d);return c},map:function(a,b){var c,d,e,f;for(f=[],d=0,e=b.length;e>d;d++)c=b[d],f.push(a(c));return f},each:function(a,b){var c,d,e;e=[];for(c in a)d=a[c],e.push(b(c,d));return e},toArray:function(a){return F(a)?a:[a]},contains:function(a,b){return-1!==cb.indexOf(a,b)},id:function(a){return a},last:function(a){return a[a.length-1]},all:function(a,b){var c,d,e;for(null==b&&(b=cb.id),d=0,e=a.length;e>d;d++)if(c=a[d],!b(c))return!1;return!0},any:function(a,b){var c,d,e;for(null==b&&(b=cb.id),d=0,e=a.length;e>d;d++)if(c=a[d],b(c))return!0;return!1},without:function(a,b){return cb.filter(function(b){return b!==a},b)},remove:function(a,b){var c;return c=cb.indexOf(b,a),c>=0?b.splice(c,1):void 0},fold:function(a,b,c){var d,e,f;for(e=0,f=a.length;f>e;e++)d=a[e],b=c(b,d);return b},flatMap:function(a,b){return cb.fold(b,[],function(b,c){return b.concat(a(c))})},cached:function(a){var b;return b=m,function(){return b===m&&(b=a(),a=null),b}},toString:function(a){var b,c,d,e;try{return T++,null==a?"undefined":H(a)?"function":F(a)?T>5?"[..]":"["+cb.map(cb.toString,a).toString()+"]":null!=(null!=a?a.toString:void 0)&&a.toString!==Object.prototype.toString?a.toString():"object"==typeof a?T>5?"{..}":(c=function(){var c;c=[];for(d in a)fb.call(a,d)&&(e=function(){try{return a[d]}catch(c){return b=c}}(),c.push(cb.toString(d)+":"+cb.toString(e)));return c}(),"{"+c+"}"):a}finally{T--}}},T=0,a._=cb,a.scheduler={setTimeout:function(a,b){return setTimeout(a,b)},setInterval:function(a,b){return setInterval(a,b)},clearInterval:function(a){return clearInterval(a)},now:function(){return(new Date).getTime()}},"undefined"!=typeof module&&null!==module?(module.exports=a,a.Bacon=a):("undefined"!=typeof define&&null!==define&&null!=define.amd&&define([],function(){return a}),this.Bacon=a)}).call(this); diff --git a/ajax/libs/bacon.js/package.json b/ajax/libs/bacon.js/package.json index 79762c40e..af643164d 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.7.6", + "version": "0.7.7", "author": "Juha Paananen", "description": "A small functional reactive programming lib for JavaScript.", "homepage": "http://baconjs.blogspot.com",