diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 00000000..5ce41eb4 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,5 @@ +{ + "reporter": "spec", + "spec": "test/specs/*.js", + "ui": "bdd" +} diff --git a/.travis.yml b/.travis.yml index 612246bb..e8a4fff3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: node_js sudo: false node_js: - - 6 - - 8 - - 10 - 12 - stable before_install: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..32cb0d48 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:14 + +WORKDIR /code + +COPY package*.json ./ + +RUN npm install diff --git a/configs/rollup.esm.js b/configs/rollup.esm.js index ae0d8c3c..702f7ab6 100644 --- a/configs/rollup.esm.js +++ b/configs/rollup.esm.js @@ -1,6 +1,13 @@ import base from './rollup.dev.js' +import stripCode from 'rollup-plugin-strip-code' export default Object.assign({}, base, { format: 'es', + plugins: [ + stripCode({ + start_comment: 'dev-code', + end_comment: 'end-dev-code', + }), + ].concat(base.plugins), dest: 'dist/kefir.esm.js', }) diff --git a/configs/rollup.prod.js b/configs/rollup.prod.js index 84cbe492..8f36baa5 100644 --- a/configs/rollup.prod.js +++ b/configs/rollup.prod.js @@ -1,7 +1,13 @@ import base from './rollup.dev.js' import uglify from 'rollup-plugin-uglify' +import stripCode from 'rollup-plugin-strip-code' export default Object.assign({}, base, { - plugins: base.plugins.concat([uglify({output: {comments: /\!\s\w/}})]), + plugins: [ + stripCode({ + start_comment: 'dev-code', + end_comment: 'end-dev-code', + }), + ].concat(base.plugins.concat([uglify({output: {comments: /\!\s\w/}})])), dest: 'dist/kefir.min.js', }) diff --git a/dist/kefir.esm.js b/dist/kefir.esm.js new file mode 100644 index 00000000..de3dd232 --- /dev/null +++ b/dist/kefir.esm.js @@ -0,0 +1,3641 @@ +/*! Kefir.js v3.8.8 + * https://github.com/kefirjs/kefir + */ + +function createObj(proto) { + var F = function () {}; + F.prototype = proto; + return new F(); +} + +function extend(target /*, mixin1, mixin2...*/) { + var length = arguments.length, + i = void 0, + prop = void 0; + for (i = 1; i < length; i++) { + for (prop in arguments[i]) { + target[prop] = arguments[i][prop]; + } + } + return target; +} + +function inherit(Child, Parent /*, mixin1, mixin2...*/) { + var length = arguments.length, + i = void 0; + Child.prototype = createObj(Parent.prototype); + Child.prototype.constructor = Child; + for (i = 2; i < length; i++) { + extend(Child.prototype, arguments[i]); + } + return Child; +} + +var NOTHING = ['']; +var END = 'end'; +var VALUE = 'value'; +var ERROR = 'error'; +var ANY = 'any'; + +function concat(a, b) { + var result = void 0, + length = void 0, + i = void 0, + j = void 0; + if (a.length === 0) { + return b; + } + if (b.length === 0) { + return a; + } + j = 0; + result = new Array(a.length + b.length); + length = a.length; + for (i = 0; i < length; i++, j++) { + result[j] = a[i]; + } + length = b.length; + for (i = 0; i < length; i++, j++) { + result[j] = b[i]; + } + return result; +} + +function find(arr, value) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + if (arr[i] === value) { + return i; + } + } + return -1; +} + +function findByPred(arr, pred) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + if (pred(arr[i])) { + return i; + } + } + return -1; +} + +function cloneArray(input) { + var length = input.length, + result = new Array(length), + i = void 0; + for (i = 0; i < length; i++) { + result[i] = input[i]; + } + return result; +} + +function remove(input, index) { + var length = input.length, + result = void 0, + i = void 0, + j = void 0; + if (index >= 0 && index < length) { + if (length === 1) { + return []; + } else { + result = new Array(length - 1); + for (i = 0, j = 0; i < length; i++) { + if (i !== index) { + result[j] = input[i]; + j++; + } + } + return result; + } + } else { + return input; + } +} + +function map(input, fn) { + var length = input.length, + result = new Array(length), + i = void 0; + for (i = 0; i < length; i++) { + result[i] = fn(input[i]); + } + return result; +} + +function forEach(arr, fn) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + fn(arr[i]); + } +} + +function fillArray(arr, value) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + arr[i] = value; + } +} + +function contains(arr, value) { + return find(arr, value) !== -1; +} + +function slide(cur, next, max) { + var length = Math.min(max, cur.length + 1), + offset = cur.length - length + 1, + result = new Array(length), + i = void 0; + for (i = offset; i < length; i++) { + result[i - offset] = cur[i]; + } + result[length - 1] = next; + return result; +} + +function callSubscriber(type, fn, event) { + if (type === ANY) { + fn(event); + } else if (type === event.type) { + if (type === VALUE || type === ERROR) { + fn(event.value); + } else { + fn(); + } + } +} + +function Dispatcher() { + this._items = []; + this._spies = []; + this._inLoop = 0; + this._removedItems = null; +} + +extend(Dispatcher.prototype, { + add: function (type, fn) { + this._items = concat(this._items, [{ type: type, fn: fn }]); + return this._items.length; + }, + remove: function (type, fn) { + var index = findByPred(this._items, function (x) { + return x.type === type && x.fn === fn; + }); + + // if we're currently in a notification loop, + // remember this subscriber was removed + if (this._inLoop !== 0 && index !== -1) { + if (this._removedItems === null) { + this._removedItems = []; + } + this._removedItems.push(this._items[index]); + } + + this._items = remove(this._items, index); + return this._items.length; + }, + addSpy: function (fn) { + this._spies = concat(this._spies, [fn]); + return this._spies.length; + }, + + + // Because spies are only ever a function that perform logging as + // their only side effect, we don't need the same complicated + // removal logic like in remove() + removeSpy: function (fn) { + this._spies = remove(this._spies, this._spies.indexOf(fn)); + return this._spies.length; + }, + dispatch: function (event) { + this._inLoop++; + for (var i = 0, spies = this._spies; this._spies !== null && i < spies.length; i++) { + spies[i](event); + } + + for (var _i = 0, items = this._items; _i < items.length; _i++) { + // cleanup was called + if (this._items === null) { + break; + } + + // this subscriber was removed + if (this._removedItems !== null && contains(this._removedItems, items[_i])) { + continue; + } + + callSubscriber(items[_i].type, items[_i].fn, event); + } + this._inLoop--; + if (this._inLoop === 0) { + this._removedItems = null; + } + }, + cleanup: function () { + this._items = null; + this._spies = null; + } +}); + +function Observable() { + this._dispatcher = new Dispatcher(); + this._active = false; + this._alive = true; + this._activating = false; + this._logHandlers = null; + this._spyHandlers = null; +} + +extend(Observable.prototype, { + _name: 'observable', + + _onActivation: function () {}, + _onDeactivation: function () {}, + _setActive: function (active) { + if (this._active !== active) { + this._active = active; + if (active) { + this._activating = true; + this._onActivation(); + this._activating = false; + } else { + this._onDeactivation(); + } + } + }, + _clear: function () { + this._setActive(false); + this._dispatcher.cleanup(); + this._dispatcher = null; + this._logHandlers = null; + }, + _emit: function (type, x) { + switch (type) { + case VALUE: + return this._emitValue(x); + case ERROR: + return this._emitError(x); + case END: + return this._emitEnd(); + } + }, + _emitValue: function (value) { + if (this._alive) { + this._dispatcher.dispatch({ type: VALUE, value: value }); + } + }, + _emitError: function (value) { + if (this._alive) { + this._dispatcher.dispatch({ type: ERROR, value: value }); + } + }, + _emitEnd: function () { + if (this._alive) { + this._alive = false; + this._dispatcher.dispatch({ type: END }); + this._clear(); + } + }, + _on: function (type, fn) { + if (this._alive) { + this._dispatcher.add(type, fn); + this._setActive(true); + } else { + callSubscriber(type, fn, { type: END }); + } + return this; + }, + _off: function (type, fn) { + if (this._alive) { + var count = this._dispatcher.remove(type, fn); + if (count === 0) { + this._setActive(false); + } + } + return this; + }, + onValue: function (fn) { + return this._on(VALUE, fn); + }, + onError: function (fn) { + return this._on(ERROR, fn); + }, + onEnd: function (fn) { + return this._on(END, fn); + }, + onAny: function (fn) { + return this._on(ANY, fn); + }, + offValue: function (fn) { + return this._off(VALUE, fn); + }, + offError: function (fn) { + return this._off(ERROR, fn); + }, + offEnd: function (fn) { + return this._off(END, fn); + }, + offAny: function (fn) { + return this._off(ANY, fn); + }, + observe: function (observerOrOnValue, onError, onEnd) { + var _this = this; + var closed = false; + + var observer = !observerOrOnValue || typeof observerOrOnValue === 'function' ? { value: observerOrOnValue, error: onError, end: onEnd } : observerOrOnValue; + + var handler = function (event) { + if (event.type === END) { + closed = true; + } + if (event.type === VALUE && observer.value) { + observer.value(event.value); + } else if (event.type === ERROR && observer.error) { + observer.error(event.value); + } else if (event.type === END && observer.end) { + observer.end(event.value); + } + }; + + this.onAny(handler); + + return { + unsubscribe: function () { + if (!closed) { + _this.offAny(handler); + closed = true; + } + }, + + get closed() { + return closed; + } + }; + }, + + + // A and B must be subclasses of Stream and Property (order doesn't matter) + _ofSameType: function (A, B) { + return A.prototype.getType() === this.getType() ? A : B; + }, + setName: function (sourceObs /* optional */, selfName) { + this._name = selfName ? sourceObs._name + '.' + selfName : sourceObs; + return this; + }, + log: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + var isCurrent = void 0; + var handler = function (event) { + var type = '<' + event.type + (isCurrent ? ':current' : '') + '>'; + if (event.type === END) { + console.log(name, type); + } else { + console.log(name, type, event.value); + } + }; + + if (this._alive) { + if (!this._logHandlers) { + this._logHandlers = []; + } + this._logHandlers.push({ name: name, handler: handler }); + } + + isCurrent = true; + this.onAny(handler); + isCurrent = false; + + return this; + }, + offLog: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + if (this._logHandlers) { + var handlerIndex = findByPred(this._logHandlers, function (obj) { + return obj.name === name; + }); + if (handlerIndex !== -1) { + this.offAny(this._logHandlers[handlerIndex].handler); + this._logHandlers.splice(handlerIndex, 1); + } + } + + return this; + }, + spy: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + var handler = function (event) { + var type = '<' + event.type + '>'; + if (event.type === END) { + console.log(name, type); + } else { + console.log(name, type, event.value); + } + }; + if (this._alive) { + if (!this._spyHandlers) { + this._spyHandlers = []; + } + this._spyHandlers.push({ name: name, handler: handler }); + this._dispatcher.addSpy(handler); + } + return this; + }, + offSpy: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + if (this._spyHandlers) { + var handlerIndex = findByPred(this._spyHandlers, function (obj) { + return obj.name === name; + }); + if (handlerIndex !== -1) { + this._dispatcher.removeSpy(this._spyHandlers[handlerIndex].handler); + this._spyHandlers.splice(handlerIndex, 1); + } + } + return this; + } +}); + +// extend() can't handle `toString` in IE8 +Observable.prototype.toString = function () { + return '[' + this._name + ']'; +}; + +function Stream() { + Observable.call(this); +} + +inherit(Stream, Observable, { + _name: 'stream', + + getType: function () { + return 'stream'; + } +}); + +function Property() { + Observable.call(this); + this._currentEvent = null; +} + +inherit(Property, Observable, { + _name: 'property', + + _emitValue: function (value) { + if (this._alive) { + this._currentEvent = { type: VALUE, value: value }; + if (!this._activating) { + this._dispatcher.dispatch({ type: VALUE, value: value }); + } + } + }, + _emitError: function (value) { + if (this._alive) { + this._currentEvent = { type: ERROR, value: value }; + if (!this._activating) { + this._dispatcher.dispatch({ type: ERROR, value: value }); + } + } + }, + _emitEnd: function () { + if (this._alive) { + this._alive = false; + if (!this._activating) { + this._dispatcher.dispatch({ type: END }); + } + this._clear(); + } + }, + _on: function (type, fn) { + if (this._alive) { + this._dispatcher.add(type, fn); + this._setActive(true); + } + if (this._currentEvent !== null) { + callSubscriber(type, fn, this._currentEvent); + } + if (!this._alive) { + callSubscriber(type, fn, { type: END }); + } + return this; + }, + getType: function () { + return 'property'; + } +}); + +var neverS = new Stream(); +neverS._emitEnd(); +neverS._name = 'never'; + +function never() { + return neverS; +} + +function timeBased(mixin) { + function AnonymousStream(wait, options) { + var _this = this; + + Stream.call(this); + this._wait = wait; + this._intervalId = null; + this._$onTick = function () { + return _this._onTick(); + }; + this._init(options); + } + + inherit(AnonymousStream, Stream, { + _init: function () {}, + _free: function () {}, + _onTick: function () {}, + _onActivation: function () { + this._intervalId = setInterval(this._$onTick, this._wait); + }, + _onDeactivation: function () { + if (this._intervalId !== null) { + clearInterval(this._intervalId); + this._intervalId = null; + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._$onTick = null; + this._free(); + } + }, mixin); + + return AnonymousStream; +} + +var S = timeBased({ + _name: 'later', + + _init: function (_ref) { + var x = _ref.x; + + this._x = x; + }, + _free: function () { + this._x = null; + }, + _onTick: function () { + this._emitValue(this._x); + this._emitEnd(); + } +}); + +function later(wait, x) { + return new S(wait, { x: x }); +} + +var S$1 = timeBased({ + _name: 'interval', + + _init: function (_ref) { + var x = _ref.x; + + this._x = x; + }, + _free: function () { + this._x = null; + }, + _onTick: function () { + this._emitValue(this._x); + } +}); + +function interval(wait, x) { + return new S$1(wait, { x: x }); +} + +var S$2 = timeBased({ + _name: 'sequentially', + + _init: function (_ref) { + var xs = _ref.xs; + + this._xs = cloneArray(xs); + }, + _free: function () { + this._xs = null; + }, + _onTick: function () { + if (this._xs.length === 1) { + this._emitValue(this._xs[0]); + this._emitEnd(); + } else { + this._emitValue(this._xs.shift()); + } + } +}); + +function sequentially(wait, xs) { + return xs.length === 0 ? never() : new S$2(wait, { xs: xs }); +} + +var S$3 = timeBased({ + _name: 'fromPoll', + + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _onTick: function () { + var fn = this._fn; + this._emitValue(fn()); + } +}); + +function fromPoll(wait, fn) { + return new S$3(wait, { fn: fn }); +} + +function emitter(obs) { + function value(x) { + obs._emitValue(x); + return obs._active; + } + + function error(x) { + obs._emitError(x); + return obs._active; + } + + function end() { + obs._emitEnd(); + return obs._active; + } + + function event(e) { + obs._emit(e.type, e.value); + return obs._active; + } + + return { + value: value, + error: error, + end: end, + event: event, + + // legacy + emit: value, + emitEvent: event + }; +} + +var S$4 = timeBased({ + _name: 'withInterval', + + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + this._emitter = emitter(this); + }, + _free: function () { + this._fn = null; + this._emitter = null; + }, + _onTick: function () { + var fn = this._fn; + fn(this._emitter); + } +}); + +function withInterval(wait, fn) { + return new S$4(wait, { fn: fn }); +} + +function S$5(fn) { + Stream.call(this); + this._fn = fn; + this._unsubscribe = null; +} + +inherit(S$5, Stream, { + _name: 'stream', + + _onActivation: function () { + var fn = this._fn; + var unsubscribe = fn(emitter(this)); + this._unsubscribe = typeof unsubscribe === 'function' ? unsubscribe : null; + + // fix https://github.com/kefirjs/kefir/issues/35 + if (!this._active) { + this._callUnsubscribe(); + } + }, + _callUnsubscribe: function () { + if (this._unsubscribe !== null) { + this._unsubscribe(); + this._unsubscribe = null; + } + }, + _onDeactivation: function () { + this._callUnsubscribe(); + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._fn = null; + } +}); + +function stream(fn) { + return new S$5(fn); +} + +function fromCallback(callbackConsumer) { + var called = false; + + return stream(function (emitter) { + if (!called) { + callbackConsumer(function (x) { + emitter.emit(x); + emitter.end(); + }); + called = true; + } + }).setName('fromCallback'); +} + +function fromNodeCallback(callbackConsumer) { + var called = false; + + return stream(function (emitter) { + if (!called) { + callbackConsumer(function (error, x) { + if (error) { + emitter.error(error); + } else { + emitter.emit(x); + } + emitter.end(); + }); + called = true; + } + }).setName('fromNodeCallback'); +} + +function spread(fn, length) { + switch (length) { + case 0: + return function () { + return fn(); + }; + case 1: + return function (a) { + return fn(a[0]); + }; + case 2: + return function (a) { + return fn(a[0], a[1]); + }; + case 3: + return function (a) { + return fn(a[0], a[1], a[2]); + }; + case 4: + return function (a) { + return fn(a[0], a[1], a[2], a[3]); + }; + default: + return function (a) { + return fn.apply(null, a); + }; + } +} + +function apply(fn, c, a) { + var aLength = a ? a.length : 0; + if (c == null) { + switch (aLength) { + case 0: + return fn(); + case 1: + return fn(a[0]); + case 2: + return fn(a[0], a[1]); + case 3: + return fn(a[0], a[1], a[2]); + case 4: + return fn(a[0], a[1], a[2], a[3]); + default: + return fn.apply(null, a); + } + } else { + switch (aLength) { + case 0: + return fn.call(c); + default: + return fn.apply(c, a); + } + } +} + +function fromSubUnsub(sub, unsub, transformer /* Function | falsey */) { + return stream(function (emitter) { + var handler = transformer ? function () { + emitter.emit(apply(transformer, this, arguments)); + } : function (x) { + emitter.emit(x); + }; + + sub(handler); + return function () { + return unsub(handler); + }; + }).setName('fromSubUnsub'); +} + +var pairs = [['addEventListener', 'removeEventListener'], ['addListener', 'removeListener'], ['on', 'off']]; + +function fromEvents(target, eventName, transformer) { + var sub = void 0, + unsub = void 0; + + for (var i = 0; i < pairs.length; i++) { + if (typeof target[pairs[i][0]] === 'function' && typeof target[pairs[i][1]] === 'function') { + sub = pairs[i][0]; + unsub = pairs[i][1]; + break; + } + } + + if (sub === undefined) { + throw new Error("target don't support any of " + 'addEventListener/removeEventListener, addListener/removeListener, on/off method pair'); + } + + return fromSubUnsub(function (handler) { + return target[sub](eventName, handler); + }, function (handler) { + return target[unsub](eventName, handler); + }, transformer).setName('fromEvents'); +} + +// HACK: +// We don't call parent Class constructor, but instead putting all necessary +// properties into prototype to simulate ended Property +// (see Propperty and Observable classes). + +function P(value) { + this._currentEvent = { type: 'value', value: value, current: true }; +} + +inherit(P, Property, { + _name: 'constant', + _active: false, + _activating: false, + _alive: false, + _dispatcher: null, + _logHandlers: null +}); + +function constant(x) { + return new P(x); +} + +// HACK: +// We don't call parent Class constructor, but instead putting all necessary +// properties into prototype to simulate ended Property +// (see Propperty and Observable classes). + +function P$1(value) { + this._currentEvent = { type: 'error', value: value, current: true }; +} + +inherit(P$1, Property, { + _name: 'constantError', + _active: false, + _activating: false, + _alive: false, + _dispatcher: null, + _logHandlers: null +}); + +function constantError(x) { + return new P$1(x); +} + +function createConstructor(BaseClass, name) { + return function AnonymousObservable(source, options) { + var _this = this; + + BaseClass.call(this); + this._source = source; + this._name = source._name + '.' + name; + this._init(options); + this._$handleAny = function (event) { + return _this._handleAny(event); + }; + }; +} + +function createClassMethods(BaseClass) { + return { + _init: function () {}, + _free: function () {}, + _handleValue: function (x) { + this._emitValue(x); + }, + _handleError: function (x) { + this._emitError(x); + }, + _handleEnd: function () { + this._emitEnd(); + }, + _handleAny: function (event) { + switch (event.type) { + case VALUE: + return this._handleValue(event.value); + case ERROR: + return this._handleError(event.value); + case END: + return this._handleEnd(); + } + }, + _onActivation: function () { + this._source.onAny(this._$handleAny); + }, + _onDeactivation: function () { + this._source.offAny(this._$handleAny); + }, + _clear: function () { + BaseClass.prototype._clear.call(this); + this._source = null; + this._$handleAny = null; + this._free(); + } + }; +} + +function createStream(name, mixin) { + var S = createConstructor(Stream, name); + inherit(S, Stream, createClassMethods(Stream), mixin); + return S; +} + +function createProperty(name, mixin) { + var P = createConstructor(Property, name); + inherit(P, Property, createClassMethods(Property), mixin); + return P; +} + +var P$2 = createProperty('toProperty', { + _init: function (_ref) { + var fn = _ref.fn; + + this._getInitialCurrent = fn; + }, + _onActivation: function () { + if (this._getInitialCurrent !== null) { + var getInitial = this._getInitialCurrent; + this._emitValue(getInitial()); + } + this._source.onAny(this._$handleAny); // copied from patterns/one-source + } +}); + +function toProperty(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + + if (fn !== null && typeof fn !== 'function') { + throw new Error('You should call toProperty() with a function or no arguments.'); + } + return new P$2(obs, { fn: fn }); +} + +var S$6 = createStream('changes', { + _handleValue: function (x) { + if (!this._activating) { + this._emitValue(x); + } + }, + _handleError: function (x) { + if (!this._activating) { + this._emitError(x); + } + } +}); + +function changes(obs) { + return new S$6(obs); +} + +function fromPromise(promise) { + var called = false; + + var result = stream(function (emitter) { + if (!called) { + var onValue = function (x) { + emitter.emit(x); + emitter.end(); + }; + var onError = function (x) { + emitter.error(x); + emitter.end(); + }; + var _promise = promise.then(onValue, onError); + + // prevent libraries like 'Q' or 'when' from swallowing exceptions + if (_promise && typeof _promise.done === 'function') { + _promise.done(); + } + + called = true; + } + }); + + return toProperty(result, null).setName('fromPromise'); +} + +function getGlodalPromise() { + if (typeof Promise === 'function') { + return Promise; + } else { + throw new Error("There isn't default Promise, use shim or parameter"); + } +} + +var toPromise = function (obs) { + var Promise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getGlodalPromise(); + + var last = null; + return new Promise(function (resolve, reject) { + obs.onAny(function (event) { + if (event.type === END && last !== null) { + (last.type === VALUE ? resolve : reject)(last.value); + last = null; + } else { + last = event; + } + }); + }); +}; + +function symbolObservablePonyfill(root) { + var result; + var Symbol = root.Symbol; + + if (typeof Symbol === 'function') { + if (Symbol.observable) { + result = Symbol.observable; + } else { + result = Symbol('observable'); + Symbol.observable = result; + } + } else { + result = '@@observable'; + } + + return result; +} + +/* global window */ +var root; + +if (typeof self !== 'undefined') { + root = self; +} else if (typeof window !== 'undefined') { + root = window; +} else if (typeof global !== 'undefined') { + root = global; +} else if (typeof module !== 'undefined') { + root = module; +} else { + root = Function('return this')(); +} + +var result = symbolObservablePonyfill(root); + +// this file contains some hot JS modules systems stuff + +var $$observable = result.default ? result.default : result; + +function fromESObservable(_observable) { + var observable = _observable[$$observable] ? _observable[$$observable]() : _observable; + return stream(function (emitter) { + var unsub = observable.subscribe({ + error: function (error) { + emitter.error(error); + emitter.end(); + }, + next: function (value) { + emitter.emit(value); + }, + complete: function () { + emitter.end(); + } + }); + + if (unsub.unsubscribe) { + return function () { + unsub.unsubscribe(); + }; + } else { + return unsub; + } + }).setName('fromESObservable'); +} + +function ESObservable(observable) { + this._observable = observable.takeErrors(1); +} + +extend(ESObservable.prototype, { + subscribe: function (observerOrOnNext, onError, onComplete) { + var _this = this; + + var observer = typeof observerOrOnNext === 'function' ? { next: observerOrOnNext, error: onError, complete: onComplete } : observerOrOnNext; + + var fn = function (event) { + if (event.type === END) { + closed = true; + } + + if (event.type === VALUE && observer.next) { + observer.next(event.value); + } else if (event.type === ERROR && observer.error) { + observer.error(event.value); + } else if (event.type === END && observer.complete) { + observer.complete(event.value); + } + }; + + this._observable.onAny(fn); + var closed = false; + + var subscription = { + unsubscribe: function () { + closed = true; + _this._observable.offAny(fn); + }, + get closed() { + return closed; + } + }; + return subscription; + } +}); + +// Need to assign directly b/c Symbols aren't enumerable. +ESObservable.prototype[$$observable] = function () { + return this; +}; + +function toESObservable() { + return new ESObservable(this); +} + +function collect(source, keys, values) { + for (var prop in source) { + if (source.hasOwnProperty(prop)) { + keys.push(prop); + values.push(source[prop]); + } + } +} + +function defaultErrorsCombinator(errors) { + var latestError = void 0; + for (var i = 0; i < errors.length; i++) { + if (errors[i] !== undefined) { + if (latestError === undefined || latestError.index < errors[i].index) { + latestError = errors[i]; + } + } + } + return latestError.error; +} + +function Combine(active, passive, combinator) { + var _this = this; + + Stream.call(this); + this._activeCount = active.length; + this._sources = concat(active, passive); + this._combinator = combinator; + this._aliveCount = 0; + this._latestValues = new Array(this._sources.length); + this._latestErrors = new Array(this._sources.length); + fillArray(this._latestValues, NOTHING); + this._emitAfterActivation = false; + this._endAfterActivation = false; + this._latestErrorIndex = 0; + + this._$handlers = []; + + var _loop = function (i) { + _this._$handlers.push(function (event) { + return _this._handleAny(i, event); + }); + }; + + for (var i = 0; i < this._sources.length; i++) { + _loop(i); + } +} + +inherit(Combine, Stream, { + _name: 'combine', + + _onActivation: function () { + this._aliveCount = this._activeCount; + + // we need to suscribe to _passive_ sources before _active_ + // (see https://github.com/kefirjs/kefir/issues/98) + for (var i = this._activeCount; i < this._sources.length; i++) { + this._sources[i].onAny(this._$handlers[i]); + } + for (var _i = 0; _i < this._activeCount; _i++) { + this._sources[_i].onAny(this._$handlers[_i]); + } + + if (this._emitAfterActivation) { + this._emitAfterActivation = false; + this._emitIfFull(); + } + if (this._endAfterActivation) { + this._emitEnd(); + } + }, + _onDeactivation: function () { + var length = this._sources.length, + i = void 0; + for (i = 0; i < length; i++) { + this._sources[i].offAny(this._$handlers[i]); + } + }, + _emitIfFull: function () { + var hasAllValues = true; + var hasErrors = false; + var length = this._latestValues.length; + var valuesCopy = new Array(length); + var errorsCopy = new Array(length); + + for (var i = 0; i < length; i++) { + valuesCopy[i] = this._latestValues[i]; + errorsCopy[i] = this._latestErrors[i]; + + if (valuesCopy[i] === NOTHING) { + hasAllValues = false; + } + + if (errorsCopy[i] !== undefined) { + hasErrors = true; + } + } + + if (hasAllValues) { + var combinator = this._combinator; + this._emitValue(combinator(valuesCopy)); + } + if (hasErrors) { + this._emitError(defaultErrorsCombinator(errorsCopy)); + } + }, + _handleAny: function (i, event) { + if (event.type === VALUE || event.type === ERROR) { + if (event.type === VALUE) { + this._latestValues[i] = event.value; + this._latestErrors[i] = undefined; + } + if (event.type === ERROR) { + this._latestValues[i] = NOTHING; + this._latestErrors[i] = { + index: this._latestErrorIndex++, + error: event.value + }; + } + + if (i < this._activeCount) { + if (this._activating) { + this._emitAfterActivation = true; + } else { + this._emitIfFull(); + } + } + } else { + // END + + if (i < this._activeCount) { + this._aliveCount--; + if (this._aliveCount === 0) { + if (this._activating) { + this._endAfterActivation = true; + } else { + this._emitEnd(); + } + } + } + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._sources = null; + this._latestValues = null; + this._latestErrors = null; + this._combinator = null; + this._$handlers = null; + } +}); + +function combineAsArray(active) { + var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + var combinator = arguments[2]; + + if (!Array.isArray(passive)) { + throw new Error('Combine can only combine active and passive collections of the same type.'); + } + + combinator = combinator ? spread(combinator, active.length + passive.length) : function (x) { + return x; + }; + return active.length === 0 ? never() : new Combine(active, passive, combinator); +} + +function combineAsObject(active) { + var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var combinator = arguments[2]; + + if (typeof passive !== 'object' || Array.isArray(passive)) { + throw new Error('Combine can only combine active and passive collections of the same type.'); + } + + var keys = [], + activeObservables = [], + passiveObservables = []; + + collect(active, keys, activeObservables); + collect(passive, keys, passiveObservables); + + var objectify = function (values) { + var event = {}; + for (var i = values.length - 1; 0 <= i; i--) { + event[keys[i]] = values[i]; + } + return combinator ? combinator(event) : event; + }; + + return activeObservables.length === 0 ? never() : new Combine(activeObservables, passiveObservables, objectify); +} + +function combine(active, passive, combinator) { + if (typeof passive === 'function') { + combinator = passive; + passive = undefined; + } + + return Array.isArray(active) ? combineAsArray(active, passive, combinator) : combineAsObject(active, passive, combinator); +} + +var Observable$2 = { + empty: function () { + return never(); + }, + + + // Monoid based on merge() seems more useful than one based on concat(). + concat: function (a, b) { + return a.merge(b); + }, + of: function (x) { + return constant(x); + }, + map: function (fn, obs) { + return obs.map(fn); + }, + bimap: function (fnErr, fnVal, obs) { + return obs.mapErrors(fnErr).map(fnVal); + }, + + + // This ap strictly speaking incompatible with chain. If we derive ap from chain we get + // different (not very useful) behavior. But spec requires that if method can be derived + // it must have the same behavior as hand-written method. We intentionally violate the spec + // in hope that it won't cause many troubles in practice. And in return we have more useful type. + ap: function (obsFn, obsVal) { + return combine([obsFn, obsVal], function (fn, val) { + return fn(val); + }); + }, + chain: function (fn, obs) { + return obs.flatMap(fn); + } +}; + + + +var staticLand = Object.freeze({ + Observable: Observable$2 +}); + +var mixin = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + this._emitValue(fn(x)); + } +}; + +var S$7 = createStream('map', mixin); +var P$3 = createProperty('map', mixin); + +var id = function (x) { + return x; +}; + +function map$1(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id; + + return new (obs._ofSameType(S$7, P$3))(obs, { fn: fn }); +} + +var mixin$1 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (fn(x)) { + this._emitValue(x); + } + } +}; + +var S$8 = createStream('filter', mixin$1); +var P$4 = createProperty('filter', mixin$1); + +var id$1 = function (x) { + return x; +}; + +function filter(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$1; + + return new (obs._ofSameType(S$8, P$4))(obs, { fn: fn }); +} + +var mixin$2 = { + _init: function (_ref) { + var n = _ref.n; + + this._n = n; + if (n <= 0) { + this._emitEnd(); + } + }, + _handleValue: function (x) { + if (this._n === 0) { + return; + } + this._n--; + this._emitValue(x); + if (this._n === 0) { + this._emitEnd(); + } + } +}; + +var S$9 = createStream('take', mixin$2); +var P$5 = createProperty('take', mixin$2); + +function take(obs, n) { + return new (obs._ofSameType(S$9, P$5))(obs, { n: n }); +} + +var mixin$3 = { + _init: function (_ref) { + var n = _ref.n; + + this._n = n; + if (n <= 0) { + this._emitEnd(); + } + }, + _handleError: function (x) { + if (this._n === 0) { + return; + } + this._n--; + this._emitError(x); + if (this._n === 0) { + this._emitEnd(); + } + } +}; + +var S$10 = createStream('takeErrors', mixin$3); +var P$6 = createProperty('takeErrors', mixin$3); + +function takeErrors(obs, n) { + return new (obs._ofSameType(S$10, P$6))(obs, { n: n }); +} + +var mixin$4 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (fn(x)) { + this._emitValue(x); + } else { + this._emitEnd(); + } + } +}; + +var S$11 = createStream('takeWhile', mixin$4); +var P$7 = createProperty('takeWhile', mixin$4); + +var id$2 = function (x) { + return x; +}; + +function takeWhile(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$2; + + return new (obs._ofSameType(S$11, P$7))(obs, { fn: fn }); +} + +var mixin$5 = { + _init: function () { + this._lastValue = NOTHING; + }, + _free: function () { + this._lastValue = null; + }, + _handleValue: function (x) { + this._lastValue = x; + }, + _handleEnd: function () { + if (this._lastValue !== NOTHING) { + this._emitValue(this._lastValue); + } + this._emitEnd(); + } +}; + +var S$12 = createStream('last', mixin$5); +var P$8 = createProperty('last', mixin$5); + +function last(obs) { + return new (obs._ofSameType(S$12, P$8))(obs); +} + +var mixin$6 = { + _init: function (_ref) { + var n = _ref.n; + + this._n = Math.max(0, n); + }, + _handleValue: function (x) { + if (this._n === 0) { + this._emitValue(x); + } else { + this._n--; + } + } +}; + +var S$13 = createStream('skip', mixin$6); +var P$9 = createProperty('skip', mixin$6); + +function skip(obs, n) { + return new (obs._ofSameType(S$13, P$9))(obs, { n: n }); +} + +var mixin$7 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (this._fn !== null && !fn(x)) { + this._fn = null; + } + if (this._fn === null) { + this._emitValue(x); + } + } +}; + +var S$14 = createStream('skipWhile', mixin$7); +var P$10 = createProperty('skipWhile', mixin$7); + +var id$3 = function (x) { + return x; +}; + +function skipWhile(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$3; + + return new (obs._ofSameType(S$14, P$10))(obs, { fn: fn }); +} + +var mixin$8 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + this._prev = NOTHING; + }, + _free: function () { + this._fn = null; + this._prev = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (this._prev === NOTHING || !fn(this._prev, x)) { + this._prev = x; + this._emitValue(x); + } + } +}; + +var S$15 = createStream('skipDuplicates', mixin$8); +var P$11 = createProperty('skipDuplicates', mixin$8); + +var eq = function (a, b) { + return a === b; +}; + +function skipDuplicates(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : eq; + + return new (obs._ofSameType(S$15, P$11))(obs, { fn: fn }); +} + +var mixin$9 = { + _init: function (_ref) { + var fn = _ref.fn, + seed = _ref.seed; + + this._fn = fn; + this._prev = seed; + }, + _free: function () { + this._prev = null; + this._fn = null; + }, + _handleValue: function (x) { + if (this._prev !== NOTHING) { + var fn = this._fn; + this._emitValue(fn(this._prev, x)); + } + this._prev = x; + } +}; + +var S$16 = createStream('diff', mixin$9); +var P$12 = createProperty('diff', mixin$9); + +function defaultFn(a, b) { + return [a, b]; +} + +function diff(obs, fn) { + var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NOTHING; + + return new (obs._ofSameType(S$16, P$12))(obs, { fn: fn || defaultFn, seed: seed }); +} + +var P$13 = createProperty('scan', { + _init: function (_ref) { + var fn = _ref.fn, + seed = _ref.seed; + + this._fn = fn; + this._seed = seed; + if (seed !== NOTHING) { + this._emitValue(seed); + } + }, + _free: function () { + this._fn = null; + this._seed = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (this._currentEvent === null || this._currentEvent.type === ERROR) { + this._emitValue(this._seed === NOTHING ? x : fn(this._seed, x)); + } else { + this._emitValue(fn(this._currentEvent.value, x)); + } + } +}); + +function scan(obs, fn) { + var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NOTHING; + + return new P$13(obs, { fn: fn, seed: seed }); +} + +var mixin$10 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + var xs = fn(x); + for (var i = 0; i < xs.length; i++) { + this._emitValue(xs[i]); + } + } +}; + +var S$17 = createStream('flatten', mixin$10); + +var id$4 = function (x) { + return x; +}; + +function flatten(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$4; + + return new S$17(obs, { fn: fn }); +} + +var END_MARKER = {}; + +var mixin$11 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait; + + this._wait = Math.max(0, wait); + this._buff = []; + this._$shiftBuff = function () { + var value = _this._buff.shift(); + if (value === END_MARKER) { + _this._emitEnd(); + } else { + _this._emitValue(value); + } + }; + }, + _free: function () { + this._buff = null; + this._$shiftBuff = null; + }, + _handleValue: function (x) { + if (this._activating) { + this._emitValue(x); + } else { + this._buff.push(x); + setTimeout(this._$shiftBuff, this._wait); + } + }, + _handleEnd: function () { + if (this._activating) { + this._emitEnd(); + } else { + this._buff.push(END_MARKER); + setTimeout(this._$shiftBuff, this._wait); + } + } +}; + +var S$18 = createStream('delay', mixin$11); +var P$14 = createProperty('delay', mixin$11); + +function delay(obs, wait) { + return new (obs._ofSameType(S$18, P$14))(obs, { wait: wait }); +} + +var now = Date.now ? function () { + return Date.now(); +} : function () { + return new Date().getTime(); +}; + +var mixin$12 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait, + leading = _ref.leading, + trailing = _ref.trailing; + + this._wait = Math.max(0, wait); + this._leading = leading; + this._trailing = trailing; + this._trailingValue = null; + this._timeoutId = null; + this._endLater = false; + this._lastCallTime = 0; + this._$trailingCall = function () { + return _this._trailingCall(); + }; + }, + _free: function () { + this._trailingValue = null; + this._$trailingCall = null; + }, + _handleValue: function (x) { + if (this._activating) { + this._emitValue(x); + } else { + var curTime = now(); + if (this._lastCallTime === 0 && !this._leading) { + this._lastCallTime = curTime; + } + var remaining = this._wait - (curTime - this._lastCallTime); + if (remaining <= 0) { + this._cancelTrailing(); + this._lastCallTime = curTime; + this._emitValue(x); + } else if (this._trailing) { + this._cancelTrailing(); + this._trailingValue = x; + this._timeoutId = setTimeout(this._$trailingCall, remaining); + } + } + }, + _handleEnd: function () { + if (this._activating) { + this._emitEnd(); + } else { + if (this._timeoutId) { + this._endLater = true; + } else { + this._emitEnd(); + } + } + }, + _cancelTrailing: function () { + if (this._timeoutId !== null) { + clearTimeout(this._timeoutId); + this._timeoutId = null; + } + }, + _trailingCall: function () { + this._emitValue(this._trailingValue); + this._timeoutId = null; + this._trailingValue = null; + this._lastCallTime = !this._leading ? 0 : now(); + if (this._endLater) { + this._emitEnd(); + } + } +}; + +var S$19 = createStream('throttle', mixin$12); +var P$15 = createProperty('throttle', mixin$12); + +function throttle(obs, wait) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$leading = _ref2.leading, + leading = _ref2$leading === undefined ? true : _ref2$leading, + _ref2$trailing = _ref2.trailing, + trailing = _ref2$trailing === undefined ? true : _ref2$trailing; + + return new (obs._ofSameType(S$19, P$15))(obs, { wait: wait, leading: leading, trailing: trailing }); +} + +var mixin$13 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait, + immediate = _ref.immediate; + + this._wait = Math.max(0, wait); + this._immediate = immediate; + this._lastAttempt = 0; + this._timeoutId = null; + this._laterValue = null; + this._endLater = false; + this._$later = function () { + return _this._later(); + }; + }, + _free: function () { + this._laterValue = null; + this._$later = null; + }, + _handleValue: function (x) { + if (this._activating) { + this._emitValue(x); + } else { + this._lastAttempt = now(); + if (this._immediate && !this._timeoutId) { + this._emitValue(x); + } + if (!this._timeoutId) { + this._timeoutId = setTimeout(this._$later, this._wait); + } + if (!this._immediate) { + this._laterValue = x; + } + } + }, + _handleEnd: function () { + if (this._activating) { + this._emitEnd(); + } else { + if (this._timeoutId && !this._immediate) { + this._endLater = true; + } else { + this._emitEnd(); + } + } + }, + _later: function () { + var last = now() - this._lastAttempt; + if (last < this._wait && last >= 0) { + this._timeoutId = setTimeout(this._$later, this._wait - last); + } else { + this._timeoutId = null; + if (!this._immediate) { + var _laterValue = this._laterValue; + this._laterValue = null; + this._emitValue(_laterValue); + } + if (this._endLater) { + this._emitEnd(); + } + } + } +}; + +var S$20 = createStream('debounce', mixin$13); +var P$16 = createProperty('debounce', mixin$13); + +function debounce(obs, wait) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$immediate = _ref2.immediate, + immediate = _ref2$immediate === undefined ? false : _ref2$immediate; + + return new (obs._ofSameType(S$20, P$16))(obs, { wait: wait, immediate: immediate }); +} + +var mixin$14 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleError: function (x) { + var fn = this._fn; + this._emitError(fn(x)); + } +}; + +var S$21 = createStream('mapErrors', mixin$14); +var P$17 = createProperty('mapErrors', mixin$14); + +var id$5 = function (x) { + return x; +}; + +function mapErrors(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$5; + + return new (obs._ofSameType(S$21, P$17))(obs, { fn: fn }); +} + +var mixin$15 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleError: function (x) { + var fn = this._fn; + if (fn(x)) { + this._emitError(x); + } + } +}; + +var S$22 = createStream('filterErrors', mixin$15); +var P$18 = createProperty('filterErrors', mixin$15); + +var id$6 = function (x) { + return x; +}; + +function filterErrors(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$6; + + return new (obs._ofSameType(S$22, P$18))(obs, { fn: fn }); +} + +var mixin$16 = { + _handleValue: function () {} +}; + +var S$23 = createStream('ignoreValues', mixin$16); +var P$19 = createProperty('ignoreValues', mixin$16); + +function ignoreValues(obs) { + return new (obs._ofSameType(S$23, P$19))(obs); +} + +var mixin$17 = { + _handleError: function () {} +}; + +var S$24 = createStream('ignoreErrors', mixin$17); +var P$20 = createProperty('ignoreErrors', mixin$17); + +function ignoreErrors(obs) { + return new (obs._ofSameType(S$24, P$20))(obs); +} + +var mixin$18 = { + _handleEnd: function () {} +}; + +var S$25 = createStream('ignoreEnd', mixin$18); +var P$21 = createProperty('ignoreEnd', mixin$18); + +function ignoreEnd(obs) { + return new (obs._ofSameType(S$25, P$21))(obs); +} + +var mixin$19 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleEnd: function () { + var fn = this._fn; + this._emitValue(fn()); + this._emitEnd(); + } +}; + +var S$26 = createStream('beforeEnd', mixin$19); +var P$22 = createProperty('beforeEnd', mixin$19); + +function beforeEnd(obs, fn) { + return new (obs._ofSameType(S$26, P$22))(obs, { fn: fn }); +} + +var mixin$20 = { + _init: function (_ref) { + var min = _ref.min, + max = _ref.max; + + this._max = max; + this._min = min; + this._buff = []; + }, + _free: function () { + this._buff = null; + }, + _handleValue: function (x) { + this._buff = slide(this._buff, x, this._max); + if (this._buff.length >= this._min) { + this._emitValue(this._buff); + } + } +}; + +var S$27 = createStream('slidingWindow', mixin$20); +var P$23 = createProperty('slidingWindow', mixin$20); + +function slidingWindow(obs, max) { + var min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + + return new (obs._ofSameType(S$27, P$23))(obs, { min: min, max: max }); +} + +var mixin$21 = { + _init: function (_ref) { + var fn = _ref.fn, + flushOnEnd = _ref.flushOnEnd; + + this._fn = fn; + this._flushOnEnd = flushOnEnd; + this._buff = []; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null && this._buff.length !== 0) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handleValue: function (x) { + this._buff.push(x); + var fn = this._fn; + if (!fn(x)) { + this._flush(); + } + }, + _handleEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + } +}; + +var S$28 = createStream('bufferWhile', mixin$21); +var P$24 = createProperty('bufferWhile', mixin$21); + +var id$7 = function (x) { + return x; +}; + +function bufferWhile(obs, fn) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$flushOnEnd = _ref2.flushOnEnd, + flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd; + + return new (obs._ofSameType(S$28, P$24))(obs, { fn: fn || id$7, flushOnEnd: flushOnEnd }); +} + +var mixin$22 = { + _init: function (_ref) { + var count = _ref.count, + flushOnEnd = _ref.flushOnEnd; + + this._count = count; + this._flushOnEnd = flushOnEnd; + this._buff = []; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null && this._buff.length !== 0) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handleValue: function (x) { + this._buff.push(x); + if (this._buff.length >= this._count) { + this._flush(); + } + }, + _handleEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + } +}; + +var S$29 = createStream('bufferWithCount', mixin$22); +var P$25 = createProperty('bufferWithCount', mixin$22); + +function bufferWhile$1(obs, count) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$flushOnEnd = _ref2.flushOnEnd, + flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd; + + return new (obs._ofSameType(S$29, P$25))(obs, { count: count, flushOnEnd: flushOnEnd }); +} + +var mixin$23 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait, + count = _ref.count, + flushOnEnd = _ref.flushOnEnd; + + this._wait = wait; + this._count = count; + this._flushOnEnd = flushOnEnd; + this._intervalId = null; + this._$onTick = function () { + return _this._flush(); + }; + this._buff = []; + }, + _free: function () { + this._$onTick = null; + this._buff = null; + }, + _flush: function () { + if (this._buff !== null) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handleValue: function (x) { + this._buff.push(x); + if (this._buff.length >= this._count) { + clearInterval(this._intervalId); + this._flush(); + this._intervalId = setInterval(this._$onTick, this._wait); + } + }, + _handleEnd: function () { + if (this._flushOnEnd && this._buff.length !== 0) { + this._flush(); + } + this._emitEnd(); + }, + _onActivation: function () { + this._intervalId = setInterval(this._$onTick, this._wait); + this._source.onAny(this._$handleAny); // copied from patterns/one-source + }, + _onDeactivation: function () { + if (this._intervalId !== null) { + clearInterval(this._intervalId); + this._intervalId = null; + } + this._source.offAny(this._$handleAny); // copied from patterns/one-source + } +}; + +var S$30 = createStream('bufferWithTimeOrCount', mixin$23); +var P$26 = createProperty('bufferWithTimeOrCount', mixin$23); + +function bufferWithTimeOrCount(obs, wait, count) { + var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, + _ref2$flushOnEnd = _ref2.flushOnEnd, + flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd; + + return new (obs._ofSameType(S$30, P$26))(obs, { wait: wait, count: count, flushOnEnd: flushOnEnd }); +} + +function xformForObs(obs) { + return { + '@@transducer/step': function (res, input) { + obs._emitValue(input); + return null; + }, + '@@transducer/result': function () { + obs._emitEnd(); + return null; + } + }; +} + +var mixin$24 = { + _init: function (_ref) { + var transducer = _ref.transducer; + + this._xform = transducer(xformForObs(this)); + }, + _free: function () { + this._xform = null; + }, + _handleValue: function (x) { + if (this._xform['@@transducer/step'](null, x) !== null) { + this._xform['@@transducer/result'](null); + } + }, + _handleEnd: function () { + this._xform['@@transducer/result'](null); + } +}; + +var S$31 = createStream('transduce', mixin$24); +var P$27 = createProperty('transduce', mixin$24); + +function transduce(obs, transducer) { + return new (obs._ofSameType(S$31, P$27))(obs, { transducer: transducer }); +} + +var mixin$25 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._handler = fn; + this._emitter = emitter(this); + }, + _free: function () { + this._handler = null; + this._emitter = null; + }, + _handleAny: function (event) { + this._handler(this._emitter, event); + } +}; + +var S$32 = createStream('withHandler', mixin$25); +var P$28 = createProperty('withHandler', mixin$25); + +function withHandler(obs, fn) { + return new (obs._ofSameType(S$32, P$28))(obs, { fn: fn }); +} + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function Zip(sources, combinator) { + var _this = this; + + Stream.call(this); + + this._buffers = map(sources, function (source) { + return isArray(source) ? cloneArray(source) : []; + }); + this._sources = map(sources, function (source) { + return isArray(source) ? never() : source; + }); + + this._combinator = combinator ? spread(combinator, this._sources.length) : function (x) { + return x; + }; + this._aliveCount = 0; + + this._$handlers = []; + + var _loop = function (i) { + _this._$handlers.push(function (event) { + return _this._handleAny(i, event); + }); + }; + + for (var i = 0; i < this._sources.length; i++) { + _loop(i); + } +} + +inherit(Zip, Stream, { + _name: 'zip', + + _onActivation: function () { + // if all sources are arrays + while (this._isFull()) { + this._emit(); + } + + var length = this._sources.length; + this._aliveCount = length; + for (var i = 0; i < length && this._active; i++) { + this._sources[i].onAny(this._$handlers[i]); + } + }, + _onDeactivation: function () { + for (var i = 0; i < this._sources.length; i++) { + this._sources[i].offAny(this._$handlers[i]); + } + }, + _emit: function () { + var values = new Array(this._buffers.length); + for (var i = 0; i < this._buffers.length; i++) { + values[i] = this._buffers[i].shift(); + } + var combinator = this._combinator; + this._emitValue(combinator(values)); + }, + _isFull: function () { + for (var i = 0; i < this._buffers.length; i++) { + if (this._buffers[i].length === 0) { + return false; + } + } + return true; + }, + _handleAny: function (i, event) { + if (event.type === VALUE) { + this._buffers[i].push(event.value); + if (this._isFull()) { + this._emit(); + } + } + if (event.type === ERROR) { + this._emitError(event.value); + } + if (event.type === END) { + this._aliveCount--; + if (this._aliveCount === 0) { + this._emitEnd(); + } + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._sources = null; + this._buffers = null; + this._combinator = null; + this._$handlers = null; + } +}); + +function zip(observables, combinator /* Function | falsey */) { + return observables.length === 0 ? never() : new Zip(observables, combinator); +} + +var id$8 = function (x) { + return x; +}; + +function AbstractPool() { + var _this = this; + + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$queueLim = _ref.queueLim, + queueLim = _ref$queueLim === undefined ? 0 : _ref$queueLim, + _ref$concurLim = _ref.concurLim, + concurLim = _ref$concurLim === undefined ? -1 : _ref$concurLim, + _ref$drop = _ref.drop, + drop = _ref$drop === undefined ? 'new' : _ref$drop; + + Stream.call(this); + + this._queueLim = queueLim < 0 ? -1 : queueLim; + this._concurLim = concurLim < 0 ? -1 : concurLim; + this._drop = drop; + this._queue = []; + this._curSources = []; + this._$handleSubAny = function (event) { + return _this._handleSubAny(event); + }; + this._$endHandlers = []; + this._currentlyAdding = null; + + if (this._concurLim === 0) { + this._emitEnd(); + } +} + +inherit(AbstractPool, Stream, { + _name: 'abstractPool', + + _add: function (obj, toObs /* Function | falsey */) { + toObs = toObs || id$8; + if (this._concurLim === -1 || this._curSources.length < this._concurLim) { + this._addToCur(toObs(obj)); + } else { + if (this._queueLim === -1 || this._queue.length < this._queueLim) { + this._addToQueue(toObs(obj)); + } else if (this._drop === 'old') { + this._removeOldest(); + this._add(obj, toObs); + } + } + }, + _addAll: function (obss) { + var _this2 = this; + + forEach(obss, function (obs) { + return _this2._add(obs); + }); + }, + _remove: function (obs) { + if (this._removeCur(obs) === -1) { + this._removeQueue(obs); + } + }, + _addToQueue: function (obs) { + this._queue = concat(this._queue, [obs]); + }, + _addToCur: function (obs) { + if (this._active) { + // HACK: + // + // We have two optimizations for cases when `obs` is ended. We don't want + // to add such observable to the list, but only want to emit events + // from it (if it has some). + // + // Instead of this hacks, we could just did following, + // but it would be 5-8 times slower: + // + // this._curSources = concat(this._curSources, [obs]); + // this._subscribe(obs); + // + + // #1 + // This one for cases when `obs` already ended + // e.g., Kefir.constant() or Kefir.never() + if (!obs._alive) { + if (obs._currentEvent) { + this._emit(obs._currentEvent.type, obs._currentEvent.value); + } + // The _emit above could have caused this stream to end. + if (this._active) { + if (this._queue.length !== 0) { + this._pullQueue(); + } else if (this._curSources.length === 0) { + this._onEmpty(); + } + } + return; + } + + // #2 + // This one is for cases when `obs` going to end synchronously on + // first subscriber e.g., Kefir.stream(em => {em.emit(1); em.end()}) + this._currentlyAdding = obs; + obs.onAny(this._$handleSubAny); + this._currentlyAdding = null; + if (obs._alive) { + this._curSources = concat(this._curSources, [obs]); + if (this._active) { + this._subToEnd(obs); + } + } else { + if (this._queue.length !== 0) { + this._pullQueue(); + } else if (this._curSources.length === 0) { + this._onEmpty(); + } + } + } else { + this._curSources = concat(this._curSources, [obs]); + } + }, + _subToEnd: function (obs) { + var _this3 = this; + + var onEnd = function () { + return _this3._removeCur(obs); + }; + this._$endHandlers.push({ obs: obs, handler: onEnd }); + obs.onEnd(onEnd); + }, + _subscribe: function (obs) { + obs.onAny(this._$handleSubAny); + + // it can become inactive in responce of subscribing to `obs.onAny` above + if (this._active) { + this._subToEnd(obs); + } + }, + _unsubscribe: function (obs) { + obs.offAny(this._$handleSubAny); + + var onEndI = findByPred(this._$endHandlers, function (obj) { + return obj.obs === obs; + }); + if (onEndI !== -1) { + obs.offEnd(this._$endHandlers[onEndI].handler); + this._$endHandlers.splice(onEndI, 1); + } + }, + _handleSubAny: function (event) { + if (event.type === VALUE) { + this._emitValue(event.value); + } else if (event.type === ERROR) { + this._emitError(event.value); + } + }, + _removeQueue: function (obs) { + var index = find(this._queue, obs); + this._queue = remove(this._queue, index); + return index; + }, + _removeCur: function (obs) { + if (this._active) { + this._unsubscribe(obs); + } + var index = find(this._curSources, obs); + this._curSources = remove(this._curSources, index); + if (index !== -1) { + if (this._queue.length !== 0) { + this._pullQueue(); + } else if (this._curSources.length === 0) { + this._onEmpty(); + } + } + return index; + }, + _removeOldest: function () { + this._removeCur(this._curSources[0]); + }, + _pullQueue: function () { + if (this._queue.length !== 0) { + this._queue = cloneArray(this._queue); + this._addToCur(this._queue.shift()); + } + }, + _onActivation: function () { + for (var i = 0, sources = this._curSources; i < sources.length && this._active; i++) { + this._subscribe(sources[i]); + } + }, + _onDeactivation: function () { + for (var i = 0, sources = this._curSources; i < sources.length; i++) { + this._unsubscribe(sources[i]); + } + if (this._currentlyAdding !== null) { + this._unsubscribe(this._currentlyAdding); + } + }, + _isEmpty: function () { + return this._curSources.length === 0; + }, + _onEmpty: function () {}, + _clear: function () { + Stream.prototype._clear.call(this); + this._queue = null; + this._curSources = null; + this._$handleSubAny = null; + this._$endHandlers = null; + } +}); + +function Merge(sources) { + AbstractPool.call(this); + this._addAll(sources); + this._initialised = true; +} + +inherit(Merge, AbstractPool, { + _name: 'merge', + + _onEmpty: function () { + if (this._initialised) { + this._emitEnd(); + } + } +}); + +function merge(observables) { + return observables.length === 0 ? never() : new Merge(observables); +} + +function S$33(generator) { + var _this = this; + + Stream.call(this); + this._generator = generator; + this._source = null; + this._inLoop = false; + this._iteration = 0; + this._$handleAny = function (event) { + return _this._handleAny(event); + }; +} + +inherit(S$33, Stream, { + _name: 'repeat', + + _handleAny: function (event) { + if (event.type === END) { + this._source = null; + this._getSource(); + } else { + this._emit(event.type, event.value); + } + }, + _getSource: function () { + if (!this._inLoop) { + this._inLoop = true; + var generator = this._generator; + while (this._source === null && this._alive && this._active) { + this._source = generator(this._iteration++); + if (this._source) { + this._source.onAny(this._$handleAny); + } else { + this._emitEnd(); + } + } + this._inLoop = false; + } + }, + _onActivation: function () { + if (this._source) { + this._source.onAny(this._$handleAny); + } else { + this._getSource(); + } + }, + _onDeactivation: function () { + if (this._source) { + this._source.offAny(this._$handleAny); + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._generator = null; + this._source = null; + this._$handleAny = null; + } +}); + +var repeat = function (generator) { + return new S$33(generator); +}; + +function concat$1(observables) { + return repeat(function (index) { + return observables.length > index ? observables[index] : false; + }).setName('concat'); +} + +function Pool() { + AbstractPool.call(this); +} + +inherit(Pool, AbstractPool, { + _name: 'pool', + + plug: function (obs) { + this._add(obs); + return this; + }, + unplug: function (obs) { + this._remove(obs); + return this; + } +}); + +function FlatMap(source, fn, options) { + var _this = this; + + AbstractPool.call(this, options); + this._source = source; + this._fn = fn; + this._mainEnded = false; + this._lastCurrent = null; + this._$handleMain = function (event) { + return _this._handleMain(event); + }; +} + +inherit(FlatMap, AbstractPool, { + _onActivation: function () { + AbstractPool.prototype._onActivation.call(this); + if (this._active) { + this._source.onAny(this._$handleMain); + } + }, + _onDeactivation: function () { + AbstractPool.prototype._onDeactivation.call(this); + this._source.offAny(this._$handleMain); + this._hadNoEvSinceDeact = true; + }, + _handleMain: function (event) { + if (event.type === VALUE) { + // Is latest value before deactivation survived, and now is 'current' on this activation? + // We don't want to handle such values, to prevent to constantly add + // same observale on each activation/deactivation when our main source + // is a `Kefir.conatant()` for example. + var sameCurr = this._activating && this._hadNoEvSinceDeact && this._lastCurrent === event.value; + if (!sameCurr) { + this._add(event.value, this._fn); + } + this._lastCurrent = event.value; + this._hadNoEvSinceDeact = false; + } + + if (event.type === ERROR) { + this._emitError(event.value); + } + + if (event.type === END) { + if (this._isEmpty()) { + this._emitEnd(); + } else { + this._mainEnded = true; + } + } + }, + _onEmpty: function () { + if (this._mainEnded) { + this._emitEnd(); + } + }, + _clear: function () { + AbstractPool.prototype._clear.call(this); + this._source = null; + this._lastCurrent = null; + this._$handleMain = null; + } +}); + +function FlatMapErrors(source, fn) { + FlatMap.call(this, source, fn); +} + +inherit(FlatMapErrors, FlatMap, { + // Same as in FlatMap, only VALUE/ERROR flipped + _handleMain: function (event) { + if (event.type === ERROR) { + var sameCurr = this._activating && this._hadNoEvSinceDeact && this._lastCurrent === event.value; + if (!sameCurr) { + this._add(event.value, this._fn); + } + this._lastCurrent = event.value; + this._hadNoEvSinceDeact = false; + } + + if (event.type === VALUE) { + this._emitValue(event.value); + } + + if (event.type === END) { + if (this._isEmpty()) { + this._emitEnd(); + } else { + this._mainEnded = true; + } + } + } +}); + +function createConstructor$1(BaseClass, name) { + return function AnonymousObservable(primary, secondary, options) { + var _this = this; + + BaseClass.call(this); + this._primary = primary; + this._secondary = secondary; + this._name = primary._name + '.' + name; + this._lastSecondary = NOTHING; + this._$handleSecondaryAny = function (event) { + return _this._handleSecondaryAny(event); + }; + this._$handlePrimaryAny = function (event) { + return _this._handlePrimaryAny(event); + }; + this._init(options); + }; +} + +function createClassMethods$1(BaseClass) { + return { + _init: function () {}, + _free: function () {}, + _handlePrimaryValue: function (x) { + this._emitValue(x); + }, + _handlePrimaryError: function (x) { + this._emitError(x); + }, + _handlePrimaryEnd: function () { + this._emitEnd(); + }, + _handleSecondaryValue: function (x) { + this._lastSecondary = x; + }, + _handleSecondaryError: function (x) { + this._emitError(x); + }, + _handleSecondaryEnd: function () {}, + _handlePrimaryAny: function (event) { + switch (event.type) { + case VALUE: + return this._handlePrimaryValue(event.value); + case ERROR: + return this._handlePrimaryError(event.value); + case END: + return this._handlePrimaryEnd(event.value); + } + }, + _handleSecondaryAny: function (event) { + switch (event.type) { + case VALUE: + return this._handleSecondaryValue(event.value); + case ERROR: + return this._handleSecondaryError(event.value); + case END: + this._handleSecondaryEnd(event.value); + this._removeSecondary(); + } + }, + _removeSecondary: function () { + if (this._secondary !== null) { + this._secondary.offAny(this._$handleSecondaryAny); + this._$handleSecondaryAny = null; + this._secondary = null; + } + }, + _onActivation: function () { + if (this._secondary !== null) { + this._secondary.onAny(this._$handleSecondaryAny); + } + if (this._active) { + this._primary.onAny(this._$handlePrimaryAny); + } + }, + _onDeactivation: function () { + if (this._secondary !== null) { + this._secondary.offAny(this._$handleSecondaryAny); + } + this._primary.offAny(this._$handlePrimaryAny); + }, + _clear: function () { + BaseClass.prototype._clear.call(this); + this._primary = null; + this._secondary = null; + this._lastSecondary = null; + this._$handleSecondaryAny = null; + this._$handlePrimaryAny = null; + this._free(); + } + }; +} + +function createStream$1(name, mixin) { + var S = createConstructor$1(Stream, name); + inherit(S, Stream, createClassMethods$1(Stream), mixin); + return S; +} + +function createProperty$1(name, mixin) { + var P = createConstructor$1(Property, name); + inherit(P, Property, createClassMethods$1(Property), mixin); + return P; +} + +var mixin$26 = { + _handlePrimaryValue: function (x) { + if (this._lastSecondary !== NOTHING && this._lastSecondary) { + this._emitValue(x); + } + }, + _handleSecondaryEnd: function () { + if (this._lastSecondary === NOTHING || !this._lastSecondary) { + this._emitEnd(); + } + } +}; + +var S$34 = createStream$1('filterBy', mixin$26); +var P$29 = createProperty$1('filterBy', mixin$26); + +function filterBy(primary, secondary) { + return new (primary._ofSameType(S$34, P$29))(primary, secondary); +} + +var id2 = function (_, x) { + return x; +}; + +function sampledBy(passive, active, combinator) { + var _combinator = combinator ? function (a, b) { + return combinator(b, a); + } : id2; + return combine([active], [passive], _combinator).setName(passive, 'sampledBy'); +} + +var mixin$27 = { + _handlePrimaryValue: function (x) { + if (this._lastSecondary !== NOTHING) { + this._emitValue(x); + } + }, + _handleSecondaryEnd: function () { + if (this._lastSecondary === NOTHING) { + this._emitEnd(); + } + } +}; + +var S$35 = createStream$1('skipUntilBy', mixin$27); +var P$30 = createProperty$1('skipUntilBy', mixin$27); + +function skipUntilBy(primary, secondary) { + return new (primary._ofSameType(S$35, P$30))(primary, secondary); +} + +var mixin$28 = { + _handleSecondaryValue: function () { + this._emitEnd(); + } +}; + +var S$36 = createStream$1('takeUntilBy', mixin$28); +var P$31 = createProperty$1('takeUntilBy', mixin$28); + +function takeUntilBy(primary, secondary) { + return new (primary._ofSameType(S$36, P$31))(primary, secondary); +} + +var mixin$29 = { + _init: function () { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$flushOnEnd = _ref.flushOnEnd, + flushOnEnd = _ref$flushOnEnd === undefined ? true : _ref$flushOnEnd; + + this._buff = []; + this._flushOnEnd = flushOnEnd; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handlePrimaryEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + }, + _onActivation: function () { + this._primary.onAny(this._$handlePrimaryAny); + if (this._alive && this._secondary !== null) { + this._secondary.onAny(this._$handleSecondaryAny); + } + }, + _handlePrimaryValue: function (x) { + this._buff.push(x); + }, + _handleSecondaryValue: function () { + this._flush(); + }, + _handleSecondaryEnd: function () { + if (!this._flushOnEnd) { + this._emitEnd(); + } + } +}; + +var S$37 = createStream$1('bufferBy', mixin$29); +var P$32 = createProperty$1('bufferBy', mixin$29); + +function bufferBy(primary, secondary, options /* optional */) { + return new (primary._ofSameType(S$37, P$32))(primary, secondary, options); +} + +var mixin$30 = { + _init: function () { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$flushOnEnd = _ref.flushOnEnd, + flushOnEnd = _ref$flushOnEnd === undefined ? true : _ref$flushOnEnd, + _ref$flushOnChange = _ref.flushOnChange, + flushOnChange = _ref$flushOnChange === undefined ? false : _ref$flushOnChange; + + this._buff = []; + this._flushOnEnd = flushOnEnd; + this._flushOnChange = flushOnChange; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handlePrimaryEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + }, + _handlePrimaryValue: function (x) { + this._buff.push(x); + if (this._lastSecondary !== NOTHING && !this._lastSecondary) { + this._flush(); + } + }, + _handleSecondaryEnd: function () { + if (!this._flushOnEnd && (this._lastSecondary === NOTHING || this._lastSecondary)) { + this._emitEnd(); + } + }, + _handleSecondaryValue: function (x) { + if (this._flushOnChange && !x) { + this._flush(); + } + + // from default _handleSecondaryValue + this._lastSecondary = x; + } +}; + +var S$38 = createStream$1('bufferWhileBy', mixin$30); +var P$33 = createProperty$1('bufferWhileBy', mixin$30); + +function bufferWhileBy(primary, secondary, options /* optional */) { + return new (primary._ofSameType(S$38, P$33))(primary, secondary, options); +} + +var f = function () { + return false; +}; +var t = function () { + return true; +}; + +function awaiting(a, b) { + var result = merge([map$1(a, t), map$1(b, f)]); + result = skipDuplicates(result); + result = toProperty(result, f); + return result.setName(a, 'awaiting'); +} + +var mixin$31 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + var result = fn(x); + if (result.convert) { + this._emitError(result.error); + } else { + this._emitValue(x); + } + } +}; + +var S$39 = createStream('valuesToErrors', mixin$31); +var P$34 = createProperty('valuesToErrors', mixin$31); + +var defFn = function (x) { + return { convert: true, error: x }; +}; + +function valuesToErrors(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defFn; + + return new (obs._ofSameType(S$39, P$34))(obs, { fn: fn }); +} + +var mixin$32 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleError: function (x) { + var fn = this._fn; + var result = fn(x); + if (result.convert) { + this._emitValue(result.value); + } else { + this._emitError(x); + } + } +}; + +var S$40 = createStream('errorsToValues', mixin$32); +var P$35 = createProperty('errorsToValues', mixin$32); + +var defFn$1 = function (x) { + return { convert: true, value: x }; +}; + +function errorsToValues(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defFn$1; + + return new (obs._ofSameType(S$40, P$35))(obs, { fn: fn }); +} + +var mixin$33 = { + _handleError: function (x) { + this._emitError(x); + this._emitEnd(); + } +}; + +var S$41 = createStream('endOnError', mixin$33); +var P$36 = createProperty('endOnError', mixin$33); + +function endOnError(obs) { + return new (obs._ofSameType(S$41, P$36))(obs); +} + +// Create a stream +// ----------------------------------------------------------------------------- + +// () -> Stream +// (number, any) -> Stream +// (number, any) -> Stream +// (number, Array) -> Stream +// (number, Function) -> Stream +// (number, Function) -> Stream +// (Function) -> Stream +// (Function) -> Stream +// Target = {addEventListener, removeEventListener}|{addListener, removeListener}|{on, off} +// (Target, string, Function|undefined) -> Stream +// (Function) -> Stream +// Create a property +// ----------------------------------------------------------------------------- + +// (any) -> Property +// (any) -> Property +// Convert observables +// ----------------------------------------------------------------------------- + +// (Stream|Property, Function|undefined) -> Property +Observable.prototype.toProperty = function (fn) { + return toProperty(this, fn); +}; + +// (Stream|Property) -> Stream +Observable.prototype.changes = function () { + return changes(this); +}; + +// Interoperation with other implimentations +// ----------------------------------------------------------------------------- + +// (Promise) -> Property +// (Stream|Property, Function|undefined) -> Promise +Observable.prototype.toPromise = function (Promise) { + return toPromise(this, Promise); +}; + +// (ESObservable) -> Stream +// (Stream|Property) -> ES7 Observable +Observable.prototype.toESObservable = toESObservable; +Observable.prototype[$$observable] = toESObservable; + +// Modify an observable +// ----------------------------------------------------------------------------- + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.map = function (fn) { + return map$1(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.filter = function (fn) { + return filter(this, fn); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.take = function (n) { + return take(this, n); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.takeErrors = function (n) { + return takeErrors(this, n); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.takeWhile = function (fn) { + return takeWhile(this, fn); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.last = function () { + return last(this); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.skip = function (n) { + return skip(this, n); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.skipWhile = function (fn) { + return skipWhile(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.skipDuplicates = function (fn) { + return skipDuplicates(this, fn); +}; + +// (Stream, Function|falsey, any|undefined) -> Stream +// (Property, Function|falsey, any|undefined) -> Property +Observable.prototype.diff = function (fn, seed) { + return diff(this, fn, seed); +}; + +// (Stream|Property, Function, any|undefined) -> Property +Observable.prototype.scan = function (fn, seed) { + return scan(this, fn, seed); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.flatten = function (fn) { + return flatten(this, fn); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.delay = function (wait) { + return delay(this, wait); +}; + +// Options = {leading: boolean|undefined, trailing: boolean|undefined} +// (Stream, number, Options|undefined) -> Stream +// (Property, number, Options|undefined) -> Property +Observable.prototype.throttle = function (wait, options) { + return throttle(this, wait, options); +}; + +// Options = {immediate: boolean|undefined} +// (Stream, number, Options|undefined) -> Stream +// (Property, number, Options|undefined) -> Property +Observable.prototype.debounce = function (wait, options) { + return debounce(this, wait, options); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.mapErrors = function (fn) { + return mapErrors(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.filterErrors = function (fn) { + return filterErrors(this, fn); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.ignoreValues = function () { + return ignoreValues(this); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.ignoreErrors = function () { + return ignoreErrors(this); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.ignoreEnd = function () { + return ignoreEnd(this); +}; + +// (Stream, Function) -> Stream +// (Property, Function) -> Property +Observable.prototype.beforeEnd = function (fn) { + return beforeEnd(this, fn); +}; + +// (Stream, number, number|undefined) -> Stream +// (Property, number, number|undefined) -> Property +Observable.prototype.slidingWindow = function (max, min) { + return slidingWindow(this, max, min); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, Function|falsey, Options|undefined) -> Stream +// (Property, Function|falsey, Options|undefined) -> Property +Observable.prototype.bufferWhile = function (fn, options) { + return bufferWhile(this, fn, options); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.bufferWithCount = function (count, options) { + return bufferWhile$1(this, count, options); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, number, number, Options|undefined) -> Stream +// (Property, number, number, Options|undefined) -> Property +Observable.prototype.bufferWithTimeOrCount = function (wait, count, options) { + return bufferWithTimeOrCount(this, wait, count, options); +}; + +// (Stream, Function) -> Stream +// (Property, Function) -> Property +Observable.prototype.transduce = function (transducer) { + return transduce(this, transducer); +}; + +// (Stream, Function) -> Stream +// (Property, Function) -> Property +Observable.prototype.withHandler = function (fn) { + return withHandler(this, fn); +}; + +// (Stream, Stream -> a) -> a +// (Property, Property -> a) -> a +Observable.prototype.thru = function (fn) { + return fn(this); +}; + +// Combine observables +// ----------------------------------------------------------------------------- + +// (Array, Function|undefiend) -> Stream +// (Array, Array, Function|undefiend) -> Stream +Observable.prototype.combine = function (other, combinator) { + return combine([this, other], combinator); +}; + +// (Array, Function|undefiend) -> Stream +Observable.prototype.zip = function (other, combinator) { + return zip([this, other], combinator); +}; + +// (Array) -> Stream +Observable.prototype.merge = function (other) { + return merge([this, other]); +}; + +// (Array) -> Stream +Observable.prototype.concat = function (other) { + return concat$1([this, other]); +}; + +// () -> Pool +var pool = function () { + return new Pool(); +}; + +// (Function) -> Stream +// Options = {concurLim: number|undefined, queueLim: number|undefined, drop: 'old'|'new'|undefiend} +// (Stream|Property, Function|falsey, Options|undefined) -> Stream +Observable.prototype.flatMap = function (fn) { + return new FlatMap(this, fn).setName(this, 'flatMap'); +}; +Observable.prototype.flatMapLatest = function (fn) { + return new FlatMap(this, fn, { concurLim: 1, drop: 'old' }).setName(this, 'flatMapLatest'); +}; +Observable.prototype.flatMapFirst = function (fn) { + return new FlatMap(this, fn, { concurLim: 1 }).setName(this, 'flatMapFirst'); +}; +Observable.prototype.flatMapConcat = function (fn) { + return new FlatMap(this, fn, { queueLim: -1, concurLim: 1 }).setName(this, 'flatMapConcat'); +}; +Observable.prototype.flatMapConcurLimit = function (fn, limit) { + return new FlatMap(this, fn, { queueLim: -1, concurLim: limit }).setName(this, 'flatMapConcurLimit'); +}; + +// (Stream|Property, Function|falsey) -> Stream +Observable.prototype.flatMapErrors = function (fn) { + return new FlatMapErrors(this, fn).setName(this, 'flatMapErrors'); +}; + +// Combine two observables +// ----------------------------------------------------------------------------- + +// (Stream, Stream|Property) -> Stream +// (Property, Stream|Property) -> Property +Observable.prototype.filterBy = function (other) { + return filterBy(this, other); +}; + +// (Stream, Stream|Property, Function|undefiend) -> Stream +// (Property, Stream|Property, Function|undefiend) -> Property +Observable.prototype.sampledBy = function (other, combinator) { + return sampledBy(this, other, combinator); +}; + +// (Stream, Stream|Property) -> Stream +// (Property, Stream|Property) -> Property +Observable.prototype.skipUntilBy = function (other) { + return skipUntilBy(this, other); +}; + +// (Stream, Stream|Property) -> Stream +// (Property, Stream|Property) -> Property +Observable.prototype.takeUntilBy = function (other) { + return takeUntilBy(this, other); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, Stream|Property, Options|undefined) -> Stream +// (Property, Stream|Property, Options|undefined) -> Property +Observable.prototype.bufferBy = function (other, options) { + return bufferBy(this, other, options); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, Stream|Property, Options|undefined) -> Stream +// (Property, Stream|Property, Options|undefined) -> Property +Observable.prototype.bufferWhileBy = function (other, options) { + return bufferWhileBy(this, other, options); +}; + +// Deprecated +// ----------------------------------------------------------------------------- + +var DEPRECATION_WARNINGS = true; +function dissableDeprecationWarnings() { + DEPRECATION_WARNINGS = false; +} + +function warn(msg) { + if (DEPRECATION_WARNINGS && console && typeof console.warn === 'function') { + var msg2 = '\nHere is an Error object for you containing the call stack:'; + console.warn(msg, msg2, new Error()); + } +} + +// (Stream|Property, Stream|Property) -> Property +Observable.prototype.awaiting = function (other) { + warn('You are using deprecated .awaiting() method, see https://github.com/kefirjs/kefir/issues/145'); + return awaiting(this, other); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.valuesToErrors = function (fn) { + warn('You are using deprecated .valuesToErrors() method, see https://github.com/kefirjs/kefir/issues/149'); + return valuesToErrors(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.errorsToValues = function (fn) { + warn('You are using deprecated .errorsToValues() method, see https://github.com/kefirjs/kefir/issues/149'); + return errorsToValues(this, fn); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.endOnError = function () { + warn('You are using deprecated .endOnError() method, see https://github.com/kefirjs/kefir/issues/150'); + return endOnError(this); +}; + +// Exports +// -------------------------------------------------------------------------- + +var Kefir = { + Observable: Observable, + Stream: Stream, + Property: Property, + never: never, + later: later, + interval: interval, + sequentially: sequentially, + fromPoll: fromPoll, + withInterval: withInterval, + fromCallback: fromCallback, + fromNodeCallback: fromNodeCallback, + fromEvents: fromEvents, + stream: stream, + constant: constant, + constantError: constantError, + fromPromise: fromPromise, + fromESObservable: fromESObservable, + combine: combine, + zip: zip, + merge: merge, + concat: concat$1, + Pool: Pool, + pool: pool, + repeat: repeat, + staticLand: staticLand +}; + +Kefir.Kefir = Kefir; + +export { dissableDeprecationWarnings, Kefir, Observable, Stream, Property, never, later, interval, sequentially, fromPoll, withInterval, fromCallback, fromNodeCallback, fromEvents, stream, constant, constantError, fromPromise, fromESObservable, combine, zip, merge, concat$1 as concat, Pool, pool, repeat, staticLand };export default Kefir; diff --git a/dist/kefir.js b/dist/kefir.js new file mode 100644 index 00000000..ad7f210f --- /dev/null +++ b/dist/kefir.js @@ -0,0 +1,3703 @@ +/*! Kefir.js v3.8.8 + * https://github.com/kefirjs/kefir + */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (factory((global.Kefir = global.Kefir || {}))); +}(this, (function (exports) { 'use strict'; + +function createObj(proto) { + var F = function () {}; + F.prototype = proto; + return new F(); +} + +function extend(target /*, mixin1, mixin2...*/) { + var length = arguments.length, + i = void 0, + prop = void 0; + for (i = 1; i < length; i++) { + for (prop in arguments[i]) { + target[prop] = arguments[i][prop]; + } + } + return target; +} + +function inherit(Child, Parent /*, mixin1, mixin2...*/) { + var length = arguments.length, + i = void 0; + Child.prototype = createObj(Parent.prototype); + Child.prototype.constructor = Child; + for (i = 2; i < length; i++) { + extend(Child.prototype, arguments[i]); + } + return Child; +} + +var NOTHING = ['']; +var END = 'end'; +var VALUE = 'value'; +var ERROR = 'error'; +var ANY = 'any'; + +function concat(a, b) { + var result = void 0, + length = void 0, + i = void 0, + j = void 0; + if (a.length === 0) { + return b; + } + if (b.length === 0) { + return a; + } + j = 0; + result = new Array(a.length + b.length); + length = a.length; + for (i = 0; i < length; i++, j++) { + result[j] = a[i]; + } + length = b.length; + for (i = 0; i < length; i++, j++) { + result[j] = b[i]; + } + return result; +} + +function find(arr, value) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + if (arr[i] === value) { + return i; + } + } + return -1; +} + +function findByPred(arr, pred) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + if (pred(arr[i])) { + return i; + } + } + return -1; +} + +function cloneArray(input) { + var length = input.length, + result = new Array(length), + i = void 0; + for (i = 0; i < length; i++) { + result[i] = input[i]; + } + return result; +} + +function remove(input, index) { + var length = input.length, + result = void 0, + i = void 0, + j = void 0; + if (index >= 0 && index < length) { + if (length === 1) { + return []; + } else { + result = new Array(length - 1); + for (i = 0, j = 0; i < length; i++) { + if (i !== index) { + result[j] = input[i]; + j++; + } + } + return result; + } + } else { + return input; + } +} + +function map(input, fn) { + var length = input.length, + result = new Array(length), + i = void 0; + for (i = 0; i < length; i++) { + result[i] = fn(input[i]); + } + return result; +} + +function forEach(arr, fn) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + fn(arr[i]); + } +} + +function fillArray(arr, value) { + var length = arr.length, + i = void 0; + for (i = 0; i < length; i++) { + arr[i] = value; + } +} + +function contains(arr, value) { + return find(arr, value) !== -1; +} + +function slide(cur, next, max) { + var length = Math.min(max, cur.length + 1), + offset = cur.length - length + 1, + result = new Array(length), + i = void 0; + for (i = offset; i < length; i++) { + result[i - offset] = cur[i]; + } + result[length - 1] = next; + return result; +} + +function callSubscriber(type, fn, event) { + if (type === ANY) { + fn(event); + } else if (type === event.type) { + if (type === VALUE || type === ERROR) { + fn(event.value); + } else { + fn(); + } + } +} + +function Dispatcher() { + this._items = []; + this._spies = []; + this._inLoop = 0; + this._removedItems = null; +} + +extend(Dispatcher.prototype, { + add: function (type, fn) { + this._items = concat(this._items, [{ type: type, fn: fn }]); + return this._items.length; + }, + remove: function (type, fn) { + var index = findByPred(this._items, function (x) { + return x.type === type && x.fn === fn; + }); + + // if we're currently in a notification loop, + // remember this subscriber was removed + if (this._inLoop !== 0 && index !== -1) { + if (this._removedItems === null) { + this._removedItems = []; + } + this._removedItems.push(this._items[index]); + } + + this._items = remove(this._items, index); + return this._items.length; + }, + addSpy: function (fn) { + this._spies = concat(this._spies, [fn]); + return this._spies.length; + }, + + + // Because spies are only ever a function that perform logging as + // their only side effect, we don't need the same complicated + // removal logic like in remove() + removeSpy: function (fn) { + this._spies = remove(this._spies, this._spies.indexOf(fn)); + return this._spies.length; + }, + dispatch: function (event) { + this._inLoop++; + for (var i = 0, spies = this._spies; this._spies !== null && i < spies.length; i++) { + spies[i](event); + } + + for (var _i = 0, items = this._items; _i < items.length; _i++) { + // cleanup was called + if (this._items === null) { + break; + } + + // this subscriber was removed + if (this._removedItems !== null && contains(this._removedItems, items[_i])) { + continue; + } + + callSubscriber(items[_i].type, items[_i].fn, event); + } + this._inLoop--; + if (this._inLoop === 0) { + this._removedItems = null; + } + }, + cleanup: function () { + this._items = null; + this._spies = null; + } +}); + +exports.activeObservables = []; + +function clearActiveObservables() { + exports.activeObservables = []; +} + +/* dev-code */ +/* end-dev-code */ + +function Observable() { + this._dispatcher = new Dispatcher(); + this._active = false; + this._alive = true; + this._activating = false; + this._logHandlers = null; + this._spyHandlers = null; +} + +extend(Observable.prototype, { + _name: 'observable', + + _onActivation: function () { + /* dev-code */ + exports.activeObservables.push(this); + /* end-dev-code */ + }, + _onDeactivation: function () { + /* dev-code */ + exports.activeObservables.splice(exports.activeObservables.indexOf(this), 1); + /* end-dev-code */ + }, + _setActive: function (active) { + if (this._active !== active) { + this._active = active; + if (active) { + this._activating = true; + this._onActivation(); + this._activating = false; + } else { + this._onDeactivation(); + } + } + }, + _clear: function () { + this._setActive(false); + this._dispatcher.cleanup(); + this._dispatcher = null; + this._logHandlers = null; + }, + _emit: function (type, x) { + switch (type) { + case VALUE: + return this._emitValue(x); + case ERROR: + return this._emitError(x); + case END: + return this._emitEnd(); + } + }, + _emitValue: function (value) { + if (this._alive) { + this._dispatcher.dispatch({ type: VALUE, value: value }); + } + }, + _emitError: function (value) { + if (this._alive) { + this._dispatcher.dispatch({ type: ERROR, value: value }); + } + }, + _emitEnd: function () { + if (this._alive) { + this._alive = false; + this._dispatcher.dispatch({ type: END }); + this._clear(); + } + }, + _on: function (type, fn) { + if (this._alive) { + this._dispatcher.add(type, fn); + this._setActive(true); + } else { + callSubscriber(type, fn, { type: END }); + } + return this; + }, + _off: function (type, fn) { + if (this._alive) { + var count = this._dispatcher.remove(type, fn); + if (count === 0) { + this._setActive(false); + } + } + return this; + }, + onValue: function (fn) { + return this._on(VALUE, fn); + }, + onError: function (fn) { + return this._on(ERROR, fn); + }, + onEnd: function (fn) { + return this._on(END, fn); + }, + onAny: function (fn) { + return this._on(ANY, fn); + }, + offValue: function (fn) { + return this._off(VALUE, fn); + }, + offError: function (fn) { + return this._off(ERROR, fn); + }, + offEnd: function (fn) { + return this._off(END, fn); + }, + offAny: function (fn) { + return this._off(ANY, fn); + }, + observe: function (observerOrOnValue, onError, onEnd) { + var _this = this; + var closed = false; + + var observer = !observerOrOnValue || typeof observerOrOnValue === 'function' ? { value: observerOrOnValue, error: onError, end: onEnd } : observerOrOnValue; + + var handler = function (event) { + if (event.type === END) { + closed = true; + } + if (event.type === VALUE && observer.value) { + observer.value(event.value); + } else if (event.type === ERROR && observer.error) { + observer.error(event.value); + } else if (event.type === END && observer.end) { + observer.end(event.value); + } + }; + + this.onAny(handler); + + return { + unsubscribe: function () { + if (!closed) { + _this.offAny(handler); + closed = true; + } + }, + + get closed() { + return closed; + } + }; + }, + + + // A and B must be subclasses of Stream and Property (order doesn't matter) + _ofSameType: function (A, B) { + return A.prototype.getType() === this.getType() ? A : B; + }, + setName: function (sourceObs /* optional */, selfName) { + this._name = selfName ? sourceObs._name + '.' + selfName : sourceObs; + return this; + }, + log: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + var isCurrent = void 0; + var handler = function (event) { + var type = '<' + event.type + (isCurrent ? ':current' : '') + '>'; + if (event.type === END) { + console.log(name, type); + } else { + console.log(name, type, event.value); + } + }; + + if (this._alive) { + if (!this._logHandlers) { + this._logHandlers = []; + } + this._logHandlers.push({ name: name, handler: handler }); + } + + isCurrent = true; + this.onAny(handler); + isCurrent = false; + + return this; + }, + offLog: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + if (this._logHandlers) { + var handlerIndex = findByPred(this._logHandlers, function (obj) { + return obj.name === name; + }); + if (handlerIndex !== -1) { + this.offAny(this._logHandlers[handlerIndex].handler); + this._logHandlers.splice(handlerIndex, 1); + } + } + + return this; + }, + spy: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + var handler = function (event) { + var type = '<' + event.type + '>'; + if (event.type === END) { + console.log(name, type); + } else { + console.log(name, type, event.value); + } + }; + if (this._alive) { + if (!this._spyHandlers) { + this._spyHandlers = []; + } + this._spyHandlers.push({ name: name, handler: handler }); + this._dispatcher.addSpy(handler); + } + return this; + }, + offSpy: function () { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.toString(); + + if (this._spyHandlers) { + var handlerIndex = findByPred(this._spyHandlers, function (obj) { + return obj.name === name; + }); + if (handlerIndex !== -1) { + this._dispatcher.removeSpy(this._spyHandlers[handlerIndex].handler); + this._spyHandlers.splice(handlerIndex, 1); + } + } + return this; + } +}); + +// extend() can't handle `toString` in IE8 +Observable.prototype.toString = function () { + return '[' + this._name + ']'; +}; + +function Stream() { + Observable.call(this); +} + +inherit(Stream, Observable, { + _name: 'stream', + + getType: function () { + return 'stream'; + } +}); + +function Property() { + Observable.call(this); + this._currentEvent = null; +} + +inherit(Property, Observable, { + _name: 'property', + + _emitValue: function (value) { + if (this._alive) { + this._currentEvent = { type: VALUE, value: value }; + if (!this._activating) { + this._dispatcher.dispatch({ type: VALUE, value: value }); + } + } + }, + _emitError: function (value) { + if (this._alive) { + this._currentEvent = { type: ERROR, value: value }; + if (!this._activating) { + this._dispatcher.dispatch({ type: ERROR, value: value }); + } + } + }, + _emitEnd: function () { + if (this._alive) { + this._alive = false; + if (!this._activating) { + this._dispatcher.dispatch({ type: END }); + } + this._clear(); + } + }, + _on: function (type, fn) { + if (this._alive) { + this._dispatcher.add(type, fn); + this._setActive(true); + } + if (this._currentEvent !== null) { + callSubscriber(type, fn, this._currentEvent); + } + if (!this._alive) { + callSubscriber(type, fn, { type: END }); + } + return this; + }, + getType: function () { + return 'property'; + } +}); + +var neverS = new Stream(); +neverS._emitEnd(); +neverS._name = 'never'; + +function never() { + return neverS; +} + +function timeBased(mixin) { + function AnonymousStream(wait, options) { + var _this = this; + + Stream.call(this); + this._wait = wait; + this._intervalId = null; + this._$onTick = function () { + return _this._onTick(); + }; + this._init(options); + } + + inherit(AnonymousStream, Stream, { + _init: function () {}, + _free: function () {}, + _onTick: function () {}, + _onActivation: function () { + this._intervalId = setInterval(this._$onTick, this._wait); + }, + _onDeactivation: function () { + if (this._intervalId !== null) { + clearInterval(this._intervalId); + this._intervalId = null; + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._$onTick = null; + this._free(); + } + }, mixin); + + return AnonymousStream; +} + +var S = timeBased({ + _name: 'later', + + _init: function (_ref) { + var x = _ref.x; + + this._x = x; + }, + _free: function () { + this._x = null; + }, + _onTick: function () { + this._emitValue(this._x); + this._emitEnd(); + } +}); + +function later(wait, x) { + return new S(wait, { x: x }); +} + +var S$1 = timeBased({ + _name: 'interval', + + _init: function (_ref) { + var x = _ref.x; + + this._x = x; + }, + _free: function () { + this._x = null; + }, + _onTick: function () { + this._emitValue(this._x); + } +}); + +function interval(wait, x) { + return new S$1(wait, { x: x }); +} + +var S$2 = timeBased({ + _name: 'sequentially', + + _init: function (_ref) { + var xs = _ref.xs; + + this._xs = cloneArray(xs); + }, + _free: function () { + this._xs = null; + }, + _onTick: function () { + if (this._xs.length === 1) { + this._emitValue(this._xs[0]); + this._emitEnd(); + } else { + this._emitValue(this._xs.shift()); + } + } +}); + +function sequentially(wait, xs) { + return xs.length === 0 ? never() : new S$2(wait, { xs: xs }); +} + +var S$3 = timeBased({ + _name: 'fromPoll', + + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _onTick: function () { + var fn = this._fn; + this._emitValue(fn()); + } +}); + +function fromPoll(wait, fn) { + return new S$3(wait, { fn: fn }); +} + +function emitter(obs) { + function value(x) { + obs._emitValue(x); + return obs._active; + } + + function error(x) { + obs._emitError(x); + return obs._active; + } + + function end() { + obs._emitEnd(); + return obs._active; + } + + function event(e) { + obs._emit(e.type, e.value); + return obs._active; + } + + return { + value: value, + error: error, + end: end, + event: event, + + // legacy + emit: value, + emitEvent: event + }; +} + +var S$4 = timeBased({ + _name: 'withInterval', + + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + this._emitter = emitter(this); + }, + _free: function () { + this._fn = null; + this._emitter = null; + }, + _onTick: function () { + var fn = this._fn; + fn(this._emitter); + } +}); + +function withInterval(wait, fn) { + return new S$4(wait, { fn: fn }); +} + +function S$5(fn) { + Stream.call(this); + this._fn = fn; + this._unsubscribe = null; +} + +inherit(S$5, Stream, { + _name: 'stream', + + _onActivation: function () { + var fn = this._fn; + var unsubscribe = fn(emitter(this)); + this._unsubscribe = typeof unsubscribe === 'function' ? unsubscribe : null; + + // fix https://github.com/kefirjs/kefir/issues/35 + if (!this._active) { + this._callUnsubscribe(); + } + }, + _callUnsubscribe: function () { + if (this._unsubscribe !== null) { + this._unsubscribe(); + this._unsubscribe = null; + } + }, + _onDeactivation: function () { + this._callUnsubscribe(); + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._fn = null; + } +}); + +function stream(fn) { + return new S$5(fn); +} + +function fromCallback(callbackConsumer) { + var called = false; + + return stream(function (emitter) { + if (!called) { + callbackConsumer(function (x) { + emitter.emit(x); + emitter.end(); + }); + called = true; + } + }).setName('fromCallback'); +} + +function fromNodeCallback(callbackConsumer) { + var called = false; + + return stream(function (emitter) { + if (!called) { + callbackConsumer(function (error, x) { + if (error) { + emitter.error(error); + } else { + emitter.emit(x); + } + emitter.end(); + }); + called = true; + } + }).setName('fromNodeCallback'); +} + +function spread(fn, length) { + switch (length) { + case 0: + return function () { + return fn(); + }; + case 1: + return function (a) { + return fn(a[0]); + }; + case 2: + return function (a) { + return fn(a[0], a[1]); + }; + case 3: + return function (a) { + return fn(a[0], a[1], a[2]); + }; + case 4: + return function (a) { + return fn(a[0], a[1], a[2], a[3]); + }; + default: + return function (a) { + return fn.apply(null, a); + }; + } +} + +function apply(fn, c, a) { + var aLength = a ? a.length : 0; + if (c == null) { + switch (aLength) { + case 0: + return fn(); + case 1: + return fn(a[0]); + case 2: + return fn(a[0], a[1]); + case 3: + return fn(a[0], a[1], a[2]); + case 4: + return fn(a[0], a[1], a[2], a[3]); + default: + return fn.apply(null, a); + } + } else { + switch (aLength) { + case 0: + return fn.call(c); + default: + return fn.apply(c, a); + } + } +} + +function fromSubUnsub(sub, unsub, transformer /* Function | falsey */) { + return stream(function (emitter) { + var handler = transformer ? function () { + emitter.emit(apply(transformer, this, arguments)); + } : function (x) { + emitter.emit(x); + }; + + sub(handler); + return function () { + return unsub(handler); + }; + }).setName('fromSubUnsub'); +} + +var pairs = [['addEventListener', 'removeEventListener'], ['addListener', 'removeListener'], ['on', 'off']]; + +function fromEvents(target, eventName, transformer) { + var sub = void 0, + unsub = void 0; + + for (var i = 0; i < pairs.length; i++) { + if (typeof target[pairs[i][0]] === 'function' && typeof target[pairs[i][1]] === 'function') { + sub = pairs[i][0]; + unsub = pairs[i][1]; + break; + } + } + + if (sub === undefined) { + throw new Error("target don't support any of " + 'addEventListener/removeEventListener, addListener/removeListener, on/off method pair'); + } + + return fromSubUnsub(function (handler) { + return target[sub](eventName, handler); + }, function (handler) { + return target[unsub](eventName, handler); + }, transformer).setName('fromEvents'); +} + +// HACK: +// We don't call parent Class constructor, but instead putting all necessary +// properties into prototype to simulate ended Property +// (see Propperty and Observable classes). + +function P(value) { + this._currentEvent = { type: 'value', value: value, current: true }; +} + +inherit(P, Property, { + _name: 'constant', + _active: false, + _activating: false, + _alive: false, + _dispatcher: null, + _logHandlers: null +}); + +function constant(x) { + return new P(x); +} + +// HACK: +// We don't call parent Class constructor, but instead putting all necessary +// properties into prototype to simulate ended Property +// (see Propperty and Observable classes). + +function P$1(value) { + this._currentEvent = { type: 'error', value: value, current: true }; +} + +inherit(P$1, Property, { + _name: 'constantError', + _active: false, + _activating: false, + _alive: false, + _dispatcher: null, + _logHandlers: null +}); + +function constantError(x) { + return new P$1(x); +} + +function createConstructor(BaseClass, name) { + return function AnonymousObservable(source, options) { + var _this = this; + + BaseClass.call(this); + this._source = source; + this._name = source._name + '.' + name; + this._init(options); + this._$handleAny = function (event) { + return _this._handleAny(event); + }; + }; +} + +function createClassMethods(BaseClass) { + return { + _init: function () {}, + _free: function () {}, + _handleValue: function (x) { + this._emitValue(x); + }, + _handleError: function (x) { + this._emitError(x); + }, + _handleEnd: function () { + this._emitEnd(); + }, + _handleAny: function (event) { + switch (event.type) { + case VALUE: + return this._handleValue(event.value); + case ERROR: + return this._handleError(event.value); + case END: + return this._handleEnd(); + } + }, + _onActivation: function () { + this._source.onAny(this._$handleAny); + }, + _onDeactivation: function () { + this._source.offAny(this._$handleAny); + }, + _clear: function () { + BaseClass.prototype._clear.call(this); + this._source = null; + this._$handleAny = null; + this._free(); + } + }; +} + +function createStream(name, mixin) { + var S = createConstructor(Stream, name); + inherit(S, Stream, createClassMethods(Stream), mixin); + return S; +} + +function createProperty(name, mixin) { + var P = createConstructor(Property, name); + inherit(P, Property, createClassMethods(Property), mixin); + return P; +} + +var P$2 = createProperty('toProperty', { + _init: function (_ref) { + var fn = _ref.fn; + + this._getInitialCurrent = fn; + }, + _onActivation: function () { + if (this._getInitialCurrent !== null) { + var getInitial = this._getInitialCurrent; + this._emitValue(getInitial()); + } + this._source.onAny(this._$handleAny); // copied from patterns/one-source + } +}); + +function toProperty(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + + if (fn !== null && typeof fn !== 'function') { + throw new Error('You should call toProperty() with a function or no arguments.'); + } + return new P$2(obs, { fn: fn }); +} + +var S$6 = createStream('changes', { + _handleValue: function (x) { + if (!this._activating) { + this._emitValue(x); + } + }, + _handleError: function (x) { + if (!this._activating) { + this._emitError(x); + } + } +}); + +function changes(obs) { + return new S$6(obs); +} + +function fromPromise(promise) { + var called = false; + + var result = stream(function (emitter) { + if (!called) { + var onValue = function (x) { + emitter.emit(x); + emitter.end(); + }; + var onError = function (x) { + emitter.error(x); + emitter.end(); + }; + var _promise = promise.then(onValue, onError); + + // prevent libraries like 'Q' or 'when' from swallowing exceptions + if (_promise && typeof _promise.done === 'function') { + _promise.done(); + } + + called = true; + } + }); + + return toProperty(result, null).setName('fromPromise'); +} + +function getGlodalPromise() { + if (typeof Promise === 'function') { + return Promise; + } else { + throw new Error("There isn't default Promise, use shim or parameter"); + } +} + +var toPromise = function (obs) { + var Promise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getGlodalPromise(); + + var last = null; + return new Promise(function (resolve, reject) { + obs.onAny(function (event) { + if (event.type === END && last !== null) { + (last.type === VALUE ? resolve : reject)(last.value); + last = null; + } else { + last = event; + } + }); + }); +}; + +function symbolObservablePonyfill(root) { + var result; + var Symbol = root.Symbol; + + if (typeof Symbol === 'function') { + if (Symbol.observable) { + result = Symbol.observable; + } else { + result = Symbol('observable'); + Symbol.observable = result; + } + } else { + result = '@@observable'; + } + + return result; +} + +/* global window */ +var root; + +if (typeof self !== 'undefined') { + root = self; +} else if (typeof window !== 'undefined') { + root = window; +} else if (typeof global !== 'undefined') { + root = global; +} else if (typeof module !== 'undefined') { + root = module; +} else { + root = Function('return this')(); +} + +var result = symbolObservablePonyfill(root); + +// this file contains some hot JS modules systems stuff + +var $$observable = result.default ? result.default : result; + +function fromESObservable(_observable) { + var observable = _observable[$$observable] ? _observable[$$observable]() : _observable; + return stream(function (emitter) { + var unsub = observable.subscribe({ + error: function (error) { + emitter.error(error); + emitter.end(); + }, + next: function (value) { + emitter.emit(value); + }, + complete: function () { + emitter.end(); + } + }); + + if (unsub.unsubscribe) { + return function () { + unsub.unsubscribe(); + }; + } else { + return unsub; + } + }).setName('fromESObservable'); +} + +function ESObservable(observable) { + this._observable = observable.takeErrors(1); +} + +extend(ESObservable.prototype, { + subscribe: function (observerOrOnNext, onError, onComplete) { + var _this = this; + + var observer = typeof observerOrOnNext === 'function' ? { next: observerOrOnNext, error: onError, complete: onComplete } : observerOrOnNext; + + var fn = function (event) { + if (event.type === END) { + closed = true; + } + + if (event.type === VALUE && observer.next) { + observer.next(event.value); + } else if (event.type === ERROR && observer.error) { + observer.error(event.value); + } else if (event.type === END && observer.complete) { + observer.complete(event.value); + } + }; + + this._observable.onAny(fn); + var closed = false; + + var subscription = { + unsubscribe: function () { + closed = true; + _this._observable.offAny(fn); + }, + get closed() { + return closed; + } + }; + return subscription; + } +}); + +// Need to assign directly b/c Symbols aren't enumerable. +ESObservable.prototype[$$observable] = function () { + return this; +}; + +function toESObservable() { + return new ESObservable(this); +} + +function collect(source, keys, values) { + for (var prop in source) { + if (source.hasOwnProperty(prop)) { + keys.push(prop); + values.push(source[prop]); + } + } +} + +function defaultErrorsCombinator(errors) { + var latestError = void 0; + for (var i = 0; i < errors.length; i++) { + if (errors[i] !== undefined) { + if (latestError === undefined || latestError.index < errors[i].index) { + latestError = errors[i]; + } + } + } + return latestError.error; +} + +function Combine(active, passive, combinator) { + var _this = this; + + Stream.call(this); + this._activeCount = active.length; + this._sources = concat(active, passive); + this._combinator = combinator; + this._aliveCount = 0; + this._latestValues = new Array(this._sources.length); + this._latestErrors = new Array(this._sources.length); + fillArray(this._latestValues, NOTHING); + this._emitAfterActivation = false; + this._endAfterActivation = false; + this._latestErrorIndex = 0; + + this._$handlers = []; + + var _loop = function (i) { + _this._$handlers.push(function (event) { + return _this._handleAny(i, event); + }); + }; + + for (var i = 0; i < this._sources.length; i++) { + _loop(i); + } +} + +inherit(Combine, Stream, { + _name: 'combine', + + _onActivation: function () { + this._aliveCount = this._activeCount; + + // we need to suscribe to _passive_ sources before _active_ + // (see https://github.com/kefirjs/kefir/issues/98) + for (var i = this._activeCount; i < this._sources.length; i++) { + this._sources[i].onAny(this._$handlers[i]); + } + for (var _i = 0; _i < this._activeCount; _i++) { + this._sources[_i].onAny(this._$handlers[_i]); + } + + if (this._emitAfterActivation) { + this._emitAfterActivation = false; + this._emitIfFull(); + } + if (this._endAfterActivation) { + this._emitEnd(); + } + }, + _onDeactivation: function () { + var length = this._sources.length, + i = void 0; + for (i = 0; i < length; i++) { + this._sources[i].offAny(this._$handlers[i]); + } + }, + _emitIfFull: function () { + var hasAllValues = true; + var hasErrors = false; + var length = this._latestValues.length; + var valuesCopy = new Array(length); + var errorsCopy = new Array(length); + + for (var i = 0; i < length; i++) { + valuesCopy[i] = this._latestValues[i]; + errorsCopy[i] = this._latestErrors[i]; + + if (valuesCopy[i] === NOTHING) { + hasAllValues = false; + } + + if (errorsCopy[i] !== undefined) { + hasErrors = true; + } + } + + if (hasAllValues) { + var combinator = this._combinator; + this._emitValue(combinator(valuesCopy)); + } + if (hasErrors) { + this._emitError(defaultErrorsCombinator(errorsCopy)); + } + }, + _handleAny: function (i, event) { + if (event.type === VALUE || event.type === ERROR) { + if (event.type === VALUE) { + this._latestValues[i] = event.value; + this._latestErrors[i] = undefined; + } + if (event.type === ERROR) { + this._latestValues[i] = NOTHING; + this._latestErrors[i] = { + index: this._latestErrorIndex++, + error: event.value + }; + } + + if (i < this._activeCount) { + if (this._activating) { + this._emitAfterActivation = true; + } else { + this._emitIfFull(); + } + } + } else { + // END + + if (i < this._activeCount) { + this._aliveCount--; + if (this._aliveCount === 0) { + if (this._activating) { + this._endAfterActivation = true; + } else { + this._emitEnd(); + } + } + } + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._sources = null; + this._latestValues = null; + this._latestErrors = null; + this._combinator = null; + this._$handlers = null; + } +}); + +function combineAsArray(active) { + var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + var combinator = arguments[2]; + + if (!Array.isArray(passive)) { + throw new Error('Combine can only combine active and passive collections of the same type.'); + } + + combinator = combinator ? spread(combinator, active.length + passive.length) : function (x) { + return x; + }; + return active.length === 0 ? never() : new Combine(active, passive, combinator); +} + +function combineAsObject(active) { + var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var combinator = arguments[2]; + + if (typeof passive !== 'object' || Array.isArray(passive)) { + throw new Error('Combine can only combine active and passive collections of the same type.'); + } + + var keys = [], + activeObservables = [], + passiveObservables = []; + + collect(active, keys, activeObservables); + collect(passive, keys, passiveObservables); + + var objectify = function (values) { + var event = {}; + for (var i = values.length - 1; 0 <= i; i--) { + event[keys[i]] = values[i]; + } + return combinator ? combinator(event) : event; + }; + + return activeObservables.length === 0 ? never() : new Combine(activeObservables, passiveObservables, objectify); +} + +function combine(active, passive, combinator) { + if (typeof passive === 'function') { + combinator = passive; + passive = undefined; + } + + return Array.isArray(active) ? combineAsArray(active, passive, combinator) : combineAsObject(active, passive, combinator); +} + +var Observable$2 = { + empty: function () { + return never(); + }, + + + // Monoid based on merge() seems more useful than one based on concat(). + concat: function (a, b) { + return a.merge(b); + }, + of: function (x) { + return constant(x); + }, + map: function (fn, obs) { + return obs.map(fn); + }, + bimap: function (fnErr, fnVal, obs) { + return obs.mapErrors(fnErr).map(fnVal); + }, + + + // This ap strictly speaking incompatible with chain. If we derive ap from chain we get + // different (not very useful) behavior. But spec requires that if method can be derived + // it must have the same behavior as hand-written method. We intentionally violate the spec + // in hope that it won't cause many troubles in practice. And in return we have more useful type. + ap: function (obsFn, obsVal) { + return combine([obsFn, obsVal], function (fn, val) { + return fn(val); + }); + }, + chain: function (fn, obs) { + return obs.flatMap(fn); + } +}; + + + +var staticLand = Object.freeze({ + Observable: Observable$2 +}); + +var mixin = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + this._emitValue(fn(x)); + } +}; + +var S$7 = createStream('map', mixin); +var P$3 = createProperty('map', mixin); + +var id = function (x) { + return x; +}; + +function map$1(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id; + + return new (obs._ofSameType(S$7, P$3))(obs, { fn: fn }); +} + +var mixin$1 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (fn(x)) { + this._emitValue(x); + } + } +}; + +var S$8 = createStream('filter', mixin$1); +var P$4 = createProperty('filter', mixin$1); + +var id$1 = function (x) { + return x; +}; + +function filter(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$1; + + return new (obs._ofSameType(S$8, P$4))(obs, { fn: fn }); +} + +var mixin$2 = { + _init: function (_ref) { + var n = _ref.n; + + this._n = n; + if (n <= 0) { + this._emitEnd(); + } + }, + _handleValue: function (x) { + if (this._n === 0) { + return; + } + this._n--; + this._emitValue(x); + if (this._n === 0) { + this._emitEnd(); + } + } +}; + +var S$9 = createStream('take', mixin$2); +var P$5 = createProperty('take', mixin$2); + +function take(obs, n) { + return new (obs._ofSameType(S$9, P$5))(obs, { n: n }); +} + +var mixin$3 = { + _init: function (_ref) { + var n = _ref.n; + + this._n = n; + if (n <= 0) { + this._emitEnd(); + } + }, + _handleError: function (x) { + if (this._n === 0) { + return; + } + this._n--; + this._emitError(x); + if (this._n === 0) { + this._emitEnd(); + } + } +}; + +var S$10 = createStream('takeErrors', mixin$3); +var P$6 = createProperty('takeErrors', mixin$3); + +function takeErrors(obs, n) { + return new (obs._ofSameType(S$10, P$6))(obs, { n: n }); +} + +var mixin$4 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (fn(x)) { + this._emitValue(x); + } else { + this._emitEnd(); + } + } +}; + +var S$11 = createStream('takeWhile', mixin$4); +var P$7 = createProperty('takeWhile', mixin$4); + +var id$2 = function (x) { + return x; +}; + +function takeWhile(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$2; + + return new (obs._ofSameType(S$11, P$7))(obs, { fn: fn }); +} + +var mixin$5 = { + _init: function () { + this._lastValue = NOTHING; + }, + _free: function () { + this._lastValue = null; + }, + _handleValue: function (x) { + this._lastValue = x; + }, + _handleEnd: function () { + if (this._lastValue !== NOTHING) { + this._emitValue(this._lastValue); + } + this._emitEnd(); + } +}; + +var S$12 = createStream('last', mixin$5); +var P$8 = createProperty('last', mixin$5); + +function last(obs) { + return new (obs._ofSameType(S$12, P$8))(obs); +} + +var mixin$6 = { + _init: function (_ref) { + var n = _ref.n; + + this._n = Math.max(0, n); + }, + _handleValue: function (x) { + if (this._n === 0) { + this._emitValue(x); + } else { + this._n--; + } + } +}; + +var S$13 = createStream('skip', mixin$6); +var P$9 = createProperty('skip', mixin$6); + +function skip(obs, n) { + return new (obs._ofSameType(S$13, P$9))(obs, { n: n }); +} + +var mixin$7 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (this._fn !== null && !fn(x)) { + this._fn = null; + } + if (this._fn === null) { + this._emitValue(x); + } + } +}; + +var S$14 = createStream('skipWhile', mixin$7); +var P$10 = createProperty('skipWhile', mixin$7); + +var id$3 = function (x) { + return x; +}; + +function skipWhile(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$3; + + return new (obs._ofSameType(S$14, P$10))(obs, { fn: fn }); +} + +var mixin$8 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + this._prev = NOTHING; + }, + _free: function () { + this._fn = null; + this._prev = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (this._prev === NOTHING || !fn(this._prev, x)) { + this._prev = x; + this._emitValue(x); + } + } +}; + +var S$15 = createStream('skipDuplicates', mixin$8); +var P$11 = createProperty('skipDuplicates', mixin$8); + +var eq = function (a, b) { + return a === b; +}; + +function skipDuplicates(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : eq; + + return new (obs._ofSameType(S$15, P$11))(obs, { fn: fn }); +} + +var mixin$9 = { + _init: function (_ref) { + var fn = _ref.fn, + seed = _ref.seed; + + this._fn = fn; + this._prev = seed; + }, + _free: function () { + this._prev = null; + this._fn = null; + }, + _handleValue: function (x) { + if (this._prev !== NOTHING) { + var fn = this._fn; + this._emitValue(fn(this._prev, x)); + } + this._prev = x; + } +}; + +var S$16 = createStream('diff', mixin$9); +var P$12 = createProperty('diff', mixin$9); + +function defaultFn(a, b) { + return [a, b]; +} + +function diff(obs, fn) { + var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NOTHING; + + return new (obs._ofSameType(S$16, P$12))(obs, { fn: fn || defaultFn, seed: seed }); +} + +var P$13 = createProperty('scan', { + _init: function (_ref) { + var fn = _ref.fn, + seed = _ref.seed; + + this._fn = fn; + this._seed = seed; + if (seed !== NOTHING) { + this._emitValue(seed); + } + }, + _free: function () { + this._fn = null; + this._seed = null; + }, + _handleValue: function (x) { + var fn = this._fn; + if (this._currentEvent === null || this._currentEvent.type === ERROR) { + this._emitValue(this._seed === NOTHING ? x : fn(this._seed, x)); + } else { + this._emitValue(fn(this._currentEvent.value, x)); + } + } +}); + +function scan(obs, fn) { + var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NOTHING; + + return new P$13(obs, { fn: fn, seed: seed }); +} + +var mixin$10 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + var xs = fn(x); + for (var i = 0; i < xs.length; i++) { + this._emitValue(xs[i]); + } + } +}; + +var S$17 = createStream('flatten', mixin$10); + +var id$4 = function (x) { + return x; +}; + +function flatten(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$4; + + return new S$17(obs, { fn: fn }); +} + +var END_MARKER = {}; + +var mixin$11 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait; + + this._wait = Math.max(0, wait); + this._buff = []; + this._$shiftBuff = function () { + var value = _this._buff.shift(); + if (value === END_MARKER) { + _this._emitEnd(); + } else { + _this._emitValue(value); + } + }; + }, + _free: function () { + this._buff = null; + this._$shiftBuff = null; + }, + _handleValue: function (x) { + if (this._activating) { + this._emitValue(x); + } else { + this._buff.push(x); + setTimeout(this._$shiftBuff, this._wait); + } + }, + _handleEnd: function () { + if (this._activating) { + this._emitEnd(); + } else { + this._buff.push(END_MARKER); + setTimeout(this._$shiftBuff, this._wait); + } + } +}; + +var S$18 = createStream('delay', mixin$11); +var P$14 = createProperty('delay', mixin$11); + +function delay(obs, wait) { + return new (obs._ofSameType(S$18, P$14))(obs, { wait: wait }); +} + +var now = Date.now ? function () { + return Date.now(); +} : function () { + return new Date().getTime(); +}; + +var mixin$12 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait, + leading = _ref.leading, + trailing = _ref.trailing; + + this._wait = Math.max(0, wait); + this._leading = leading; + this._trailing = trailing; + this._trailingValue = null; + this._timeoutId = null; + this._endLater = false; + this._lastCallTime = 0; + this._$trailingCall = function () { + return _this._trailingCall(); + }; + }, + _free: function () { + this._trailingValue = null; + this._$trailingCall = null; + }, + _handleValue: function (x) { + if (this._activating) { + this._emitValue(x); + } else { + var curTime = now(); + if (this._lastCallTime === 0 && !this._leading) { + this._lastCallTime = curTime; + } + var remaining = this._wait - (curTime - this._lastCallTime); + if (remaining <= 0) { + this._cancelTrailing(); + this._lastCallTime = curTime; + this._emitValue(x); + } else if (this._trailing) { + this._cancelTrailing(); + this._trailingValue = x; + this._timeoutId = setTimeout(this._$trailingCall, remaining); + } + } + }, + _handleEnd: function () { + if (this._activating) { + this._emitEnd(); + } else { + if (this._timeoutId) { + this._endLater = true; + } else { + this._emitEnd(); + } + } + }, + _cancelTrailing: function () { + if (this._timeoutId !== null) { + clearTimeout(this._timeoutId); + this._timeoutId = null; + } + }, + _trailingCall: function () { + this._emitValue(this._trailingValue); + this._timeoutId = null; + this._trailingValue = null; + this._lastCallTime = !this._leading ? 0 : now(); + if (this._endLater) { + this._emitEnd(); + } + } +}; + +var S$19 = createStream('throttle', mixin$12); +var P$15 = createProperty('throttle', mixin$12); + +function throttle(obs, wait) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$leading = _ref2.leading, + leading = _ref2$leading === undefined ? true : _ref2$leading, + _ref2$trailing = _ref2.trailing, + trailing = _ref2$trailing === undefined ? true : _ref2$trailing; + + return new (obs._ofSameType(S$19, P$15))(obs, { wait: wait, leading: leading, trailing: trailing }); +} + +var mixin$13 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait, + immediate = _ref.immediate; + + this._wait = Math.max(0, wait); + this._immediate = immediate; + this._lastAttempt = 0; + this._timeoutId = null; + this._laterValue = null; + this._endLater = false; + this._$later = function () { + return _this._later(); + }; + }, + _free: function () { + this._laterValue = null; + this._$later = null; + }, + _handleValue: function (x) { + if (this._activating) { + this._emitValue(x); + } else { + this._lastAttempt = now(); + if (this._immediate && !this._timeoutId) { + this._emitValue(x); + } + if (!this._timeoutId) { + this._timeoutId = setTimeout(this._$later, this._wait); + } + if (!this._immediate) { + this._laterValue = x; + } + } + }, + _handleEnd: function () { + if (this._activating) { + this._emitEnd(); + } else { + if (this._timeoutId && !this._immediate) { + this._endLater = true; + } else { + this._emitEnd(); + } + } + }, + _later: function () { + var last = now() - this._lastAttempt; + if (last < this._wait && last >= 0) { + this._timeoutId = setTimeout(this._$later, this._wait - last); + } else { + this._timeoutId = null; + if (!this._immediate) { + var _laterValue = this._laterValue; + this._laterValue = null; + this._emitValue(_laterValue); + } + if (this._endLater) { + this._emitEnd(); + } + } + } +}; + +var S$20 = createStream('debounce', mixin$13); +var P$16 = createProperty('debounce', mixin$13); + +function debounce(obs, wait) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$immediate = _ref2.immediate, + immediate = _ref2$immediate === undefined ? false : _ref2$immediate; + + return new (obs._ofSameType(S$20, P$16))(obs, { wait: wait, immediate: immediate }); +} + +var mixin$14 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleError: function (x) { + var fn = this._fn; + this._emitError(fn(x)); + } +}; + +var S$21 = createStream('mapErrors', mixin$14); +var P$17 = createProperty('mapErrors', mixin$14); + +var id$5 = function (x) { + return x; +}; + +function mapErrors(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$5; + + return new (obs._ofSameType(S$21, P$17))(obs, { fn: fn }); +} + +var mixin$15 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleError: function (x) { + var fn = this._fn; + if (fn(x)) { + this._emitError(x); + } + } +}; + +var S$22 = createStream('filterErrors', mixin$15); +var P$18 = createProperty('filterErrors', mixin$15); + +var id$6 = function (x) { + return x; +}; + +function filterErrors(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : id$6; + + return new (obs._ofSameType(S$22, P$18))(obs, { fn: fn }); +} + +var mixin$16 = { + _handleValue: function () {} +}; + +var S$23 = createStream('ignoreValues', mixin$16); +var P$19 = createProperty('ignoreValues', mixin$16); + +function ignoreValues(obs) { + return new (obs._ofSameType(S$23, P$19))(obs); +} + +var mixin$17 = { + _handleError: function () {} +}; + +var S$24 = createStream('ignoreErrors', mixin$17); +var P$20 = createProperty('ignoreErrors', mixin$17); + +function ignoreErrors(obs) { + return new (obs._ofSameType(S$24, P$20))(obs); +} + +var mixin$18 = { + _handleEnd: function () {} +}; + +var S$25 = createStream('ignoreEnd', mixin$18); +var P$21 = createProperty('ignoreEnd', mixin$18); + +function ignoreEnd(obs) { + return new (obs._ofSameType(S$25, P$21))(obs); +} + +var mixin$19 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleEnd: function () { + var fn = this._fn; + this._emitValue(fn()); + this._emitEnd(); + } +}; + +var S$26 = createStream('beforeEnd', mixin$19); +var P$22 = createProperty('beforeEnd', mixin$19); + +function beforeEnd(obs, fn) { + return new (obs._ofSameType(S$26, P$22))(obs, { fn: fn }); +} + +var mixin$20 = { + _init: function (_ref) { + var min = _ref.min, + max = _ref.max; + + this._max = max; + this._min = min; + this._buff = []; + }, + _free: function () { + this._buff = null; + }, + _handleValue: function (x) { + this._buff = slide(this._buff, x, this._max); + if (this._buff.length >= this._min) { + this._emitValue(this._buff); + } + } +}; + +var S$27 = createStream('slidingWindow', mixin$20); +var P$23 = createProperty('slidingWindow', mixin$20); + +function slidingWindow(obs, max) { + var min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + + return new (obs._ofSameType(S$27, P$23))(obs, { min: min, max: max }); +} + +var mixin$21 = { + _init: function (_ref) { + var fn = _ref.fn, + flushOnEnd = _ref.flushOnEnd; + + this._fn = fn; + this._flushOnEnd = flushOnEnd; + this._buff = []; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null && this._buff.length !== 0) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handleValue: function (x) { + this._buff.push(x); + var fn = this._fn; + if (!fn(x)) { + this._flush(); + } + }, + _handleEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + } +}; + +var S$28 = createStream('bufferWhile', mixin$21); +var P$24 = createProperty('bufferWhile', mixin$21); + +var id$7 = function (x) { + return x; +}; + +function bufferWhile(obs, fn) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$flushOnEnd = _ref2.flushOnEnd, + flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd; + + return new (obs._ofSameType(S$28, P$24))(obs, { fn: fn || id$7, flushOnEnd: flushOnEnd }); +} + +var mixin$22 = { + _init: function (_ref) { + var count = _ref.count, + flushOnEnd = _ref.flushOnEnd; + + this._count = count; + this._flushOnEnd = flushOnEnd; + this._buff = []; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null && this._buff.length !== 0) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handleValue: function (x) { + this._buff.push(x); + if (this._buff.length >= this._count) { + this._flush(); + } + }, + _handleEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + } +}; + +var S$29 = createStream('bufferWithCount', mixin$22); +var P$25 = createProperty('bufferWithCount', mixin$22); + +function bufferWhile$1(obs, count) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$flushOnEnd = _ref2.flushOnEnd, + flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd; + + return new (obs._ofSameType(S$29, P$25))(obs, { count: count, flushOnEnd: flushOnEnd }); +} + +var mixin$23 = { + _init: function (_ref) { + var _this = this; + + var wait = _ref.wait, + count = _ref.count, + flushOnEnd = _ref.flushOnEnd; + + this._wait = wait; + this._count = count; + this._flushOnEnd = flushOnEnd; + this._intervalId = null; + this._$onTick = function () { + return _this._flush(); + }; + this._buff = []; + }, + _free: function () { + this._$onTick = null; + this._buff = null; + }, + _flush: function () { + if (this._buff !== null) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handleValue: function (x) { + this._buff.push(x); + if (this._buff.length >= this._count) { + clearInterval(this._intervalId); + this._flush(); + this._intervalId = setInterval(this._$onTick, this._wait); + } + }, + _handleEnd: function () { + if (this._flushOnEnd && this._buff.length !== 0) { + this._flush(); + } + this._emitEnd(); + }, + _onActivation: function () { + this._intervalId = setInterval(this._$onTick, this._wait); + this._source.onAny(this._$handleAny); // copied from patterns/one-source + }, + _onDeactivation: function () { + if (this._intervalId !== null) { + clearInterval(this._intervalId); + this._intervalId = null; + } + this._source.offAny(this._$handleAny); // copied from patterns/one-source + } +}; + +var S$30 = createStream('bufferWithTimeOrCount', mixin$23); +var P$26 = createProperty('bufferWithTimeOrCount', mixin$23); + +function bufferWithTimeOrCount(obs, wait, count) { + var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, + _ref2$flushOnEnd = _ref2.flushOnEnd, + flushOnEnd = _ref2$flushOnEnd === undefined ? true : _ref2$flushOnEnd; + + return new (obs._ofSameType(S$30, P$26))(obs, { wait: wait, count: count, flushOnEnd: flushOnEnd }); +} + +function xformForObs(obs) { + return { + '@@transducer/step': function (res, input) { + obs._emitValue(input); + return null; + }, + '@@transducer/result': function () { + obs._emitEnd(); + return null; + } + }; +} + +var mixin$24 = { + _init: function (_ref) { + var transducer = _ref.transducer; + + this._xform = transducer(xformForObs(this)); + }, + _free: function () { + this._xform = null; + }, + _handleValue: function (x) { + if (this._xform['@@transducer/step'](null, x) !== null) { + this._xform['@@transducer/result'](null); + } + }, + _handleEnd: function () { + this._xform['@@transducer/result'](null); + } +}; + +var S$31 = createStream('transduce', mixin$24); +var P$27 = createProperty('transduce', mixin$24); + +function transduce(obs, transducer) { + return new (obs._ofSameType(S$31, P$27))(obs, { transducer: transducer }); +} + +var mixin$25 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._handler = fn; + this._emitter = emitter(this); + }, + _free: function () { + this._handler = null; + this._emitter = null; + }, + _handleAny: function (event) { + this._handler(this._emitter, event); + } +}; + +var S$32 = createStream('withHandler', mixin$25); +var P$28 = createProperty('withHandler', mixin$25); + +function withHandler(obs, fn) { + return new (obs._ofSameType(S$32, P$28))(obs, { fn: fn }); +} + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function Zip(sources, combinator) { + var _this = this; + + Stream.call(this); + + this._buffers = map(sources, function (source) { + return isArray(source) ? cloneArray(source) : []; + }); + this._sources = map(sources, function (source) { + return isArray(source) ? never() : source; + }); + + this._combinator = combinator ? spread(combinator, this._sources.length) : function (x) { + return x; + }; + this._aliveCount = 0; + + this._$handlers = []; + + var _loop = function (i) { + _this._$handlers.push(function (event) { + return _this._handleAny(i, event); + }); + }; + + for (var i = 0; i < this._sources.length; i++) { + _loop(i); + } +} + +inherit(Zip, Stream, { + _name: 'zip', + + _onActivation: function () { + // if all sources are arrays + while (this._isFull()) { + this._emit(); + } + + var length = this._sources.length; + this._aliveCount = length; + for (var i = 0; i < length && this._active; i++) { + this._sources[i].onAny(this._$handlers[i]); + } + }, + _onDeactivation: function () { + for (var i = 0; i < this._sources.length; i++) { + this._sources[i].offAny(this._$handlers[i]); + } + }, + _emit: function () { + var values = new Array(this._buffers.length); + for (var i = 0; i < this._buffers.length; i++) { + values[i] = this._buffers[i].shift(); + } + var combinator = this._combinator; + this._emitValue(combinator(values)); + }, + _isFull: function () { + for (var i = 0; i < this._buffers.length; i++) { + if (this._buffers[i].length === 0) { + return false; + } + } + return true; + }, + _handleAny: function (i, event) { + if (event.type === VALUE) { + this._buffers[i].push(event.value); + if (this._isFull()) { + this._emit(); + } + } + if (event.type === ERROR) { + this._emitError(event.value); + } + if (event.type === END) { + this._aliveCount--; + if (this._aliveCount === 0) { + this._emitEnd(); + } + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._sources = null; + this._buffers = null; + this._combinator = null; + this._$handlers = null; + } +}); + +function zip(observables, combinator /* Function | falsey */) { + return observables.length === 0 ? never() : new Zip(observables, combinator); +} + +var id$8 = function (x) { + return x; +}; + +function AbstractPool() { + var _this = this; + + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$queueLim = _ref.queueLim, + queueLim = _ref$queueLim === undefined ? 0 : _ref$queueLim, + _ref$concurLim = _ref.concurLim, + concurLim = _ref$concurLim === undefined ? -1 : _ref$concurLim, + _ref$drop = _ref.drop, + drop = _ref$drop === undefined ? 'new' : _ref$drop; + + Stream.call(this); + + this._queueLim = queueLim < 0 ? -1 : queueLim; + this._concurLim = concurLim < 0 ? -1 : concurLim; + this._drop = drop; + this._queue = []; + this._curSources = []; + this._$handleSubAny = function (event) { + return _this._handleSubAny(event); + }; + this._$endHandlers = []; + this._currentlyAdding = null; + + if (this._concurLim === 0) { + this._emitEnd(); + } +} + +inherit(AbstractPool, Stream, { + _name: 'abstractPool', + + _add: function (obj, toObs /* Function | falsey */) { + toObs = toObs || id$8; + if (this._concurLim === -1 || this._curSources.length < this._concurLim) { + this._addToCur(toObs(obj)); + } else { + if (this._queueLim === -1 || this._queue.length < this._queueLim) { + this._addToQueue(toObs(obj)); + } else if (this._drop === 'old') { + this._removeOldest(); + this._add(obj, toObs); + } + } + }, + _addAll: function (obss) { + var _this2 = this; + + forEach(obss, function (obs) { + return _this2._add(obs); + }); + }, + _remove: function (obs) { + if (this._removeCur(obs) === -1) { + this._removeQueue(obs); + } + }, + _addToQueue: function (obs) { + this._queue = concat(this._queue, [obs]); + }, + _addToCur: function (obs) { + if (this._active) { + // HACK: + // + // We have two optimizations for cases when `obs` is ended. We don't want + // to add such observable to the list, but only want to emit events + // from it (if it has some). + // + // Instead of this hacks, we could just did following, + // but it would be 5-8 times slower: + // + // this._curSources = concat(this._curSources, [obs]); + // this._subscribe(obs); + // + + // #1 + // This one for cases when `obs` already ended + // e.g., Kefir.constant() or Kefir.never() + if (!obs._alive) { + if (obs._currentEvent) { + this._emit(obs._currentEvent.type, obs._currentEvent.value); + } + // The _emit above could have caused this stream to end. + if (this._active) { + if (this._queue.length !== 0) { + this._pullQueue(); + } else if (this._curSources.length === 0) { + this._onEmpty(); + } + } + return; + } + + // #2 + // This one is for cases when `obs` going to end synchronously on + // first subscriber e.g., Kefir.stream(em => {em.emit(1); em.end()}) + this._currentlyAdding = obs; + obs.onAny(this._$handleSubAny); + this._currentlyAdding = null; + if (obs._alive) { + this._curSources = concat(this._curSources, [obs]); + if (this._active) { + this._subToEnd(obs); + } + } else { + if (this._queue.length !== 0) { + this._pullQueue(); + } else if (this._curSources.length === 0) { + this._onEmpty(); + } + } + } else { + this._curSources = concat(this._curSources, [obs]); + } + }, + _subToEnd: function (obs) { + var _this3 = this; + + var onEnd = function () { + return _this3._removeCur(obs); + }; + this._$endHandlers.push({ obs: obs, handler: onEnd }); + obs.onEnd(onEnd); + }, + _subscribe: function (obs) { + obs.onAny(this._$handleSubAny); + + // it can become inactive in responce of subscribing to `obs.onAny` above + if (this._active) { + this._subToEnd(obs); + } + }, + _unsubscribe: function (obs) { + obs.offAny(this._$handleSubAny); + + var onEndI = findByPred(this._$endHandlers, function (obj) { + return obj.obs === obs; + }); + if (onEndI !== -1) { + obs.offEnd(this._$endHandlers[onEndI].handler); + this._$endHandlers.splice(onEndI, 1); + } + }, + _handleSubAny: function (event) { + if (event.type === VALUE) { + this._emitValue(event.value); + } else if (event.type === ERROR) { + this._emitError(event.value); + } + }, + _removeQueue: function (obs) { + var index = find(this._queue, obs); + this._queue = remove(this._queue, index); + return index; + }, + _removeCur: function (obs) { + if (this._active) { + this._unsubscribe(obs); + } + var index = find(this._curSources, obs); + this._curSources = remove(this._curSources, index); + if (index !== -1) { + if (this._queue.length !== 0) { + this._pullQueue(); + } else if (this._curSources.length === 0) { + this._onEmpty(); + } + } + return index; + }, + _removeOldest: function () { + this._removeCur(this._curSources[0]); + }, + _pullQueue: function () { + if (this._queue.length !== 0) { + this._queue = cloneArray(this._queue); + this._addToCur(this._queue.shift()); + } + }, + _onActivation: function () { + for (var i = 0, sources = this._curSources; i < sources.length && this._active; i++) { + this._subscribe(sources[i]); + } + }, + _onDeactivation: function () { + for (var i = 0, sources = this._curSources; i < sources.length; i++) { + this._unsubscribe(sources[i]); + } + if (this._currentlyAdding !== null) { + this._unsubscribe(this._currentlyAdding); + } + }, + _isEmpty: function () { + return this._curSources.length === 0; + }, + _onEmpty: function () {}, + _clear: function () { + Stream.prototype._clear.call(this); + this._queue = null; + this._curSources = null; + this._$handleSubAny = null; + this._$endHandlers = null; + } +}); + +function Merge(sources) { + AbstractPool.call(this); + this._addAll(sources); + this._initialised = true; +} + +inherit(Merge, AbstractPool, { + _name: 'merge', + + _onEmpty: function () { + if (this._initialised) { + this._emitEnd(); + } + } +}); + +function merge(observables) { + return observables.length === 0 ? never() : new Merge(observables); +} + +function S$33(generator) { + var _this = this; + + Stream.call(this); + this._generator = generator; + this._source = null; + this._inLoop = false; + this._iteration = 0; + this._$handleAny = function (event) { + return _this._handleAny(event); + }; +} + +inherit(S$33, Stream, { + _name: 'repeat', + + _handleAny: function (event) { + if (event.type === END) { + this._source = null; + this._getSource(); + } else { + this._emit(event.type, event.value); + } + }, + _getSource: function () { + if (!this._inLoop) { + this._inLoop = true; + var generator = this._generator; + while (this._source === null && this._alive && this._active) { + this._source = generator(this._iteration++); + if (this._source) { + this._source.onAny(this._$handleAny); + } else { + this._emitEnd(); + } + } + this._inLoop = false; + } + }, + _onActivation: function () { + if (this._source) { + this._source.onAny(this._$handleAny); + } else { + this._getSource(); + } + }, + _onDeactivation: function () { + if (this._source) { + this._source.offAny(this._$handleAny); + } + }, + _clear: function () { + Stream.prototype._clear.call(this); + this._generator = null; + this._source = null; + this._$handleAny = null; + } +}); + +var repeat = function (generator) { + return new S$33(generator); +}; + +function concat$1(observables) { + return repeat(function (index) { + return observables.length > index ? observables[index] : false; + }).setName('concat'); +} + +function Pool() { + AbstractPool.call(this); +} + +inherit(Pool, AbstractPool, { + _name: 'pool', + + plug: function (obs) { + this._add(obs); + return this; + }, + unplug: function (obs) { + this._remove(obs); + return this; + } +}); + +function FlatMap(source, fn, options) { + var _this = this; + + AbstractPool.call(this, options); + this._source = source; + this._fn = fn; + this._mainEnded = false; + this._lastCurrent = null; + this._$handleMain = function (event) { + return _this._handleMain(event); + }; +} + +inherit(FlatMap, AbstractPool, { + _onActivation: function () { + AbstractPool.prototype._onActivation.call(this); + if (this._active) { + this._source.onAny(this._$handleMain); + } + }, + _onDeactivation: function () { + AbstractPool.prototype._onDeactivation.call(this); + this._source.offAny(this._$handleMain); + this._hadNoEvSinceDeact = true; + }, + _handleMain: function (event) { + if (event.type === VALUE) { + // Is latest value before deactivation survived, and now is 'current' on this activation? + // We don't want to handle such values, to prevent to constantly add + // same observale on each activation/deactivation when our main source + // is a `Kefir.conatant()` for example. + var sameCurr = this._activating && this._hadNoEvSinceDeact && this._lastCurrent === event.value; + if (!sameCurr) { + this._add(event.value, this._fn); + } + this._lastCurrent = event.value; + this._hadNoEvSinceDeact = false; + } + + if (event.type === ERROR) { + this._emitError(event.value); + } + + if (event.type === END) { + if (this._isEmpty()) { + this._emitEnd(); + } else { + this._mainEnded = true; + } + } + }, + _onEmpty: function () { + if (this._mainEnded) { + this._emitEnd(); + } + }, + _clear: function () { + AbstractPool.prototype._clear.call(this); + this._source = null; + this._lastCurrent = null; + this._$handleMain = null; + } +}); + +function FlatMapErrors(source, fn) { + FlatMap.call(this, source, fn); +} + +inherit(FlatMapErrors, FlatMap, { + // Same as in FlatMap, only VALUE/ERROR flipped + _handleMain: function (event) { + if (event.type === ERROR) { + var sameCurr = this._activating && this._hadNoEvSinceDeact && this._lastCurrent === event.value; + if (!sameCurr) { + this._add(event.value, this._fn); + } + this._lastCurrent = event.value; + this._hadNoEvSinceDeact = false; + } + + if (event.type === VALUE) { + this._emitValue(event.value); + } + + if (event.type === END) { + if (this._isEmpty()) { + this._emitEnd(); + } else { + this._mainEnded = true; + } + } + } +}); + +function createConstructor$1(BaseClass, name) { + return function AnonymousObservable(primary, secondary, options) { + var _this = this; + + BaseClass.call(this); + this._primary = primary; + this._secondary = secondary; + this._name = primary._name + '.' + name; + this._lastSecondary = NOTHING; + this._$handleSecondaryAny = function (event) { + return _this._handleSecondaryAny(event); + }; + this._$handlePrimaryAny = function (event) { + return _this._handlePrimaryAny(event); + }; + this._init(options); + }; +} + +function createClassMethods$1(BaseClass) { + return { + _init: function () {}, + _free: function () {}, + _handlePrimaryValue: function (x) { + this._emitValue(x); + }, + _handlePrimaryError: function (x) { + this._emitError(x); + }, + _handlePrimaryEnd: function () { + this._emitEnd(); + }, + _handleSecondaryValue: function (x) { + this._lastSecondary = x; + }, + _handleSecondaryError: function (x) { + this._emitError(x); + }, + _handleSecondaryEnd: function () {}, + _handlePrimaryAny: function (event) { + switch (event.type) { + case VALUE: + return this._handlePrimaryValue(event.value); + case ERROR: + return this._handlePrimaryError(event.value); + case END: + return this._handlePrimaryEnd(event.value); + } + }, + _handleSecondaryAny: function (event) { + switch (event.type) { + case VALUE: + return this._handleSecondaryValue(event.value); + case ERROR: + return this._handleSecondaryError(event.value); + case END: + this._handleSecondaryEnd(event.value); + this._removeSecondary(); + } + }, + _removeSecondary: function () { + if (this._secondary !== null) { + this._secondary.offAny(this._$handleSecondaryAny); + this._$handleSecondaryAny = null; + this._secondary = null; + } + }, + _onActivation: function () { + if (this._secondary !== null) { + this._secondary.onAny(this._$handleSecondaryAny); + } + if (this._active) { + this._primary.onAny(this._$handlePrimaryAny); + } + }, + _onDeactivation: function () { + if (this._secondary !== null) { + this._secondary.offAny(this._$handleSecondaryAny); + } + this._primary.offAny(this._$handlePrimaryAny); + }, + _clear: function () { + BaseClass.prototype._clear.call(this); + this._primary = null; + this._secondary = null; + this._lastSecondary = null; + this._$handleSecondaryAny = null; + this._$handlePrimaryAny = null; + this._free(); + } + }; +} + +function createStream$1(name, mixin) { + var S = createConstructor$1(Stream, name); + inherit(S, Stream, createClassMethods$1(Stream), mixin); + return S; +} + +function createProperty$1(name, mixin) { + var P = createConstructor$1(Property, name); + inherit(P, Property, createClassMethods$1(Property), mixin); + return P; +} + +var mixin$26 = { + _handlePrimaryValue: function (x) { + if (this._lastSecondary !== NOTHING && this._lastSecondary) { + this._emitValue(x); + } + }, + _handleSecondaryEnd: function () { + if (this._lastSecondary === NOTHING || !this._lastSecondary) { + this._emitEnd(); + } + } +}; + +var S$34 = createStream$1('filterBy', mixin$26); +var P$29 = createProperty$1('filterBy', mixin$26); + +function filterBy(primary, secondary) { + return new (primary._ofSameType(S$34, P$29))(primary, secondary); +} + +var id2 = function (_, x) { + return x; +}; + +function sampledBy(passive, active, combinator) { + var _combinator = combinator ? function (a, b) { + return combinator(b, a); + } : id2; + return combine([active], [passive], _combinator).setName(passive, 'sampledBy'); +} + +var mixin$27 = { + _handlePrimaryValue: function (x) { + if (this._lastSecondary !== NOTHING) { + this._emitValue(x); + } + }, + _handleSecondaryEnd: function () { + if (this._lastSecondary === NOTHING) { + this._emitEnd(); + } + } +}; + +var S$35 = createStream$1('skipUntilBy', mixin$27); +var P$30 = createProperty$1('skipUntilBy', mixin$27); + +function skipUntilBy(primary, secondary) { + return new (primary._ofSameType(S$35, P$30))(primary, secondary); +} + +var mixin$28 = { + _handleSecondaryValue: function () { + this._emitEnd(); + } +}; + +var S$36 = createStream$1('takeUntilBy', mixin$28); +var P$31 = createProperty$1('takeUntilBy', mixin$28); + +function takeUntilBy(primary, secondary) { + return new (primary._ofSameType(S$36, P$31))(primary, secondary); +} + +var mixin$29 = { + _init: function () { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$flushOnEnd = _ref.flushOnEnd, + flushOnEnd = _ref$flushOnEnd === undefined ? true : _ref$flushOnEnd; + + this._buff = []; + this._flushOnEnd = flushOnEnd; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handlePrimaryEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + }, + _onActivation: function () { + this._primary.onAny(this._$handlePrimaryAny); + if (this._alive && this._secondary !== null) { + this._secondary.onAny(this._$handleSecondaryAny); + } + }, + _handlePrimaryValue: function (x) { + this._buff.push(x); + }, + _handleSecondaryValue: function () { + this._flush(); + }, + _handleSecondaryEnd: function () { + if (!this._flushOnEnd) { + this._emitEnd(); + } + } +}; + +var S$37 = createStream$1('bufferBy', mixin$29); +var P$32 = createProperty$1('bufferBy', mixin$29); + +function bufferBy(primary, secondary, options /* optional */) { + return new (primary._ofSameType(S$37, P$32))(primary, secondary, options); +} + +var mixin$30 = { + _init: function () { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$flushOnEnd = _ref.flushOnEnd, + flushOnEnd = _ref$flushOnEnd === undefined ? true : _ref$flushOnEnd, + _ref$flushOnChange = _ref.flushOnChange, + flushOnChange = _ref$flushOnChange === undefined ? false : _ref$flushOnChange; + + this._buff = []; + this._flushOnEnd = flushOnEnd; + this._flushOnChange = flushOnChange; + }, + _free: function () { + this._buff = null; + }, + _flush: function () { + if (this._buff !== null) { + this._emitValue(this._buff); + this._buff = []; + } + }, + _handlePrimaryEnd: function () { + if (this._flushOnEnd) { + this._flush(); + } + this._emitEnd(); + }, + _handlePrimaryValue: function (x) { + this._buff.push(x); + if (this._lastSecondary !== NOTHING && !this._lastSecondary) { + this._flush(); + } + }, + _handleSecondaryEnd: function () { + if (!this._flushOnEnd && (this._lastSecondary === NOTHING || this._lastSecondary)) { + this._emitEnd(); + } + }, + _handleSecondaryValue: function (x) { + if (this._flushOnChange && !x) { + this._flush(); + } + + // from default _handleSecondaryValue + this._lastSecondary = x; + } +}; + +var S$38 = createStream$1('bufferWhileBy', mixin$30); +var P$33 = createProperty$1('bufferWhileBy', mixin$30); + +function bufferWhileBy(primary, secondary, options /* optional */) { + return new (primary._ofSameType(S$38, P$33))(primary, secondary, options); +} + +var f = function () { + return false; +}; +var t = function () { + return true; +}; + +function awaiting(a, b) { + var result = merge([map$1(a, t), map$1(b, f)]); + result = skipDuplicates(result); + result = toProperty(result, f); + return result.setName(a, 'awaiting'); +} + +var mixin$31 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleValue: function (x) { + var fn = this._fn; + var result = fn(x); + if (result.convert) { + this._emitError(result.error); + } else { + this._emitValue(x); + } + } +}; + +var S$39 = createStream('valuesToErrors', mixin$31); +var P$34 = createProperty('valuesToErrors', mixin$31); + +var defFn = function (x) { + return { convert: true, error: x }; +}; + +function valuesToErrors(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defFn; + + return new (obs._ofSameType(S$39, P$34))(obs, { fn: fn }); +} + +var mixin$32 = { + _init: function (_ref) { + var fn = _ref.fn; + + this._fn = fn; + }, + _free: function () { + this._fn = null; + }, + _handleError: function (x) { + var fn = this._fn; + var result = fn(x); + if (result.convert) { + this._emitValue(result.value); + } else { + this._emitError(x); + } + } +}; + +var S$40 = createStream('errorsToValues', mixin$32); +var P$35 = createProperty('errorsToValues', mixin$32); + +var defFn$1 = function (x) { + return { convert: true, value: x }; +}; + +function errorsToValues(obs) { + var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defFn$1; + + return new (obs._ofSameType(S$40, P$35))(obs, { fn: fn }); +} + +var mixin$33 = { + _handleError: function (x) { + this._emitError(x); + this._emitEnd(); + } +}; + +var S$41 = createStream('endOnError', mixin$33); +var P$36 = createProperty('endOnError', mixin$33); + +function endOnError(obs) { + return new (obs._ofSameType(S$41, P$36))(obs); +} + +/* dev-code */ +/* end-dev-code */ + +// Create a stream +// ----------------------------------------------------------------------------- + +// () -> Stream +// (number, any) -> Stream +// (number, any) -> Stream +// (number, Array) -> Stream +// (number, Function) -> Stream +// (number, Function) -> Stream +// (Function) -> Stream +// (Function) -> Stream +// Target = {addEventListener, removeEventListener}|{addListener, removeListener}|{on, off} +// (Target, string, Function|undefined) -> Stream +// (Function) -> Stream +// Create a property +// ----------------------------------------------------------------------------- + +// (any) -> Property +// (any) -> Property +// Convert observables +// ----------------------------------------------------------------------------- + +// (Stream|Property, Function|undefined) -> Property +Observable.prototype.toProperty = function (fn) { + return toProperty(this, fn); +}; + +// (Stream|Property) -> Stream +Observable.prototype.changes = function () { + return changes(this); +}; + +// Interoperation with other implimentations +// ----------------------------------------------------------------------------- + +// (Promise) -> Property +// (Stream|Property, Function|undefined) -> Promise +Observable.prototype.toPromise = function (Promise) { + return toPromise(this, Promise); +}; + +// (ESObservable) -> Stream +// (Stream|Property) -> ES7 Observable +Observable.prototype.toESObservable = toESObservable; +Observable.prototype[$$observable] = toESObservable; + +// Modify an observable +// ----------------------------------------------------------------------------- + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.map = function (fn) { + return map$1(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.filter = function (fn) { + return filter(this, fn); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.take = function (n) { + return take(this, n); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.takeErrors = function (n) { + return takeErrors(this, n); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.takeWhile = function (fn) { + return takeWhile(this, fn); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.last = function () { + return last(this); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.skip = function (n) { + return skip(this, n); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.skipWhile = function (fn) { + return skipWhile(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.skipDuplicates = function (fn) { + return skipDuplicates(this, fn); +}; + +// (Stream, Function|falsey, any|undefined) -> Stream +// (Property, Function|falsey, any|undefined) -> Property +Observable.prototype.diff = function (fn, seed) { + return diff(this, fn, seed); +}; + +// (Stream|Property, Function, any|undefined) -> Property +Observable.prototype.scan = function (fn, seed) { + return scan(this, fn, seed); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.flatten = function (fn) { + return flatten(this, fn); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.delay = function (wait) { + return delay(this, wait); +}; + +// Options = {leading: boolean|undefined, trailing: boolean|undefined} +// (Stream, number, Options|undefined) -> Stream +// (Property, number, Options|undefined) -> Property +Observable.prototype.throttle = function (wait, options) { + return throttle(this, wait, options); +}; + +// Options = {immediate: boolean|undefined} +// (Stream, number, Options|undefined) -> Stream +// (Property, number, Options|undefined) -> Property +Observable.prototype.debounce = function (wait, options) { + return debounce(this, wait, options); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.mapErrors = function (fn) { + return mapErrors(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.filterErrors = function (fn) { + return filterErrors(this, fn); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.ignoreValues = function () { + return ignoreValues(this); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.ignoreErrors = function () { + return ignoreErrors(this); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.ignoreEnd = function () { + return ignoreEnd(this); +}; + +// (Stream, Function) -> Stream +// (Property, Function) -> Property +Observable.prototype.beforeEnd = function (fn) { + return beforeEnd(this, fn); +}; + +// (Stream, number, number|undefined) -> Stream +// (Property, number, number|undefined) -> Property +Observable.prototype.slidingWindow = function (max, min) { + return slidingWindow(this, max, min); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, Function|falsey, Options|undefined) -> Stream +// (Property, Function|falsey, Options|undefined) -> Property +Observable.prototype.bufferWhile = function (fn, options) { + return bufferWhile(this, fn, options); +}; + +// (Stream, number) -> Stream +// (Property, number) -> Property +Observable.prototype.bufferWithCount = function (count, options) { + return bufferWhile$1(this, count, options); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, number, number, Options|undefined) -> Stream +// (Property, number, number, Options|undefined) -> Property +Observable.prototype.bufferWithTimeOrCount = function (wait, count, options) { + return bufferWithTimeOrCount(this, wait, count, options); +}; + +// (Stream, Function) -> Stream +// (Property, Function) -> Property +Observable.prototype.transduce = function (transducer) { + return transduce(this, transducer); +}; + +// (Stream, Function) -> Stream +// (Property, Function) -> Property +Observable.prototype.withHandler = function (fn) { + return withHandler(this, fn); +}; + +// (Stream, Stream -> a) -> a +// (Property, Property -> a) -> a +Observable.prototype.thru = function (fn) { + return fn(this); +}; + +// Combine observables +// ----------------------------------------------------------------------------- + +// (Array, Function|undefiend) -> Stream +// (Array, Array, Function|undefiend) -> Stream +Observable.prototype.combine = function (other, combinator) { + return combine([this, other], combinator); +}; + +// (Array, Function|undefiend) -> Stream +Observable.prototype.zip = function (other, combinator) { + return zip([this, other], combinator); +}; + +// (Array) -> Stream +Observable.prototype.merge = function (other) { + return merge([this, other]); +}; + +// (Array) -> Stream +Observable.prototype.concat = function (other) { + return concat$1([this, other]); +}; + +// () -> Pool +var pool = function () { + return new Pool(); +}; + +// (Function) -> Stream +// Options = {concurLim: number|undefined, queueLim: number|undefined, drop: 'old'|'new'|undefiend} +// (Stream|Property, Function|falsey, Options|undefined) -> Stream +Observable.prototype.flatMap = function (fn) { + return new FlatMap(this, fn).setName(this, 'flatMap'); +}; +Observable.prototype.flatMapLatest = function (fn) { + return new FlatMap(this, fn, { concurLim: 1, drop: 'old' }).setName(this, 'flatMapLatest'); +}; +Observable.prototype.flatMapFirst = function (fn) { + return new FlatMap(this, fn, { concurLim: 1 }).setName(this, 'flatMapFirst'); +}; +Observable.prototype.flatMapConcat = function (fn) { + return new FlatMap(this, fn, { queueLim: -1, concurLim: 1 }).setName(this, 'flatMapConcat'); +}; +Observable.prototype.flatMapConcurLimit = function (fn, limit) { + return new FlatMap(this, fn, { queueLim: -1, concurLim: limit }).setName(this, 'flatMapConcurLimit'); +}; + +// (Stream|Property, Function|falsey) -> Stream +Observable.prototype.flatMapErrors = function (fn) { + return new FlatMapErrors(this, fn).setName(this, 'flatMapErrors'); +}; + +// Combine two observables +// ----------------------------------------------------------------------------- + +// (Stream, Stream|Property) -> Stream +// (Property, Stream|Property) -> Property +Observable.prototype.filterBy = function (other) { + return filterBy(this, other); +}; + +// (Stream, Stream|Property, Function|undefiend) -> Stream +// (Property, Stream|Property, Function|undefiend) -> Property +Observable.prototype.sampledBy = function (other, combinator) { + return sampledBy(this, other, combinator); +}; + +// (Stream, Stream|Property) -> Stream +// (Property, Stream|Property) -> Property +Observable.prototype.skipUntilBy = function (other) { + return skipUntilBy(this, other); +}; + +// (Stream, Stream|Property) -> Stream +// (Property, Stream|Property) -> Property +Observable.prototype.takeUntilBy = function (other) { + return takeUntilBy(this, other); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, Stream|Property, Options|undefined) -> Stream +// (Property, Stream|Property, Options|undefined) -> Property +Observable.prototype.bufferBy = function (other, options) { + return bufferBy(this, other, options); +}; + +// Options = {flushOnEnd: boolean|undefined} +// (Stream, Stream|Property, Options|undefined) -> Stream +// (Property, Stream|Property, Options|undefined) -> Property +Observable.prototype.bufferWhileBy = function (other, options) { + return bufferWhileBy(this, other, options); +}; + +// Deprecated +// ----------------------------------------------------------------------------- + +var DEPRECATION_WARNINGS = true; +function dissableDeprecationWarnings() { + DEPRECATION_WARNINGS = false; +} + +function warn(msg) { + if (DEPRECATION_WARNINGS && console && typeof console.warn === 'function') { + var msg2 = '\nHere is an Error object for you containing the call stack:'; + console.warn(msg, msg2, new Error()); + } +} + +// (Stream|Property, Stream|Property) -> Property +Observable.prototype.awaiting = function (other) { + warn('You are using deprecated .awaiting() method, see https://github.com/kefirjs/kefir/issues/145'); + return awaiting(this, other); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.valuesToErrors = function (fn) { + warn('You are using deprecated .valuesToErrors() method, see https://github.com/kefirjs/kefir/issues/149'); + return valuesToErrors(this, fn); +}; + +// (Stream, Function|undefined) -> Stream +// (Property, Function|undefined) -> Property +Observable.prototype.errorsToValues = function (fn) { + warn('You are using deprecated .errorsToValues() method, see https://github.com/kefirjs/kefir/issues/149'); + return errorsToValues(this, fn); +}; + +// (Stream) -> Stream +// (Property) -> Property +Observable.prototype.endOnError = function () { + warn('You are using deprecated .endOnError() method, see https://github.com/kefirjs/kefir/issues/150'); + return endOnError(this); +}; + +// Exports +// -------------------------------------------------------------------------- + +var Kefir = { + Observable: Observable, + Stream: Stream, + Property: Property, + never: never, + later: later, + interval: interval, + sequentially: sequentially, + fromPoll: fromPoll, + withInterval: withInterval, + fromCallback: fromCallback, + fromNodeCallback: fromNodeCallback, + fromEvents: fromEvents, + stream: stream, + constant: constant, + constantError: constantError, + fromPromise: fromPromise, + fromESObservable: fromESObservable, + combine: combine, + zip: zip, + merge: merge, + concat: concat$1, + Pool: Pool, + pool: pool, + repeat: repeat, + staticLand: staticLand, + /* dev-code */ + activeObservables: exports.activeObservables, + clearActiveObservables: clearActiveObservables + /* end-dev-code */ +}; + +Kefir.Kefir = Kefir; + +exports.dissableDeprecationWarnings = dissableDeprecationWarnings; +exports.Kefir = Kefir; +exports.Observable = Observable; +exports.Stream = Stream; +exports.Property = Property; +exports.never = never; +exports.later = later; +exports.interval = interval; +exports.sequentially = sequentially; +exports.fromPoll = fromPoll; +exports.withInterval = withInterval; +exports.fromCallback = fromCallback; +exports.fromNodeCallback = fromNodeCallback; +exports.fromEvents = fromEvents; +exports.stream = stream; +exports.constant = constant; +exports.constantError = constantError; +exports.fromPromise = fromPromise; +exports.fromESObservable = fromESObservable; +exports.combine = combine; +exports.zip = zip; +exports.merge = merge; +exports.concat = concat$1; +exports.Pool = Pool; +exports.pool = pool; +exports.repeat = repeat; +exports.staticLand = staticLand; +exports.clearActiveObservables = clearActiveObservables; +exports['default'] = Kefir; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/dist/kefir.js.flow b/dist/kefir.js.flow new file mode 100644 index 00000000..28c0a686 --- /dev/null +++ b/dist/kefir.js.flow @@ -0,0 +1,269 @@ +/* @flow */ + +import type EventEmitter from "events"; + +export type Event<+V,+E> = + {type: 'value', +value: V} | + {type: 'error', +value: E} | + {type: 'end', +value: void}; + +export type Emitter<-V,-E> = { + value(value: V): boolean; + event(event: Event): boolean; + error(e: E): boolean; + end(): void; + + // Deprecated methods + emit(value: V): boolean; + emitEvent(event: Event): boolean; +}; + +export type Subscription = { + closed: boolean; + unsubscribe(): void; +}; + +export type Observer<-V,-E> = { + +value?: (value: V) => void; + +error?: (err: E) => void; + +end?: () => void; +}; + +interface ESObserver<-V,-E> { + +start?: Function, + +next?: (value: V) => any, + +error?: (error: E) => any, + +complete?: () => any, +} + +/* + * This is the interface described by https://github.com/tc39/proposal-observable + * It provides interoperability between stream implementations, including Kefir, + * RxJS, and zen-observable. + */ +type ESObservable<+V,+E=*> = { + subscribe(callbacks: ESObserver): { unsubscribe(): void }; +}; + +declare class Observable<+V,+E=*> { + toProperty($?: empty): Property; + toProperty(getCurrent: () => V2): Property; + changes(): Observable; + + observe(obs: Observer, $?: empty): Subscription; + observe(onValue?: ?(v: V) => void, onError?: ?(err: E) => void, onEnd?: ?() => void): Subscription; + onValue(cb: (v: V) => void): this; + offValue(cb: (v: V) => void): this; + onError(cb: (err: E) => void): this; + offError(cb: (err: E) => void): this; + onEnd(cb: () => void): this; + offEnd(cb: () => void): this; + onAny(cb: (event: Event) => void): this; + offAny(cb: (event: Event) => void): this; + log(name?: string): this; + offLog(name?: string): this; + spy(name?: string): this; + offSpy(name?: string): this; + setName(name: string): this; + setName(Observable, name: string): this; + toPromise(PromiseConstructor?: Function): Promise; + toESObservable(): ESObservable; + + map(cb: (v: V) => V2): Observable; + filter(cb?: typeof Boolean): Observable<$NonMaybeType,E>; + filter(cb: (v: V) => any): Observable; + take(n: number): Observable; + takeWhile(cb?: (v: V) => boolean): Observable; + last(): Observable; + skip(n: number): Observable; + skipWhile(cb?: (v: V) => boolean): Observable; + skipDuplicates(comparator?: (a: V, b: V) => boolean): Observable; + + diff($?: empty): Observable<[V, V],E>; + diff(fn: (prev: V, next: V) => V2, $?: empty): Observable; + diff(fn: (prev: V | V3, next: V) => V2, seed: V3): Observable; + diff(fn: null | void, seed: V3): Observable<[V | V3, V],E>; + + scan(cb: (prev: V, next: V) => V, $?: empty): Observable; + scan(cb: (prev: V2, next: V) => V2, seed: V2): Observable; + + flatten($?: empty): Observable; + flatten(transformer: (value: V) => V2[]): Observable; + + delay(n: number): Observable; + throttle(n: number, options?: {leading?: boolean, trailing?: boolean}): Observable; + debounce(n: number, options?: {immediate?: boolean}): Observable; + mapErrors(fn: (error: E) => E2): Observable; + filterErrors(fn?: typeof Boolean): Observable>; + filterErrors(fn: (error: E) => any): Observable; + takeErrors(n: number): Observable; + ignoreValues(): Observable; + ignoreErrors(): Observable; + ignoreEnd(): Observable; + beforeEnd(fn: () => V2): Observable; + slidingWindow(max: number, min?: number): Observable; + bufferWhile(predicate?: (value: V) => boolean, options?: {flushOnEnd?: boolean}): Observable; + transduce(transducer: any): Observable; + thru(callback: (this => V2)): V2; + withHandler(handler: (emitter: Emitter, event: Event) => void): Observable; + + combine(otherObs: Observable, $?: empty): Observable<[V,V2],E|E2>; + combine(otherObs: Observable, combinator: (v: V, v2: V2) => V3): Observable; + combine( + otherObs: Observable, + passiveObss: Observable[], + $?: empty + ): Observable,E|E2|E3>; + combine( + otherObs: Observable, + passiveObss: Observable[], + combinator: (v: V, v2: V2, ...v3: V3[]) => V4 + ): Observable; + + zip(otherObs: Observable, $?: empty): Observable<[V,V2],E|E2>; + zip(otherObs: Observable, combinator: (v: V, v2: V2) => V3): Observable; + + merge(otherObs: Observable): Observable; + concat(otherObs: Observable): Observable; + + flatMap(transform: (value: V) => Observable): Observable; + flatMapLatest(transform: (value: V) => Observable): Observable; + flatMapFirst(transform: (value: V) => Observable): Observable; + flatMapConcat(transform: (value: V) => Observable): Observable; + flatMapConcurLimit(transform: (value: V) => Observable, limit: number): Observable; + flatMapErrors(transform: (error: E) => Observable): Observable; + + filterBy(otherObs: Observable): Observable; + skipUntilBy(otherObs: Observable): Observable; + takeUntilBy(otherObs: Observable): Observable; + bufferBy(otherObs: Observable, options?: {flushOnEnd?: boolean}): Observable; + bufferWhileBy(otherObs: Observable, options?: {flushOnEnd?: boolean, flushOnChange?: boolean}): Observable; + + sampledBy(otherObs: Observable, $?: empty): Observable; + sampledBy(otherObs: Observable, combinator: (obsValue: V, otherObsValue: V2) => V3): Observable; + + bufferWithTimeOrCount(time: number, count: number, options?: {flushOnEnd: boolean}): Observable; +} + +declare class Pool extends Observable { + plug(s: Observable): () => void; + unplug(s: Observable): () => void; +} + +declare class Stream<+V,+E=*> extends Observable { +} + +declare class Property<+V,+E=*> extends Observable { +} + +// `$observedValuesTuple` is a helper type that describes a type for a tuple or +// array of values in relation to a tuple or array of observables. This mapping +// states that the type of each position in the new tuple type matches the type +// of the value type parameter of the observable in the same position in the +// input tuple. +type $observedValuesTuple = $TupleMap(obs: Observable) => V> + +// `$observedValuesObject` is similar to `$observedValuesTuple` - except that +// `$observedValuesObject` describes an object type where the type of each +// property in the new object matches the value type parameter of the observable +// type under the same key in the input object. +type $observedValuesObject = $ObjMap(obs: Observable) => V> + +declare var Kefir: { + Observable: typeof Observable; + Pool: typeof Pool; + Stream: typeof Stream; + Property: typeof Property; + + staticLand: { + Observable: { + ap(obsF: Observable<(x: A) => B, E1>, obsV: Observable): Observable; + bimap(fnE: (x: E1) => E2, fnV: (x: V1) => V2, obs: Observable): Observable; + chain(cb: (value: V) => Observable, s: Observable): Observable; + concat(obs1: Observable, obs2: Observable): Observable; + empty(): Observable<*,*>; + map(cb: (value: V) => V2, s: Observable): Observable; + of(value: V): Observable; + }; + }; + + never(): Observable; + later(delay: number, value: V): Observable; + interval(interval: number, value: V): Observable; + sequentially(interval: number, values: V[]): Observable; + fromPoll(interval: number, f: () => V): Observable; + withInterval(interval: number, f: (emitter: Emitter) => void): Observable; + fromCallback(f: (cb: (value: V) => void) => void): Observable; + fromNodeCallback(f: (cb: (err: E, value: ?V) => void) => void): Observable; + fromEvents( + target: EventTarget | EventEmitter, // `EventTarget` comes from Flow's built-in dom types + eventName: string, + transformer?: (...args: any[]) => V + ): Observable; + stream(subscribe: (emitter: Emitter) => ?() => void): Observable; + + constant(value: V): Property; + constantError(err: E): Property; + + fromPromise(promise: Promise): Property; + fromESObservable(observable: ESObservable): Observable; + + combine: + // array of observables + & ([]>( + obss: Obss, + $?: empty + ) => Observable<$observedValuesTuple, E>) + + // array of observables, combinator + & ((obss: Observable[], combinator: (...args: any[]) => V) => Observable) + + // array of observables, array of passive observables + & ((obss: Observable[], passiveObss: Observable[], $?: empty) => Observable<(V|V2)[],E|E2>) + + // array of observables, array of passive observables, combinator + & ((obss: Observable[], passiveObss: Observable[], combinator: (...args: any[]) => V) => Observable) + + // object of observables + & ( }>( + obss: Obss, + $?: empty + ) => Observable<$observedValuesObject, E>) + + // object of observables, combinator + & ( }>( + obss: Obss, + combinator: (vs: $observedValuesObject) => V + ) => Observable) + + // object of observables, object of passive observables + & ( }, PassiveObss: { [key: string]: Observable }>( + obss: Obss, + passiveObss: PassiveObss, + $?: empty + ) => Observable< + $observedValuesObject & $observedValuesObject, + E|E2>) + + // object of observables, object of passive observables, combinator + & ( }, PassiveObss: { [key: string]: Observable }>( + obss: Obss, + passiveObss: PassiveObss, + combinator: (vs: $observedValuesObject & $observedValuesObject) => V, + ) => Observable); + + zip: + & ([]>( + obss: Obss, + $?: empty + ) => Observable<$observedValuesTuple, E>) + & ((obss: Observable[], combinator: (...args: any[]) => V2) => Observable); + + merge(obss: Observable[]): Observable; + concat(obss: Observable[]): Observable; + + pool(): Pool<*,*>; + repeat(fn: (i: number) => ?Observable): Observable; +}; + +module.exports = Kefir; diff --git a/dist/kefir.min.js b/dist/kefir.min.js new file mode 100644 index 00000000..cced2d22 --- /dev/null +++ b/dist/kefir.min.js @@ -0,0 +1,5 @@ +/*! Kefir.js v3.8.8 + * https://github.com/kefirjs/kefir + */ +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.Kefir=t.Kefir||{})}(this,function(t){"use strict";function n(t){var n=function(){};return n.prototype=t,new n}function i(t){var n=arguments.length,i=void 0,e=void 0;for(i=1;i=0&&n1&&void 0!==arguments[1]?arguments[1]:null;if(null!==n&&"function"!=typeof n)throw new Error("You should call toProperty() with a function or no arguments.");return new pn(t,{fn:n})}function F(t){return new yn(t)}function Q(t){var n=!1;return U(C(function(i){if(!n){var e=function(t){i.emit(t),i.end()},r=function(t){i.error(t),i.end()},s=t.then(e,r);s&&"function"==typeof s.done&&s.done(),n=!0}}),null).setName("fromPromise")}function z(){if("function"==typeof Promise)return Promise;throw new Error("There isn't default Promise, use shim or parameter")}function Y(t){var n=t[bn]?t[bn]():t;return C(function(t){var i=n.subscribe({error:function(n){t.error(n),t.end()},next:function(n){t.emit(n)},complete:function(){t.end()}});return i.unsubscribe?function(){i.unsubscribe()}:i}).setName("fromESObservable")}function K(t){this._observable=t.takeErrors(1)}function G(){return new K(this)}function J(t,n,i){for(var e in t)t.hasOwnProperty(e)&&(n.push(e),i.push(t[e]))}function R(t){for(var n=void 0,i=0;i1&&void 0!==arguments[1]?arguments[1]:[],i=arguments[2];if(!Array.isArray(n))throw new Error("Combine can only combine active and passive collections of the same type.");return i=i?O(i,t.length+n.length):function(t){return t},0===t.length?g():new X(t,n,i)}function tt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments[2];if("object"!=typeof n||Array.isArray(n))throw new Error("Combine can only combine active and passive collections of the same type.");var e=[],r=[],s=[];J(t,e,r),J(n,e,s);var u=function(t){for(var n={},r=t.length-1;0<=r;r--)n[e[r]]=t[r];return i?i(n):n};return 0===r.length?g():new X(r,s,u)}function nt(t,n,i){return"function"==typeof n&&(i=n,n=void 0),Array.isArray(t)?Z(t,n,i):tt(t,n,i)}function it(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$n;return new(t._ofSameType(Vn,Tn))(t,{fn:n})}function et(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:On;return new(t._ofSameType(kn,In))(t,{fn:n})}function rt(t,n){return new(t._ofSameType(xn,Pn))(t,{n:n})}function st(t,n){return new(t._ofSameType(Mn,Dn))(t,{n:n})}function ut(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Bn;return new(t._ofSameType(Nn,Wn))(t,{fn:n})}function ot(t){return new(t._ofSameType(Un,Fn))(t)}function ht(t,n){return new(t._ofSameType(zn,Yn))(t,{n:n})}function at(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Rn;return new(t._ofSameType(Gn,Jn))(t,{fn:n})}function lt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ni;return new(t._ofSameType(Zn,ti))(t,{fn:n})}function _t(t,n){return[t,n]}function ft(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:rn;return new(t._ofSameType(ei,ri))(t,{fn:n||_t,seed:i})}function ct(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:rn;return new si(t,{fn:n,seed:i})}function dt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:hi;return new oi(t,{fn:n})}function vt(t,n){return new(t._ofSameType(_i,fi))(t,{wait:n})}function mt(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=i.leading,r=void 0===e||e,s=i.trailing,u=void 0===s||s;return new(t._ofSameType(vi,mi))(t,{wait:n,leading:r,trailing:u})}function pt(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=i.immediate,r=void 0!==e&&e;return new(t._ofSameType(yi,gi))(t,{wait:n,immediate:r})}function yt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:wi;return new(t._ofSameType(bi,Ai))(t,{fn:n})}function gt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$i;return new(t._ofSameType(Vi,Ti))(t,{fn:n})}function Et(t){return new(t._ofSameType(ki,Ii))(t)}function bt(t){return new(t._ofSameType(Li,xi))(t)}function At(t){return new(t._ofSameType(Hi,Mi))(t)}function wt(t,n){return new(t._ofSameType(qi,Ni))(t,{fn:n})}function St(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return new(t._ofSameType(Bi,ji))(t,{min:i,max:n})}function Vt(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=i.flushOnEnd,r=void 0===e||e;return new(t._ofSameType(Fi,Qi))(t,{fn:n||zi,flushOnEnd:r})}function Tt(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=i.flushOnEnd,r=void 0===e||e;return new(t._ofSameType(Ki,Gi))(t,{count:n,flushOnEnd:r})}function $t(t,n,i){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},r=e.flushOnEnd,s=void 0===r||r;return new(t._ofSameType(Ri,Xi))(t,{wait:n,count:i,flushOnEnd:s})}function Ct(t){return{"@@transducer/step":function(n,i){return t._emitValue(i),null},"@@transducer/result":function(){return t._emitEnd(),null}}}function kt(t,n){return new(t._ofSameType(te,ne))(t,{transducer:n})}function It(t,n){return new(t._ofSameType(ee,re))(t,{fn:n})}function Ot(t,n){var i=this;p.call(this),this._buffers=a(t,function(t){return se(t)?o(t):[]}),this._sources=a(t,function(t){return se(t)?g():t}),this._combinator=n?O(n,this._sources.length):function(t){return t},this._aliveCount=0,this._$handlers=[];for(var e=0;e0&&void 0!==arguments[0]?arguments[0]:{},i=n.queueLim,e=void 0===i?0:i,r=n.concurLim,s=void 0===r?-1:r,u=n.drop,o=void 0===u?"new":u;p.call(this),this._queueLim=e<0?-1:e,this._concurLim=s<0?-1:s,this._drop=o,this._queue=[],this._curSources=[],this._$handleSubAny=function(n){return t._handleSubAny(n)},this._$endHandlers=[],this._currentlyAdding=null,0===this._concurLim&&this._emitEnd()}function Pt(t){xt.call(this),this._addAll(t),this._initialised=!0}function Ht(t){return 0===t.length?g():new Pt(t)}function Mt(t){var n=this;p.call(this),this._generator=t,this._source=null,this._inLoop=!1,this._iteration=0,this._$handleAny=function(t){return n._handleAny(t)}}function Dt(t){return oe(function(n){return t.length>n&&t[n]}).setName("concat")}function qt(){xt.call(this)}function Nt(t,n,i){var e=this;xt.call(this,i),this._source=t,this._fn=n,this._mainEnded=!1,this._lastCurrent=null,this._$handleMain=function(t){return e._handleMain(t)}}function Wt(t,n){Nt.call(this,t,n)}function Bt(t,n){return function(i,e,r){var s=this;t.call(this),this._primary=i,this._secondary=e,this._name=i._name+"."+n,this._lastSecondary=rn,this._$handleSecondaryAny=function(t){return s._handleSecondaryAny(t)},this._$handlePrimaryAny=function(t){return s._handlePrimaryAny(t)},this._init(r)}}function jt(t){return{_init:function(){},_free:function(){},_handlePrimaryValue:function(t){this._emitValue(t)},_handlePrimaryError:function(t){this._emitError(t)},_handlePrimaryEnd:function(){this._emitEnd()},_handleSecondaryValue:function(t){this._lastSecondary=t},_handleSecondaryError:function(t){this._emitError(t)},_handleSecondaryEnd:function(){},_handlePrimaryAny:function(t){switch(t.type){case un:return this._handlePrimaryValue(t.value);case on:return this._handlePrimaryError(t.value);case sn:return this._handlePrimaryEnd(t.value)}},_handleSecondaryAny:function(t){switch(t.type){case un:return this._handleSecondaryValue(t.value);case on:return this._handleSecondaryError(t.value);case sn:this._handleSecondaryEnd(t.value),this._removeSecondary()}},_removeSecondary:function(){null!==this._secondary&&(this._secondary.offAny(this._$handleSecondaryAny),this._$handleSecondaryAny=null,this._secondary=null)},_onActivation:function(){null!==this._secondary&&this._secondary.onAny(this._$handleSecondaryAny),this._active&&this._primary.onAny(this._$handlePrimaryAny)},_onDeactivation:function(){null!==this._secondary&&this._secondary.offAny(this._$handleSecondaryAny),this._primary.offAny(this._$handlePrimaryAny)},_clear:function(){t.prototype._clear.call(this),this._primary=null,this._secondary=null,this._lastSecondary=null,this._$handleSecondaryAny=null,this._$handlePrimaryAny=null,this._free()}}}function Ut(t,n){var i=Bt(p,t);return e(i,p,jt(p),n),i}function Ft(t,n){var i=Bt(y,t);return e(i,y,jt(y),n),i}function Qt(t,n){return new(t._ofSameType(ae,le))(t,n)}function zt(t,n,i){return nt([n],[t],i?function(t,n){return i(n,t)}:_e).setName(t,"sampledBy")}function Yt(t,n){return new(t._ofSameType(ce,de))(t,n)}function Kt(t,n){return new(t._ofSameType(me,pe))(t,n)}function Gt(t,n,i){return new(t._ofSameType(ge,Ee))(t,n,i)}function Jt(t,n,i){return new(t._ofSameType(Ae,we))(t,n,i)}function Rt(t,n){var i=Ht([it(t,Ve),it(n,Se)]);return i=lt(i),i=U(i,Se),i.setName(t,"awaiting")}function Xt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ke;return new(t._ofSameType($e,Ce))(t,{fn:n})}function Zt(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:xe;return new(t._ofSameType(Oe,Le))(t,{fn:n})}function tn(t){return new(t._ofSameType(He,Me))(t)}function nn(){qe=!1}function en(t){if(qe&&console&&"function"==typeof console.warn){console.warn(t,"\nHere is an Error object for you containing the call stack:",new Error)}}var rn=[""],sn="end",un="value",on="error",hn="any";i(v.prototype,{add:function(t,n){return this._items=r(this._items,[{type:t,fn:n}]),this._items.length},remove:function(t,n){var i=u(this._items,function(i){return i.type===t&&i.fn===n});return 0!==this._inLoop&&-1!==i&&(null===this._removedItems&&(this._removedItems=[]),this._removedItems.push(this._items[i])),this._items=h(this._items,i),this._items.length},addSpy:function(t){return this._spies=r(this._spies,[t]),this._spies.length},removeSpy:function(t){return this._spies=h(this._spies,this._spies.indexOf(t)),this._spies.length},dispatch:function(t){this._inLoop++;for(var n=0,i=this._spies;null!==this._spies&&n0&&void 0!==arguments[0]?arguments[0]:this.toString(),n=void 0,i=function(i){var e="<"+i.type+(n?":current":"")+">";i.type===sn?console.log(t,e):console.log(t,e,i.value)};return this._alive&&(this._logHandlers||(this._logHandlers=[]),this._logHandlers.push({name:t,handler:i})),n=!0,this.onAny(i),n=!1,this},offLog:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.toString();if(this._logHandlers){var n=u(this._logHandlers,function(n){return n.name===t});-1!==n&&(this.offAny(this._logHandlers[n].handler),this._logHandlers.splice(n,1))}return this},spy:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.toString(),n=function(n){var i="<"+n.type+">";n.type===sn?console.log(t,i):console.log(t,i,n.value)};return this._alive&&(this._spyHandlers||(this._spyHandlers=[]),this._spyHandlers.push({name:t,handler:n}),this._dispatcher.addSpy(n)),this},offSpy:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.toString();if(this._spyHandlers){var n=u(this._spyHandlers,function(n){return n.name===t});-1!==n&&(this._dispatcher.removeSpy(this._spyHandlers[n].handler),this._spyHandlers.splice(n,1))}return this}}),m.prototype.toString=function(){return"["+this._name+"]"},e(p,m,{_name:"stream",getType:function(){return"stream"}}),e(y,m,{_name:"property",_emitValue:function(t){this._alive&&(this._currentEvent={type:un,value:t},this._activating||this._dispatcher.dispatch({type:un,value:t}))},_emitError:function(t){this._alive&&(this._currentEvent={type:on,value:t},this._activating||this._dispatcher.dispatch({type:on,value:t}))},_emitEnd:function(){this._alive&&(this._alive=!1,this._activating||this._dispatcher.dispatch({type:sn}),this._clear())},_on:function(t,n){return this._alive&&(this._dispatcher.add(t,n),this._setActive(!0)),null!==this._currentEvent&&d(t,n,this._currentEvent),this._alive||d(t,n,{type:sn}),this},getType:function(){return"property"}});var an=new p;an._emitEnd(),an._name="never";var ln=E({_name:"later",_init:function(t){var n=t.x;this._x=n},_free:function(){this._x=null},_onTick:function(){this._emitValue(this._x),this._emitEnd()}}),_n=E({_name:"interval",_init:function(t){var n=t.x;this._x=n},_free:function(){this._x=null},_onTick:function(){this._emitValue(this._x)}}),fn=E({_name:"sequentially",_init:function(t){var n=t.xs;this._xs=o(n)},_free:function(){this._xs=null},_onTick:function(){1===this._xs.length?(this._emitValue(this._xs[0]),this._emitEnd()):this._emitValue(this._xs.shift())}}),cn=E({_name:"fromPoll",_init:function(t){var n=t.fn;this._fn=n},_free:function(){this._fn=null},_onTick:function(){var t=this._fn;this._emitValue(t())}}),dn=E({_name:"withInterval",_init:function(t){var n=t.fn;this._fn=n,this._emitter=V(this)},_free:function(){this._fn=null,this._emitter=null},_onTick:function(){(0,this._fn)(this._emitter)}});e($,p,{_name:"stream",_onActivation:function(){var t=this._fn,n=t(V(this));this._unsubscribe="function"==typeof n?n:null,this._active||this._callUnsubscribe()},_callUnsubscribe:function(){null!==this._unsubscribe&&(this._unsubscribe(),this._unsubscribe=null)},_onDeactivation:function(){this._callUnsubscribe()},_clear:function(){p.prototype._clear.call(this),this._fn=null}});var vn=[["addEventListener","removeEventListener"],["addListener","removeListener"],["on","off"]];e(H,y,{_name:"constant",_active:!1,_activating:!1,_alive:!1,_dispatcher:null,_logHandlers:null}),e(D,y,{_name:"constantError",_active:!1,_activating:!1,_alive:!1,_dispatcher:null,_logHandlers:null});var mn,pn=j("toProperty",{_init:function(t){var n=t.fn;this._getInitialCurrent=n},_onActivation:function(){if(null!==this._getInitialCurrent){var t=this._getInitialCurrent;this._emitValue(t())}this._source.onAny(this._$handleAny)}}),yn=B("changes",{_handleValue:function(t){this._activating||this._emitValue(t)},_handleError:function(t){this._activating||this._emitError(t)}}),gn=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:z(),i=null;return new n(function(n,e){t.onAny(function(t){t.type===sn&&null!==i?((i.type===un?n:e)(i.value),i=null):i=t})})};mn="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")();var En=function(t){var n,i=t.Symbol;return"function"==typeof i?i.observable?n=i.observable:(n=i("observable"),i.observable=n):n="@@observable",n}(mn),bn=En.default?En.default:En;i(K.prototype,{subscribe:function(t,n,i){var e=this,r="function"==typeof t?{next:t,error:n,complete:i}:t,s=function(t){t.type===sn&&(u=!0),t.type===un&&r.next?r.next(t.value):t.type===on&&r.error?r.error(t.value):t.type===sn&&r.complete&&r.complete(t.value)};this._observable.onAny(s);var u=!1;return{unsubscribe:function(){u=!0,e._observable.offAny(s)},get closed(){return u}}}}),K.prototype[bn]=function(){return this},e(X,p,{_name:"combine",_onActivation:function(){this._aliveCount=this._activeCount;for(var t=this._activeCount;t=0)this._timeoutId=setTimeout(this._$later,this._wait-t);else{if(this._timeoutId=null,!this._immediate){var n=this._laterValue;this._laterValue=null,this._emitValue(n)}this._endLater&&this._emitEnd()}}},yi=B("debounce",pi),gi=j("debounce",pi),Ei={_init:function(t){var n=t.fn;this._fn=n},_free:function(){this._fn=null},_handleError:function(t){var n=this._fn;this._emitError(n(t))}},bi=B("mapErrors",Ei),Ai=j("mapErrors",Ei),wi=function(t){return t},Si={_init:function(t){var n=t.fn;this._fn=n},_free:function(){this._fn=null},_handleError:function(t){(0,this._fn)(t)&&this._emitError(t)}},Vi=B("filterErrors",Si),Ti=j("filterErrors",Si),$i=function(t){return t},Ci={_handleValue:function(){}},ki=B("ignoreValues",Ci),Ii=j("ignoreValues",Ci),Oi={_handleError:function(){}},Li=B("ignoreErrors",Oi),xi=j("ignoreErrors",Oi),Pi={_handleEnd:function(){}},Hi=B("ignoreEnd",Pi),Mi=j("ignoreEnd",Pi),Di={_init:function(t){var n=t.fn;this._fn=n},_free:function(){this._fn=null},_handleEnd:function(){var t=this._fn;this._emitValue(t()),this._emitEnd()}},qi=B("beforeEnd",Di),Ni=j("beforeEnd",Di),Wi={_init:function(t){var n=t.min,i=t.max;this._max=i,this._min=n,this._buff=[]},_free:function(){this._buff=null},_handleValue:function(t){this._buff=c(this._buff,t,this._max),this._buff.length>=this._min&&this._emitValue(this._buff)}},Bi=B("slidingWindow",Wi),ji=j("slidingWindow",Wi),Ui={_init:function(t){var n=t.fn,i=t.flushOnEnd;this._fn=n,this._flushOnEnd=i,this._buff=[]},_free:function(){this._buff=null},_flush:function(){null!==this._buff&&0!==this._buff.length&&(this._emitValue(this._buff),this._buff=[])},_handleValue:function(t){this._buff.push(t),(0,this._fn)(t)||this._flush()},_handleEnd:function(){this._flushOnEnd&&this._flush(),this._emitEnd()}},Fi=B("bufferWhile",Ui),Qi=j("bufferWhile",Ui),zi=function(t){return t},Yi={_init:function(t){var n=t.count,i=t.flushOnEnd;this._count=n,this._flushOnEnd=i,this._buff=[]},_free:function(){this._buff=null},_flush:function(){null!==this._buff&&0!==this._buff.length&&(this._emitValue(this._buff),this._buff=[])},_handleValue:function(t){this._buff.push(t),this._buff.length>=this._count&&this._flush()},_handleEnd:function(){this._flushOnEnd&&this._flush(),this._emitEnd()}},Ki=B("bufferWithCount",Yi),Gi=j("bufferWithCount",Yi),Ji={_init:function(t){ +var n=this,i=t.wait,e=t.count,r=t.flushOnEnd;this._wait=i,this._count=e,this._flushOnEnd=r,this._intervalId=null,this._$onTick=function(){return n._flush()},this._buff=[]},_free:function(){this._$onTick=null,this._buff=null},_flush:function(){null!==this._buff&&(this._emitValue(this._buff),this._buff=[])},_handleValue:function(t){this._buff.push(t),this._buff.length>=this._count&&(clearInterval(this._intervalId),this._flush(),this._intervalId=setInterval(this._$onTick,this._wait))},_handleEnd:function(){this._flushOnEnd&&0!==this._buff.length&&this._flush(),this._emitEnd()},_onActivation:function(){this._intervalId=setInterval(this._$onTick,this._wait),this._source.onAny(this._$handleAny)},_onDeactivation:function(){null!==this._intervalId&&(clearInterval(this._intervalId),this._intervalId=null),this._source.offAny(this._$handleAny)}},Ri=B("bufferWithTimeOrCount",Ji),Xi=j("bufferWithTimeOrCount",Ji),Zi={_init:function(t){var n=t.transducer;this._xform=n(Ct(this))},_free:function(){this._xform=null},_handleValue:function(t){null!==this._xform["@@transducer/step"](null,t)&&this._xform["@@transducer/result"](null)},_handleEnd:function(){this._xform["@@transducer/result"](null)}},te=B("transduce",Zi),ne=j("transduce",Zi),ie={_init:function(t){var n=t.fn;this._handler=n,this._emitter=V(this)},_free:function(){this._handler=null,this._emitter=null},_handleAny:function(t){this._handler(this._emitter,t)}},ee=B("withHandler",ie),re=j("withHandler",ie),se=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};e(Ot,p,{_name:"zip",_onActivation:function(){for(;this._isFull();)this._emit();var t=this._sources.length;this._aliveCount=t;for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},n=t.flushOnEnd,i=void 0===n||n;this._buff=[],this._flushOnEnd=i},_free:function(){this._buff=null},_flush:function(){null!==this._buff&&(this._emitValue(this._buff),this._buff=[])},_handlePrimaryEnd:function(){this._flushOnEnd&&this._flush(),this._emitEnd()},_onActivation:function(){this._primary.onAny(this._$handlePrimaryAny),this._alive&&null!==this._secondary&&this._secondary.onAny(this._$handleSecondaryAny)},_handlePrimaryValue:function(t){this._buff.push(t)},_handleSecondaryValue:function(){this._flush()},_handleSecondaryEnd:function(){this._flushOnEnd||this._emitEnd()}},ge=Ut("bufferBy",ye),Ee=Ft("bufferBy",ye),be={_init:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.flushOnEnd,i=void 0===n||n,e=t.flushOnChange,r=void 0!==e&&e;this._buff=[],this._flushOnEnd=i,this._flushOnChange=r},_free:function(){this._buff=null},_flush:function(){null!==this._buff&&(this._emitValue(this._buff),this._buff=[])},_handlePrimaryEnd:function(){this._flushOnEnd&&this._flush(),this._emitEnd()},_handlePrimaryValue:function(t){this._buff.push(t),this._lastSecondary===rn||this._lastSecondary||this._flush()},_handleSecondaryEnd:function(){this._flushOnEnd||this._lastSecondary!==rn&&!this._lastSecondary||this._emitEnd()},_handleSecondaryValue:function(t){this._flushOnChange&&!t&&this._flush(),this._lastSecondary=t}},Ae=Ut("bufferWhileBy",be),we=Ft("bufferWhileBy",be),Se=function(){return!1},Ve=function(){return!0},Te={_init:function(t){var n=t.fn;this._fn=n},_free:function(){this._fn=null},_handleValue:function(t){var n=this._fn,i=n(t);i.convert?this._emitError(i.error):this._emitValue(t)}},$e=B("valuesToErrors",Te),Ce=j("valuesToErrors",Te),ke=function(t){return{convert:!0,error:t}},Ie={_init:function(t){var n=t.fn;this._fn=n},_free:function(){this._fn=null},_handleError:function(t){var n=this._fn,i=n(t);i.convert?this._emitValue(i.value):this._emitError(t)}},Oe=B("errorsToValues",Ie),Le=j("errorsToValues",Ie),xe=function(t){return{convert:!0,value:t}},Pe={_handleError:function(t){this._emitError(t),this._emitEnd()}},He=B("endOnError",Pe),Me=j("endOnError",Pe);m.prototype.toProperty=function(t){return U(this,t)},m.prototype.changes=function(){return F(this)},m.prototype.toPromise=function(t){return gn(this,t)},m.prototype.toESObservable=G,m.prototype[bn]=G,m.prototype.map=function(t){return it(this,t)},m.prototype.filter=function(t){return et(this,t)},m.prototype.take=function(t){return rt(this,t)},m.prototype.takeErrors=function(t){return st(this,t)},m.prototype.takeWhile=function(t){return ut(this,t)},m.prototype.last=function(){return ot(this)},m.prototype.skip=function(t){return ht(this,t)},m.prototype.skipWhile=function(t){return at(this,t)},m.prototype.skipDuplicates=function(t){return lt(this,t)},m.prototype.diff=function(t,n){return ft(this,t,n)},m.prototype.scan=function(t,n){return ct(this,t,n)},m.prototype.flatten=function(t){return dt(this,t)},m.prototype.delay=function(t){return vt(this,t)},m.prototype.throttle=function(t,n){return mt(this,t,n)},m.prototype.debounce=function(t,n){return pt(this,t,n)},m.prototype.mapErrors=function(t){return yt(this,t)},m.prototype.filterErrors=function(t){return gt(this,t)},m.prototype.ignoreValues=function(){return Et(this)},m.prototype.ignoreErrors=function(){return bt(this)},m.prototype.ignoreEnd=function(){return At(this)},m.prototype.beforeEnd=function(t){return wt(this,t)},m.prototype.slidingWindow=function(t,n){return St(this,t,n)},m.prototype.bufferWhile=function(t,n){return Vt(this,t,n)},m.prototype.bufferWithCount=function(t,n){return Tt(this,t,n)},m.prototype.bufferWithTimeOrCount=function(t,n,i){return $t(this,t,n,i)},m.prototype.transduce=function(t){return kt(this,t)},m.prototype.withHandler=function(t){return It(this,t)},m.prototype.thru=function(t){return t(this)},m.prototype.combine=function(t,n){return nt([this,t],n)},m.prototype.zip=function(t,n){return Lt([this,t],n)},m.prototype.merge=function(t){return Ht([this,t])},m.prototype.concat=function(t){return Dt([this,t])};var De=function(){return new qt};m.prototype.flatMap=function(t){return new Nt(this,t).setName(this,"flatMap")},m.prototype.flatMapLatest=function(t){return new Nt(this,t,{concurLim:1,drop:"old"}).setName(this,"flatMapLatest")},m.prototype.flatMapFirst=function(t){return new Nt(this,t,{concurLim:1}).setName(this,"flatMapFirst")},m.prototype.flatMapConcat=function(t){return new Nt(this,t,{queueLim:-1,concurLim:1}).setName(this,"flatMapConcat")},m.prototype.flatMapConcurLimit=function(t,n){return new Nt(this,t,{queueLim:-1,concurLim:n}).setName(this,"flatMapConcurLimit")},m.prototype.flatMapErrors=function(t){return new Wt(this,t).setName(this,"flatMapErrors")},m.prototype.filterBy=function(t){return Qt(this,t)},m.prototype.sampledBy=function(t,n){return zt(this,t,n)},m.prototype.skipUntilBy=function(t){return Yt(this,t)},m.prototype.takeUntilBy=function(t){return Kt(this,t)},m.prototype.bufferBy=function(t,n){return Gt(this,t,n)},m.prototype.bufferWhileBy=function(t,n){return Jt(this,t,n)};var qe=!0;m.prototype.awaiting=function(t){return en("You are using deprecated .awaiting() method, see https://github.com/kefirjs/kefir/issues/145"),Rt(this,t)},m.prototype.valuesToErrors=function(t){return en("You are using deprecated .valuesToErrors() method, see https://github.com/kefirjs/kefir/issues/149"),Xt(this,t)},m.prototype.errorsToValues=function(t){return en("You are using deprecated .errorsToValues() method, see https://github.com/kefirjs/kefir/issues/149"),Zt(this,t)},m.prototype.endOnError=function(){return en("You are using deprecated .endOnError() method, see https://github.com/kefirjs/kefir/issues/150"),tn(this)};var Ne={Observable:m,Stream:p,Property:y,never:g,later:b,interval:A,sequentially:w,fromPoll:S,withInterval:T,fromCallback:k,fromNodeCallback:I,fromEvents:P,stream:C,constant:M,constantError:q,fromPromise:Q,fromESObservable:Y,combine:nt,zip:Lt,merge:Ht,concat:Dt,Pool:qt,pool:De,repeat:oe,staticLand:wn};Ne.Kefir=Ne,t.dissableDeprecationWarnings=nn,t.Kefir=Ne,t.Observable=m,t.Stream=p,t.Property=y,t.never=g,t.later=b,t.interval=A,t.sequentially=w,t.fromPoll=S,t.withInterval=T,t.fromCallback=k,t.fromNodeCallback=I,t.fromEvents=P,t.stream=C,t.constant=M,t.constantError=q,t.fromPromise=Q,t.fromESObservable=Y,t.combine=nt,t.zip=Lt,t.merge=Ht,t.concat=Dt,t.Pool=qt,t.pool=De,t.repeat=oe,t.staticLand=wn,t.default=Ne,Object.defineProperty(t,"__esModule",{value:!0})}); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..f439a1aa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.8' +services: + app: + build: . + volumes: + - .:/code/ + - node_modules:/code/node_modules + +volumes: + node_modules: diff --git a/package-lock.json b/package-lock.json index 9433591e..d42284ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kefir", - "version": "3.8.6", + "version": "3.8.8", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -55,6 +55,12 @@ "@types/babel-types": "*" } }, + "@ungap/promise-all-settled": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", + "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", + "dev": true + }, "acorn": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", @@ -90,9 +96,9 @@ } }, "ansi-colors": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", - "integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true }, "ansi-escapes": { @@ -113,15 +119,22 @@ "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, - "argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", "dev": true, "requires": { - "sprintf-js": "~1.0.2" + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" } }, + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, "array-from": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", @@ -1171,6 +1184,12 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1181,6 +1200,15 @@ "concat-map": "0.0.1" } }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, "browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", @@ -1194,9 +1222,9 @@ "dev": true }, "camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", + "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==", "dev": true }, "center-align": { @@ -1267,6 +1295,22 @@ "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", "dev": true }, + "chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "dev": true, + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, "clean-css": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.1.tgz", @@ -1292,39 +1336,50 @@ "dev": true }, "cliui": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", - "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", "dev": true, "requires": { - "string-width": "^2.1.1", - "strip-ansi": "^4.0.0", - "wrap-ansi": "^2.0.0" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" }, "dependencies": { "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "is-fullwidth-code-point": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, + "string-width": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", + "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", "dev": true, "requires": { - "ansi-regex": "^3.0.0" + "ansi-regex": "^5.0.0" } } } }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true - }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -1373,27 +1428,6 @@ "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=", "dev": true }, - "cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, - "requires": { - "nice-try": "^1.0.4", - "path-key": "^2.0.1", - "semver": "^5.5.0", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - }, - "dependencies": { - "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", - "dev": true - } - } - }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -1418,15 +1452,6 @@ "type-detect": "^4.0.0" } }, - "define-properties": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", - "dev": true, - "requires": { - "object-keys": "^1.0.12" - } - }, "detect-indent": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz", @@ -1449,44 +1474,16 @@ "dev": true }, "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, - "end-of-stream": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "dev": true, - "requires": { - "once": "^1.4.0" - } - }, - "es-abstract": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", - "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", - "dev": true, - "requires": { - "es-to-primitive": "^1.2.0", - "function-bind": "^1.1.1", - "has": "^1.0.3", - "is-callable": "^1.1.4", - "is-regex": "^1.0.4", - "object-keys": "^1.0.12" - } - }, - "es-to-primitive": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", - "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", - "dev": true, - "requires": { - "is-callable": "^1.1.4", - "is-date-object": "^1.0.1", - "is-symbol": "^1.0.2" - } + "escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "dev": true }, "escape-string-regexp": { "version": "1.0.5", @@ -1494,12 +1491,6 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true - }, "estree-walker": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.2.1.tgz", @@ -1512,21 +1503,6 @@ "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "dev": true }, - "execa": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", - "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", - "dev": true, - "requires": { - "cross-spawn": "^6.0.0", - "get-stream": "^4.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } - }, "external-editor": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", @@ -1547,24 +1523,31 @@ "escape-string-regexp": "^1.0.5" } }, - "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "dev": true, "requires": { - "locate-path": "^3.0.0" + "to-regex-range": "^5.0.1" } }, - "flat": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", - "integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==", + "find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "requires": { - "is-buffer": "~2.0.3" + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" } }, + "flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "dev": true + }, "flow-bin": { "version": "0.100.0", "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.100.0.tgz", @@ -1577,6 +1560,13 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "optional": true + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -1595,19 +1585,10 @@ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -1618,6 +1599,15 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, "globals": { "version": "9.18.0", "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", @@ -1654,12 +1644,6 @@ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, - "has-symbols": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", - "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", - "dev": true - }, "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -1696,9 +1680,9 @@ } }, "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "inquirer": { @@ -1777,29 +1761,14 @@ "loose-envify": "^1.0.0" } }, - "invert-kv": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", - "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", - "dev": true - }, - "is-buffer": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", - "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==", - "dev": true - }, - "is-callable": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", - "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", - "dev": true - }, - "is-date-object": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", - "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", - "dev": true + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } }, "is-expression": { "version": "3.0.0", @@ -1819,6 +1788,12 @@ } } }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, "is-finite": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", @@ -1834,12 +1809,33 @@ "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, "is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", "dev": true }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true + }, "is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", @@ -1855,21 +1851,12 @@ "has": "^1.0.1" } }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", + "is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "dev": true }, - "is-symbol": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", - "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", - "dev": true, - "requires": { - "has-symbols": "^1.0.0" - } - }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -1895,13 +1882,12 @@ "dev": true }, "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" + "argparse": "^2.0.1" } }, "jsesc": { @@ -1964,23 +1950,13 @@ "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", "dev": true }, - "lcid": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", - "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", - "dev": true, - "requires": { - "invert-kv": "^2.0.0" - } - }, "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" + "p-locate": "^5.0.0" } }, "lodash": { @@ -1990,41 +1966,62 @@ "dev": true }, "log-symbols": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", - "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dev": true, "requires": { - "chalk": "^2.0.1" + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" }, "dependencies": { "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "requires": { - "color-convert": "^1.9.0" + "color-convert": "^2.0.1" } }, "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" } }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "^4.0.0" } } } @@ -2059,34 +2056,6 @@ "vlq": "^0.2.2" } }, - "map-age-cleaner": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", - "dev": true, - "requires": { - "p-defer": "^1.0.0" - } - }, - "mem": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", - "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", - "dev": true, - "requires": { - "map-age-cleaner": "^0.1.1", - "mimic-fn": "^2.0.0", - "p-is-promise": "^2.0.0" - }, - "dependencies": { - "mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "dev": true - } - } - }, "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", @@ -2118,58 +2087,86 @@ } }, "mocha": { - "version": "6.1.4", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-6.1.4.tgz", - "integrity": "sha512-PN8CIy4RXsIoxoFJzS4QNnCH4psUCPWc4/rPrst/ecSJJbLBkubMiyGCP2Kj/9YnWbotFqAoeXyXMucj7gwCFg==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.0.3.tgz", + "integrity": "sha512-hnYFrSefHxYS2XFGtN01x8un0EwNu2bzKvhpRFhgoybIvMaOkkL60IVPmkb5h6XDmUl4IMSB+rT5cIO4/4bJgg==", "dev": true, "requires": { - "ansi-colors": "3.2.3", + "@ungap/promise-all-settled": "1.1.2", + "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "debug": "3.2.6", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "find-up": "3.0.0", - "glob": "7.1.3", + "chokidar": "3.5.2", + "debug": "4.3.1", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.1.7", "growl": "1.10.5", "he": "1.2.0", - "js-yaml": "3.13.1", - "log-symbols": "2.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", "minimatch": "3.0.4", - "mkdirp": "0.5.1", - "ms": "2.1.1", - "node-environment-flags": "1.0.5", - "object.assign": "4.1.0", - "strip-json-comments": "2.0.1", - "supports-color": "6.0.0", - "which": "1.3.1", + "ms": "2.1.3", + "nanoid": "3.1.23", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "which": "2.0.2", "wide-align": "1.1.3", - "yargs": "13.2.2", - "yargs-parser": "13.0.0", - "yargs-unparser": "1.5.0" + "workerpool": "6.1.5", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" }, "dependencies": { "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", "dev": true, "requires": { - "ms": "^2.1.1" + "ms": "2.1.2" + }, + "dependencies": { + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } } }, + "diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, "supports-color": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz", - "integrity": "sha512-on9Kwidc1IUQo+bQdhi8+Tijpo0e1SS6RoGo2guUwn5vdaxw8RXOF9Vb2ws+ihWOmh4JnCJOvaziZWP1VABaLg==", + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "^4.0.0" } } } @@ -2186,10 +2183,10 @@ "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, - "nice-try": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "nanoid": { + "version": "3.1.23", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz", + "integrity": "sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==", "dev": true }, "nise": { @@ -2213,32 +2210,11 @@ } } }, - "node-environment-flags": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.5.tgz", - "integrity": "sha512-VNYPRfGfmZLx0Ye20jWzHUjyTW/c+6Wq+iLhDzUI4XmhrDd9l/FozXV3F2xOaXjvp0co0+v1YSR3CMP6g+VvLQ==", - "dev": true, - "requires": { - "object.getownpropertydescriptors": "^2.0.3", - "semver": "^5.7.0" - }, - "dependencies": { - "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", - "dev": true - } - } - }, - "npm-run-path": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", - "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", - "dev": true, - "requires": { - "path-key": "^2.0.0" - } + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true }, "number-is-nan": { "version": "1.0.1", @@ -2252,34 +2228,6 @@ "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "dev": true }, - "object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true - }, - "object.assign": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", - "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", - "dev": true, - "requires": { - "define-properties": "^1.1.2", - "function-bind": "^1.1.1", - "has-symbols": "^1.0.0", - "object-keys": "^1.0.11" - } - }, - "object.getownpropertydescriptors": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", - "integrity": "sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY=", - "dev": true, - "requires": { - "define-properties": "^1.1.2", - "es-abstract": "^1.5.1" - } - }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -2304,69 +2252,34 @@ "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true }, - "os-locale": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", - "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", - "dev": true, - "requires": { - "execa": "^1.0.0", - "lcid": "^2.0.0", - "mem": "^4.0.0" - } - }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, - "p-defer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", - "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", - "dev": true - }, - "p-finally": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", - "dev": true - }, - "p-is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", - "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==", - "dev": true - }, "p-limit": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", - "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "requires": { - "p-try": "^2.0.0" + "yocto-queue": "^0.1.0" } }, "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "requires": { - "p-limit": "^2.0.0" + "p-limit": "^3.0.2" } }, - "p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true - }, "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, "path-is-absolute": { @@ -2375,12 +2288,6 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, - "path-key": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", - "dev": true - }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", @@ -2402,6 +2309,12 @@ "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", "dev": true }, + "picomatch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", + "dev": true + }, "prettier": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz", @@ -2549,14 +2462,22 @@ "integrity": "sha1-wA1cUSi6xYBr7BXSt+fNq+QlMfM=", "dev": true }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.0" + } + }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" + "picomatch": "^2.2.1" } }, "regenerate": { @@ -2647,12 +2568,6 @@ "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, - "require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", - "dev": true - }, "resolve": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", @@ -2757,6 +2672,42 @@ "resolve": "^1.1.6" } }, + "rollup-plugin-strip-code": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/rollup-plugin-strip-code/-/rollup-plugin-strip-code-0.2.7.tgz", + "integrity": "sha512-+5t9u/VrHPSfiRWWKMVin+KOtFwFak337FAZxeTjxYDjB3DDoHBQRkXHQvBn713eAfW81t41mGuysqsMXiuTjw==", + "dev": true, + "requires": { + "magic-string": "0.25.3", + "rollup-pluginutils": "2.8.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, + "magic-string": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", + "integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, + "rollup-pluginutils": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz", + "integrity": "sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + } + } + } + }, "rollup-plugin-uglify": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-1.0.2.tgz", @@ -2812,27 +2763,15 @@ "integrity": "sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ==", "dev": true }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true - }, - "shebang-command": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", "dev": true, "requires": { - "shebang-regex": "^1.0.0" + "randombytes": "^2.1.0" } }, - "shebang-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", - "dev": true - }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -2906,10 +2845,10 @@ } } }, - "sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", "dev": true }, "string-width": { @@ -2948,16 +2887,10 @@ "ansi-regex": "^2.0.0" } }, - "strip-eof": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", - "dev": true - }, "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, "supports-color": { @@ -2993,6 +2926,15 @@ "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=", "dev": true }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + }, "token-stream": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz", @@ -3097,20 +3039,14 @@ "dev": true }, "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, "requires": { "isexe": "^2.0.0" } }, - "which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", - "dev": true - }, "wide-align": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", @@ -3142,34 +3078,77 @@ "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", "dev": true }, + "workerpool": { + "version": "6.1.5", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.5.tgz", + "integrity": "sha512-XdKkCK0Zqc6w3iTxLckiuJ81tiD/o5rBE/m+nXpRCB+/Sq4DqkfXZ/x0jW02DG1tGsfUGXbTJyZDP+eu67haSw==", + "dev": true + }, "wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, "requires": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "dependencies": { - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "requires": { - "number-is-nan": "^1.0.0" + "color-convert": "^2.0.1" } }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", + "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", "dev": true, "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" + "ansi-regex": "^5.0.0" } } } @@ -3181,123 +3160,92 @@ "dev": true }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true }, "yargs": { - "version": "13.2.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.2.tgz", - "integrity": "sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA==", + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, "requires": { - "cliui": "^4.0.0", - "find-up": "^3.0.0", - "get-caller-file": "^2.0.1", - "os-locale": "^3.1.0", + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^3.0.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^13.0.0" + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" }, "dependencies": { "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", + "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==", "dev": true, "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" } }, "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", "dev": true, "requires": { - "ansi-regex": "^4.1.0" + "ansi-regex": "^5.0.0" } } } }, "yargs-parser": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.0.0.tgz", - "integrity": "sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw==", - "dev": true, - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } + "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "dev": true }, "yargs-unparser": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.5.0.tgz", - "integrity": "sha512-HK25qidFTCVuj/D1VfNiEndpLIeJN78aqgR23nL3y4N0U/91cOAzqfHlF8n2BvoNDcZmJKin3ddNSvOxSr8flw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "requires": { - "flat": "^4.1.0", - "lodash": "^4.17.11", - "yargs": "^12.0.5" + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" }, "dependencies": { - "get-caller-file": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", - "dev": true - }, - "require-main-filename": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", + "decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true - }, - "yargs": { - "version": "12.0.5", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", - "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", - "dev": true, - "requires": { - "cliui": "^4.0.0", - "decamelize": "^1.2.0", - "find-up": "^3.0.0", - "get-caller-file": "^1.0.1", - "os-locale": "^3.0.0", - "require-directory": "^2.1.1", - "require-main-filename": "^1.0.1", - "set-blocking": "^2.0.0", - "string-width": "^2.0.0", - "which-module": "^2.0.0", - "y18n": "^3.2.1 || ^4.0.0", - "yargs-parser": "^11.1.1" - } - }, - "yargs-parser": { - "version": "11.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", - "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", - "dev": true, - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } } } }, + "yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true + }, "zen-observable": { "version": "0.8.14", "resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.14.tgz", diff --git a/package.json b/package.json index c7a01e71..f7d6c056 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build": "npm run clean && npm run build-js && npm run build-docs", "test": "npm run prettier-check && rollup -c ./configs/rollup.dev.js && mocha && flow check", "test-only": "rollup -c ./configs/rollup.dev.js && mocha", - "test-debug": "rollup -c ./configs/rollup.dev.js && mocha --inspect-brk" + "test-debug": "rollup -c ./configs/rollup.dev.js && mocha --inspect-brk", + "watch": "npm run prettier-check && rollup -c ./configs/rollup.dev.js && mocha --watch" }, "keywords": [ "frp", @@ -44,13 +45,14 @@ "chai-kefir": "^2.0.1", "flow-bin": "^0.100.0", "inquirer": "^6.3.1", - "mocha": "^6.1.4", + "mocha": "^9.0.3", "prettier": "^1.18.2", "pug": "^2.0.3", "rollup": "^0.41.6", "rollup-plugin-babel": "^2.7.1", "rollup-plugin-commonjs": "^8.0.2", "rollup-plugin-node-resolve": "^3.0.0", + "rollup-plugin-strip-code": "^0.2.7", "rollup-plugin-uglify": "^1.0.1", "rxjs": "^6.5.2", "semver": "^6.1.1", diff --git a/src/index.js b/src/index.js index 87ecec03..be9387fc 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,10 @@ import Observable from './observable' import Stream from './stream' import Property from './property' +/* dev-code */ +import {activeObservables, clearActiveObservables} from './utils/dev' +/* end-dev-code */ + // Create a stream // ----------------------------------------------------------------------------- @@ -468,6 +472,10 @@ const Kefir = { pool, repeat, staticLand, + /* dev-code */ + activeObservables, + clearActiveObservables, + /* end-dev-code */ } Kefir.Kefir = Kefir @@ -499,6 +507,10 @@ export { pool, repeat, staticLand, + /* dev-code */ + activeObservables, + clearActiveObservables, + /* end-dev-code */ } export default Kefir diff --git a/src/observable.js b/src/observable.js index 677d152e..47913081 100644 --- a/src/observable.js +++ b/src/observable.js @@ -3,6 +3,10 @@ import {VALUE, ERROR, ANY, END} from './constants' import {Dispatcher, callSubscriber} from './dispatcher' import {findByPred} from './utils/collections' +/* dev-code */ +import {activeObservables} from './utils/dev' +/* end-dev-code */ + function Observable() { this._dispatcher = new Dispatcher() this._active = false @@ -15,8 +19,16 @@ function Observable() { extend(Observable.prototype, { _name: 'observable', - _onActivation() {}, - _onDeactivation() {}, + _onActivation() { + /* dev-code */ + activeObservables.push(this) + /* end-dev-code */ + }, + _onDeactivation() { + /* dev-code */ + activeObservables.splice(activeObservables.indexOf(this), 1) + /* end-dev-code */ + }, _setActive(active) { if (this._active !== active) { diff --git a/src/utils/dev.js b/src/utils/dev.js new file mode 100644 index 00000000..2c3c2c8b --- /dev/null +++ b/src/utils/dev.js @@ -0,0 +1,7 @@ +let activeObservables = [] + +function clearActiveObservables() { + activeObservables = [] +} + +export {activeObservables, clearActiveObservables} diff --git a/test/mocha.opts b/test/mocha.opts deleted file mode 100644 index 95288221..00000000 --- a/test/mocha.opts +++ /dev/null @@ -1,3 +0,0 @@ ---reporter spec ---ui bdd -test/specs/*.js diff --git a/test/specs/active-observables.js b/test/specs/active-observables.js new file mode 100644 index 00000000..769898b9 --- /dev/null +++ b/test/specs/active-observables.js @@ -0,0 +1,128 @@ +const {Kefir, expect} = require('../test-helpers') + +describe('activeObservables', () => { + const noop = () => {} + + describe('Observable', () => { + it('counts active observables', () => { + const observable = new Kefir.Observable() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + }) + + it('counts all observable activations', () => { + const observable = new Kefir.Observable() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(0) + }) + + it('multiple subscriptions do not count as multiple active observables', () => { + const observable = new Kefir.Observable() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.onError(noop) + expect(Kefir.activeObservables.length).to.equal(1) + + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offError(noop) + expect(Kefir.activeObservables.length).to.equal(0) + }) + }) + + describe('Property', () => { + it('counts active observables', () => { + const observable = new Kefir.Property() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + }) + + it('counts all observable activations', () => { + const observable = new Kefir.Property() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(0) + }) + + it('multiple subscriptions do not count as multiple active observables', () => { + const observable = new Kefir.Property() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.onError(noop) + expect(Kefir.activeObservables.length).to.equal(1) + + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offError(noop) + expect(Kefir.activeObservables.length).to.equal(0) + }) + }) + + describe('Stream', () => { + it('counts active observables', () => { + const observable = new Kefir.Stream() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + }) + + it('counts all observable activations', () => { + const observable = new Kefir.Stream() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(0) + }) + + it('multiple subscriptions do not count as multiple active observables', () => { + const observable = new Kefir.Stream() + expect(Kefir.activeObservables.length).to.equal(0) + + observable.onValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.onError(noop) + expect(Kefir.activeObservables.length).to.equal(1) + + observable.offValue(noop) + expect(Kefir.activeObservables.length).to.equal(1) + observable.offError(noop) + expect(Kefir.activeObservables.length).to.equal(0) + }) + }) +}) diff --git a/test/specs/concat.js b/test/specs/concat.js index 7a317109..d2b9ffc9 100644 --- a/test/specs/concat.js +++ b/test/specs/concat.js @@ -67,17 +67,19 @@ describe('concat', () => { const b = send(prop(), [value(1)]) const c = stream() - let concat = Kefir.concat([a, b, c]) - expect(concat).to.emit([value(0, {current: true})]) + const concatA = Kefir.concat([a, b, c]) + expect(concatA).to.emit([value(0, {current: true})]) - concat = Kefir.concat([a, b, c]) - activate(concat) - expect(concat).to.emit([]) + const concatB = Kefir.concat([a, b, c]) + activate(concatB) + expect(concatB).to.emit([]) - concat = Kefir.concat([a, b, c]) - activate(concat) - deactivate(concat) - expect(concat).to.emit([value(0, {current: true})]) + const concatC = Kefir.concat([a, b, c]) + activate(concatC) + deactivate(concatC) + expect(concatC).to.emit([value(0, {current: true})]) + + deactivate(concatB) }) it('if made of ended properties, should emit all currents then end', () => { diff --git a/test/specs/flat-map-first.js b/test/specs/flat-map-first.js index 13574543..a1482c7a 100644 --- a/test/specs/flat-map-first.js +++ b/test/specs/flat-map-first.js @@ -102,6 +102,7 @@ describe('flatMapFirst', () => { expect(count).to.equal(1) send(a, [value(c)]) expect(count).to.equal(2) + deactivate(result) }) }) diff --git a/test/specs/log.js b/test/specs/log.js index db8bfa35..5871bfaf 100644 --- a/test/specs/log.js +++ b/test/specs/log.js @@ -4,12 +4,15 @@ const sinon = require('sinon') describe('log', () => { describe('adding', () => { it('should return the stream', () => { - expect(stream().log()).to.be.observable.stream() + const a = stream() + expect(a.log()).to.be.observable.stream() + a.offLog() }) it('should activate the stream', () => { const a = stream().log() expect(a).to.be.active() + a.offLog() }) }) @@ -45,6 +48,7 @@ describe('log', () => { expect(console.log).to.have.been.calledWith('[stream]', '', 2) expect(console.log).to.have.been.calledWith('[stream]', '', 3) }) + a.offLog() }) it('should use the name', () => { @@ -56,6 +60,7 @@ describe('log', () => { expect(console.log).to.have.been.calledWith('logged', '', 2) expect(console.log).to.have.been.calledWith('logged', '', 3) }) + a.offLog('logged') }) it('should not log if the log has been removed', () => { diff --git a/test/specs/merge.js b/test/specs/merge.js index a6631033..999ea239 100644 --- a/test/specs/merge.js +++ b/test/specs/merge.js @@ -58,17 +58,19 @@ describe('merge', () => { const b = send(prop(), [value(1)]) const c = send(prop(), [value(2)]) - let merge = Kefir.merge([a, b, c]) - expect(merge).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) + const mergeA = Kefir.merge([a, b, c]) + expect(mergeA).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) - merge = Kefir.merge([a, b, c]) - activate(merge) - expect(merge).to.emit([]) + const mergeB = Kefir.merge([a, b, c]) + activate(mergeB) + expect(mergeB).to.emit([]) - merge = Kefir.merge([a, b, c]) - activate(merge) - deactivate(merge) - expect(merge).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) + const mergeC = Kefir.merge([a, b, c]) + activate(mergeC) + deactivate(mergeC) + expect(mergeC).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) + + deactivate(mergeB) }) it('errors should flow', () => { diff --git a/test/specs/pool.js b/test/specs/pool.js index 7ac73417..8661c0b9 100644 --- a/test/specs/pool.js +++ b/test/specs/pool.js @@ -51,26 +51,28 @@ describe('pool', () => { const b = send(prop(), [value(1)]) const c = send(prop(), [value(2)]) - let pool = Kefir.pool() + const poolA = Kefir.pool() .plug(a) .plug(b) .plug(c) - expect(pool).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) + expect(poolA).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) - pool = Kefir.pool() + const poolB = Kefir.pool() .plug(a) .plug(b) .plug(c) - activate(pool) - expect(pool).to.emit([]) + activate(poolB) + expect(poolB).to.emit([]) - pool = Kefir.pool() + const poolC = Kefir.pool() .plug(a) .plug(b) .plug(c) - activate(pool) - deactivate(pool) - expect(pool).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) + activate(poolC) + deactivate(poolC) + expect(poolC).to.emit([value(0, {current: true}), value(1, {current: true}), value(2, {current: true})]) + + deactivate(poolB) }) it('should not deliver events from removed sources', () => { diff --git a/test/specs/property.js b/test/specs/property.js index 30ae294c..56ed2e7d 100644 --- a/test/specs/property.js +++ b/test/specs/property.js @@ -81,28 +81,34 @@ describe('Property', () => { }) describe('active state', () => { + const fn = () => {} + it('should activate when first subscriber added (value)', () => { const s = prop() - s.onValue(() => {}) + s.onValue(fn) expect(s).to.be.active() + s.offValue(fn) }) it('should activate when first subscriber added (error)', () => { const s = prop() - s.onError(() => {}) + s.onError(fn) expect(s).to.be.active() + s.offError(fn) }) it('should activate when first subscriber added (end)', () => { const s = prop() - s.onEnd(() => {}) + s.onEnd(fn) expect(s).to.be.active() + s.offEnd(fn) }) it('should activate when first subscriber added (any)', () => { const s = prop() - s.onAny(() => {}) + s.onAny(fn) expect(s).to.be.active() + s.offAny(fn) }) it('should deactivate when all subscribers removed', () => { @@ -137,50 +143,58 @@ describe('Property', () => { }) it('onValue subscribers should be called with 1 argument', () => { + const fn = function() { + return (count = arguments.length) + } const s = send(prop(), [value(0)]) let count = null - s.onValue(function() { - return (count = arguments.length) - }) + s.onValue(fn) expect(count).to.equal(1) send(s, [value(1)]) expect(count).to.equal(1) + s.offValue(fn) }) it('onError subscribers should be called with 1 argument', () => { + const fn = function() { + return (count = arguments.length) + } const s = send(prop(), [error(0)]) let count = null - s.onError(function() { - return (count = arguments.length) - }) + s.onError(fn) expect(count).to.equal(1) send(s, [error(1)]) expect(count).to.equal(1) + s.offError(fn) }) it('onAny subscribers should be called with 1 arguments', () => { + const fn = function() { + return (count = arguments.length) + } const s = send(prop(), [value(0)]) let count = null - s.onAny(function() { - return (count = arguments.length) - }) + s.onAny(fn) expect(count).to.equal(1) send(s, [value(1)]) expect(count).to.equal(1) + s.offAny(fn) }) it('onEnd subscribers should be called with 0 arguments', () => { + const fn = function() { + return (count = arguments.length) + } const s = send(prop(), [value(0)]) let count = null - s.onEnd(function() { - return (count = arguments.length) - }) + s.onEnd(fn) send(s, [end()]) expect(count).to.equal(0) s.onEnd(function() { return (count = arguments.length) }) expect(count).to.equal(0) + s.offEnd(fn) }) it("can't have current value and error at same time", () => { @@ -193,27 +207,33 @@ describe('Property', () => { }) it('should update catched current value before dispatching it', () => { - const p = send(prop(), [value(0)]) - const spy = sinon.spy() - p.onValue(x => { + const fn = x => { if (x === 1) { return p.onValue(spy) } - }) + } + const p = send(prop(), [value(0)]) + const spy = sinon.spy() + p.onValue(fn) send(p, [value(1)]) expect(spy.args).to.deep.equal([[1]]) + p.offValue(fn) + p.offValue(spy) }) it('should update catched current error before dispatching it', () => { - const p = send(prop(), [error(0)]) - const spy = sinon.spy() - p.onError(x => { + const fn = x => { if (x === 1) { return p.onError(spy) } - }) + } + const p = send(prop(), [error(0)]) + const spy = sinon.spy() + p.onError(fn) send(p, [error(1)]) expect(spy.args).to.deep.equal([[1]]) + p.offError(fn) + p.offError(spy) }) }) }) diff --git a/test/specs/repeat.js b/test/specs/repeat.js index 05124102..5f1ec21b 100644 --- a/test/specs/repeat.js +++ b/test/specs/repeat.js @@ -64,6 +64,7 @@ describe('repeat', () => { expect(callsCount).to.equal(1) send(a, [end()]) expect(callsCount).to.equal(2) + deactivate(b) }) it('should unsubscribe from source', () => { diff --git a/test/specs/sampled-by.js b/test/specs/sampled-by.js index 8d86609b..eca66647 100644 --- a/test/specs/sampled-by.js +++ b/test/specs/sampled-by.js @@ -59,6 +59,7 @@ describe('sampledBy', () => { activate(s2) deactivate(s2) expect(s1).to.emit([value(0)], () => send(b, [value(1)])) + deactivate(s1) }) // https://github.com/kefirjs/kefir/issues/98 diff --git a/test/specs/skip-duplicates.js b/test/specs/skip-duplicates.js index d790a3ec..b52df1fb 100644 --- a/test/specs/skip-duplicates.js +++ b/test/specs/skip-duplicates.js @@ -43,6 +43,7 @@ describe('skipDuplicates', () => { b.plug(a) b.plug(b.map(x => x).skipDuplicates()) expect(b).to.emit([value(1), value(1)], () => send(a, [value(1)])) + b.unplug(a) }) }) diff --git a/test/specs/stream.js b/test/specs/stream.js index f8e927cd..cd2e8a70 100644 --- a/test/specs/stream.js +++ b/test/specs/stream.js @@ -80,28 +80,34 @@ describe('Stream', () => { }) describe('active state', () => { + const fn = () => {} + it('should activate when first subscriber added (value)', () => { const s = stream() - s.onValue(() => {}) + s.onValue(fn) expect(s).to.be.active() + s.offValue(fn) }) it('should activate when first subscriber added (error)', () => { const s = stream() - s.onError(() => {}) + s.onError(fn) expect(s).to.be.active() + s.offError(fn) }) it('should activate when first subscriber added (end)', () => { const s = stream() - s.onEnd(() => {}) + s.onEnd(fn) expect(s).to.be.active() + s.offEnd(fn) }) it('should activate when first subscriber added (any)', () => { const s = stream() - s.onAny(() => {}) + s.onAny(fn) expect(s).to.be.active() + s.offAny(fn) }) it('should deactivate when all subscribers removed', () => { @@ -174,47 +180,53 @@ describe('Stream', () => { }) it('onValue subscribers should be called with 1 argument', () => { + const fn = function() { + return (count = arguments.length) + } const s = stream() let count = null - s.onValue(function() { - return (count = arguments.length) - }) + s.onValue(fn) send(s, [value(1)]) expect(count).to.equal(1) + s.offValue(fn) }) it('onError subscribers should be called with 1 argument', () => { + const fn = function() { + return (count = arguments.length) + } const s = stream() let count = null - s.onError(function() { - return (count = arguments.length) - }) + s.onError(fn) send(s, [error(1)]) expect(count).to.equal(1) + s.offError(fn) }) it('onAny subscribers should be called with 1 arguments', () => { + const fn = function() { + return (count = arguments.length) + } const s = stream() let count = null - s.onAny(function() { - return (count = arguments.length) - }) + s.onAny(fn) send(s, [value(1)]) expect(count).to.equal(1) + s.offAny(fn) }) it('onEnd subscribers should be called with 0 arguments', () => { + const fn = function() { + return (count = arguments.length) + } const s = stream() let count = null - s.onEnd(function() { - return (count = arguments.length) - }) + s.onEnd(fn) send(s, [end()]) expect(count).to.equal(0) - s.onEnd(function() { - return (count = arguments.length) - }) + s.onEnd(fn) expect(count).to.equal(0) + s.offEnd(fn) }) it('should not call subscriber after unsubscribing (from another subscriber)', () => { @@ -229,6 +241,7 @@ describe('Stream', () => { s.onValue(a) send(s, [value(1)]) expect(log).to.deep.equal(['unsub a']) + s.offValue(b) }) it('should not call subscribers after end (fired from another subscriber)', () => { diff --git a/test/specs/to-promise.js b/test/specs/to-promise.js index 84a386b7..e2260b89 100644 --- a/test/specs/to-promise.js +++ b/test/specs/to-promise.js @@ -50,8 +50,12 @@ describe('toPromise', () => { describe('stream', () => { it('should return a promise', () => { - expect(stream().toPromise().type).to.equal(2) - expect(stream().toPromise(Promise1).type).to.equal(1) + const a = stream() + const b = stream() + expect(a.toPromise().type).to.equal(2) + expect(b.toPromise(Promise1).type).to.equal(1) + a._clear() + b._clear() }) it('should not fulfill/reject if obs ends without value', () => { diff --git a/test/specs/to-property.js b/test/specs/to-property.js index 783d35d1..3c79e7ff 100644 --- a/test/specs/to-property.js +++ b/test/specs/to-property.js @@ -37,6 +37,7 @@ describe('toProperty', () => { expect(count).to.equal(1) activate(p) expect(count).to.equal(2) + deactivate(p) }) it('should reset value by getting new from the callback on each activation', () => { diff --git a/test/test-helpers.js b/test/test-helpers.js index d8f4bced..56c57c2b 100644 --- a/test/test-helpers.js +++ b/test/test-helpers.js @@ -100,6 +100,14 @@ use(({Assertion}, utils) => { }) }) +beforeEach(() => { + Kefir.clearActiveObservables() +}) + +afterEach(() => { + expect(Kefir.activeObservables.length).to.equal(0, 'Expected 0 active observables after test execution.') +}) + Kefir.dissableDeprecationWarnings() exports.Kefir = Kefir