UNPKG

kefir

Version:

Reactive Programming library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory usage

2,081 lines (1,621 loc) 114 kB
/*! Kefir.js v2.6.0 * https://github.com/rpominov/kefir */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define(factory); else if(typeof exports === 'object') exports["Kefir"] = factory(); else root["Kefir"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var Kefir = module.exports = {}; Kefir.Kefir = Kefir; var Observable = Kefir.Observable = __webpack_require__(1); Kefir.Stream = __webpack_require__(6); Kefir.Property = __webpack_require__(7); // Create a stream // ----------------------------------------------------------------------------- // () -> Stream Kefir.never = __webpack_require__(8); // (number, any) -> Stream Kefir.later = __webpack_require__(9); // (number, any) -> Stream Kefir.interval = __webpack_require__(11); // (number, Array<any>) -> Stream Kefir.sequentially = __webpack_require__(12); // (number, Function) -> Stream Kefir.fromPoll = __webpack_require__(13); // (number, Function) -> Stream Kefir.withInterval = __webpack_require__(14); // (Function) -> Stream Kefir.fromCallback = __webpack_require__(16); // (Function) -> Stream Kefir.fromNodeCallback = __webpack_require__(18); // Target = {addEventListener, removeEventListener}|{addListener, removeListener}|{on, off} // (Target, string, Function|undefined) -> Stream Kefir.fromEvents = __webpack_require__(19); // (Function) -> Stream Kefir.stream = __webpack_require__(17); // Create a property // ----------------------------------------------------------------------------- // (any) -> Property Kefir.constant = __webpack_require__(22); // (any) -> Property Kefir.constantError = __webpack_require__(23); // (Promise) -> Property Kefir.fromPromise = __webpack_require__(24); // Convert observables // ----------------------------------------------------------------------------- // (Stream|Property, Function|undefined) -> Property var toProperty = __webpack_require__(25); Observable.prototype.toProperty = function (fn) { return toProperty(this, fn); }; // (Stream|Property) -> Stream var changes = __webpack_require__(27); Observable.prototype.changes = function () { return changes(this); }; // Subscribe / add side effects // ----------------------------------------------------------------------------- // (Stream|Property, Function|undefined) -> Promise var toPromise = __webpack_require__(28); Observable.prototype.toPromise = function (Promise) { return toPromise(this, Promise); }; // Modify an observable // ----------------------------------------------------------------------------- // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var map = __webpack_require__(29); Observable.prototype.map = function (fn) { return map(this, fn); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var filter = __webpack_require__(30); Observable.prototype.filter = function (fn) { return filter(this, fn); }; // (Stream, number) -> Stream // (Property, number) -> Property var take = __webpack_require__(31); Observable.prototype.take = function (n) { return take(this, n); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var takeWhile = __webpack_require__(32); Observable.prototype.takeWhile = function (fn) { return takeWhile(this, fn); }; // (Stream) -> Stream // (Property) -> Property var last = __webpack_require__(33); Observable.prototype.last = function () { return last(this); }; // (Stream, number) -> Stream // (Property, number) -> Property var skip = __webpack_require__(34); Observable.prototype.skip = function (n) { return skip(this, n); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var skipWhile = __webpack_require__(35); Observable.prototype.skipWhile = function (fn) { return skipWhile(this, fn); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var skipDuplicates = __webpack_require__(36); Observable.prototype.skipDuplicates = function (fn) { return skipDuplicates(this, fn); }; // (Stream, Function|falsey, any|undefined) -> Stream // (Property, Function|falsey, any|undefined) -> Property var diff = __webpack_require__(37); Observable.prototype.diff = function (fn, seed) { return diff(this, fn, seed); }; // (Stream|Property, Function, any|undefined) -> Property var scan = __webpack_require__(38); Observable.prototype.scan = function (fn, seed) { return scan(this, fn, seed); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var flatten = __webpack_require__(39); Observable.prototype.flatten = function (fn) { return flatten(this, fn); }; // (Stream, number) -> Stream // (Property, number) -> Property var delay = __webpack_require__(40); 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 var throttle = __webpack_require__(41); 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 var debounce = __webpack_require__(43); Observable.prototype.debounce = function (wait, options) { return debounce(this, wait, options); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var valuesToErrors = __webpack_require__(44); Observable.prototype.valuesToErrors = function (fn) { return valuesToErrors(this, fn); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var errorsToValues = __webpack_require__(45); Observable.prototype.errorsToValues = function (fn) { return errorsToValues(this, fn); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var mapErrors = __webpack_require__(46); Observable.prototype.mapErrors = function (fn) { return mapErrors(this, fn); }; // (Stream, Function|undefined) -> Stream // (Property, Function|undefined) -> Property var filterErrors = __webpack_require__(47); Observable.prototype.filterErrors = function (fn) { return filterErrors(this, fn); }; // (Stream) -> Stream // (Property) -> Property var endOnError = __webpack_require__(48); Observable.prototype.endOnError = function () { return endOnError(this); }; // (Stream) -> Stream // (Property) -> Property var skipValues = __webpack_require__(49); Observable.prototype.skipValues = function () { return skipValues(this); }; // (Stream) -> Stream // (Property) -> Property var skipErrors = __webpack_require__(50); Observable.prototype.skipErrors = function () { return skipErrors(this); }; // (Stream) -> Stream // (Property) -> Property var skipEnd = __webpack_require__(51); Observable.prototype.skipEnd = function () { return skipEnd(this); }; // (Stream, Function) -> Stream // (Property, Function) -> Property var beforeEnd = __webpack_require__(52); Observable.prototype.beforeEnd = function (fn) { return beforeEnd(this, fn); }; // (Stream, number, number|undefined) -> Stream // (Property, number, number|undefined) -> Property var slidingWindow = __webpack_require__(53); 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 var bufferWhile = __webpack_require__(54); Observable.prototype.bufferWhile = function (fn, options) { return bufferWhile(this, fn, options); }; // (Stream, Function) -> Stream // (Property, Function) -> Property var transduce = __webpack_require__(55); Observable.prototype.transduce = function (transducer) { return transduce(this, transducer); }; // (Stream, Function) -> Stream // (Property, Function) -> Property var withHandler = __webpack_require__(56); Observable.prototype.withHandler = function (fn) { return withHandler(this, fn); }; // Combine observables // ----------------------------------------------------------------------------- // (Array<Stream|Property>, Function|undefiend) -> Stream // (Array<Stream|Property>, Array<Stream|Property>, Function|undefiend) -> Stream var combine = Kefir.combine = __webpack_require__(57); Observable.prototype.combine = function (other, combinator) { return combine([this, other], combinator); }; // (Array<Stream|Property>, Function|undefiend) -> Stream var zip = Kefir.zip = __webpack_require__(58); Observable.prototype.zip = function (other, combinator) { return zip([this, other], combinator); }; // (Array<Stream|Property>) -> Stream var merge = Kefir.merge = __webpack_require__(59); Observable.prototype.merge = function (other) { return merge([this, other]); }; // (Array<Stream|Property>) -> Stream var concat = Kefir.concat = __webpack_require__(61); Observable.prototype.concat = function (other) { return concat([this, other]); }; // () -> Pool var Pool = Kefir.Pool = __webpack_require__(63); Kefir.pool = function () { return new Pool(); }; // (Function) -> Stream Kefir.repeat = __webpack_require__(62); // Options = {concurLim: number|undefined, queueLim: number|undefined, drop: 'old'|'new'|undefiend} // (Stream|Property, Function|falsey, Options|undefined) -> Stream var FlatMap = __webpack_require__(64); 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 var FlatMapErrors = __webpack_require__(65); Observable.prototype.flatMapErrors = function (fn) { return new FlatMapErrors(this, fn).setName(this, 'flatMapErrors'); }; // Combine two observables // ----------------------------------------------------------------------------- // (Stream, Stream|Property) -> Stream // (Property, Stream|Property) -> Property var filterBy = __webpack_require__(66); Observable.prototype.filterBy = function (other) { return filterBy(this, other); }; // (Stream, Stream|Property, Function|undefiend) -> Stream // (Property, Stream|Property, Function|undefiend) -> Property var sampledBy2items = __webpack_require__(68); Observable.prototype.sampledBy = function (other, combinator) { return sampledBy2items(this, other, combinator); }; // (Stream, Stream|Property) -> Stream // (Property, Stream|Property) -> Property var skipUntilBy = __webpack_require__(69); Observable.prototype.skipUntilBy = function (other) { return skipUntilBy(this, other); }; // (Stream, Stream|Property) -> Stream // (Property, Stream|Property) -> Property var takeUntilBy = __webpack_require__(70); 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 var bufferBy = __webpack_require__(71); 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 var bufferWhileBy = __webpack_require__(72); Observable.prototype.bufferWhileBy = function (other, options) { return bufferWhileBy(this, other, options); }; // (Stream|Property, Stream|Property) -> Property var awaiting = __webpack_require__(73); Observable.prototype.awaiting = function (other) { return awaiting(this, other); }; // Deprecated // ----------------------------------------------------------------------------- Kefir.DEPRECATION_WARNINGS = true; function deprecated(name, alt, fn) { return function () { if (Kefir.DEPRECATION_WARNINGS && typeof console !== 'undefined' && console.log) { var message = 'Method `' + name + '` is deprecated, and to be removed in v3.0.0.\nUse `' + alt + '` instead.\nTo disable all warnings like this set `Kefir.DEPRECATION_WARNINGS = false`.'; console.log(message); } return fn.apply(this, arguments); }; } // () -> Emitter var Emitter = Kefir.Emitter = __webpack_require__(74); Kefir.emitter = deprecated('Kefir.emitter()', 'Kefir.stream()', function () { return new Emitter(); }); // () -> Bus var Bus = Kefir.Bus = __webpack_require__(75); Kefir.bus = deprecated('Kefir.bus()', 'Kefir.pool() or Kefir.stream()', function () { return new Bus(); }); // (Stream, Function, any|undefined) -> Stream // (Property, Function, any|undefined) -> Property var reduce = __webpack_require__(76); Observable.prototype.reduce = deprecated('.reduce(fn, seed)', '.scan(fn, seed).last()', function (fn, seed) { return reduce(this, fn, seed); }); // (Array<Stream|Property>, Array<Stream|Property>, Function|undefined) -> Stream var sampledByManyItems = __webpack_require__(77); Kefir.sampledBy = deprecated('Kefir.sampledBy()', 'Kefir.combine()', sampledByManyItems); // (number, Array<any>) -> Stream var repeatedly = __webpack_require__(78); Kefir.repeatedly = deprecated('Kefir.repeatedly()', 'Kefir.repeat(() => Kefir.sequentially(...)})', repeatedly); // (Stream, any) -> Stream // (Property, any) -> Property var mapTo = __webpack_require__(79); Observable.prototype.mapTo = deprecated('.mapTo()', '.map(() => value)', function (x) { return mapTo(this, x); }); // (Stream, Function) -> Stream // (Property, Function) -> Property var tap = __webpack_require__(80); Observable.prototype.tap = deprecated('.tap()', '.map((v) => {fn(v); return v})', function (fn) { return tap(this, fn); }); // (Stream, string) -> Stream // (Property, string) -> Property var pluck = __webpack_require__(81); Observable.prototype.pluck = deprecated('.pluck()', '.map((x) => x.foo)', function (propName) { return pluck(this, propName); }); // (Stream, string, Array) -> Stream // (Property, string, Array) -> Property var invoke = __webpack_require__(82); Observable.prototype.invoke = deprecated('.invoke()', '.map((x) => x.foo())', function (methodName) { for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } return invoke(this, methodName, args); }); // (Stream) -> Stream // (Property) -> Property var timestamp = __webpack_require__(83); Observable.prototype.timestamp = deprecated('.timestamp()', '.map((x) => {value: x, time: Date.now()})', function () { return timestamp(this); }); // (Array<Stream|Property>) -> Stream var and = __webpack_require__(84); Kefir.and = deprecated('Kefir.and()', 'Kefir.combine([a, b], (a, b) => a && b)', and); Observable.prototype.and = deprecated('.and()', '.combine(other, (a, b) => a && b)', function (other) { return and([this, other]); }); // (Array<Stream|Property>) -> Stream var or = __webpack_require__(85); Kefir.or = deprecated('Kefir.or()', 'Kefir.combine([a, b], (a, b) => a || b)', or); Observable.prototype.or = deprecated('.or()', '.combine(other, (a, b) => a || b)', function (other) { return or([this, other]); }); // (Stream) -> Stream // (Property) -> Property var not = __webpack_require__(86); Observable.prototype.not = deprecated('.not()', '.map((x) => !x)', function () { return not(this); }); // (Function, Function, Function|undefined) -> Stream var fromSubUnsub = __webpack_require__(20); Kefir.fromSubUnsub = deprecated('.fromSubUnsub()', 'Kefir.stream()', fromSubUnsub); // (Stream, Stream|Property) -> Stream // (Property, Stream|Property) -> Property var takeWhileBy = __webpack_require__(87); Observable.prototype.takeWhileBy = deprecated('.takeWhileBy(foo)', '.skipUntilBy(foo.filter((x) => !x))', function (other) { return takeWhileBy(this, other); }); // (Stream, Stream|Property) -> Stream // (Property, Stream|Property) -> Property var skipWhileBy = __webpack_require__(88); Observable.prototype.skipWhileBy = deprecated('.skipWhileBy(foo)', '.takeUntilBy(foo.filter((x) => !x))', function (other) { return skipWhileBy(this, other); }); /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var extend = _require.extend; var _require2 = __webpack_require__(3); var VALUE = _require2.VALUE; var ERROR = _require2.ERROR; var ANY = _require2.ANY; var END = _require2.END; var _require3 = __webpack_require__(4); var Dispatcher = _require3.Dispatcher; var callSubscriber = _require3.callSubscriber; var _require4 = __webpack_require__(5); var findByPred = _require4.findByPred; function Observable() { this._dispatcher = new Dispatcher(); this._active = false; this._alive = true; this._activating = false; this._logHandlers = null; } extend(Observable.prototype, { _name: 'observable', _onActivation: function _onActivation() {}, _onDeactivation: function _onDeactivation() {}, _setActive: function _setActive(active) { if (this._active !== active) { this._active = active; if (active) { this._activating = true; this._onActivation(); this._activating = false; } else { this._onDeactivation(); } } }, _clear: function _clear() { this._setActive(false); this._alive = false; this._dispatcher = null; this._logHandlers = null; }, _emit: function _emit(type, x) { switch (type) { case VALUE: return this._emitValue(x); case ERROR: return this._emitError(x); case END: return this._emitEnd(); } }, _emitValue: function _emitValue(value) { if (this._alive) { this._dispatcher.dispatch({ type: VALUE, value: value, current: this._activating }); } }, _emitError: function _emitError(value) { if (this._alive) { this._dispatcher.dispatch({ type: ERROR, value: value, current: this._activating }); } }, _emitEnd: function _emitEnd() { if (this._alive) { this._dispatcher.dispatch({ type: END, current: this._activating }); this._clear(); } }, _on: function _on(type, fn) { if (this._alive) { this._dispatcher.add(type, fn); this._setActive(true); } else { callSubscriber(type, fn, { type: END, current: true }); } return this; }, _off: function _off(type, fn) { if (this._alive) { var count = this._dispatcher.remove(type, fn); if (count === 0) { this._setActive(false); } } return this; }, onValue: function onValue(fn) { return this._on(VALUE, fn); }, onError: function onError(fn) { return this._on(ERROR, fn); }, onEnd: function onEnd(fn) { return this._on(END, fn); }, onAny: function onAny(fn) { return this._on(ANY, fn); }, offValue: function offValue(fn) { return this._off(VALUE, fn); }, offError: function offError(fn) { return this._off(ERROR, fn); }, offEnd: function offEnd(fn) { return this._off(END, fn); }, offAny: function offAny(fn) { return this._off(ANY, fn); }, // A and B must be subclasses of Stream and Property (order doesn't matter) _ofSameType: function _ofSameType(A, B) { return A.prototype.getType() === this.getType() ? A : B; }, setName: function setName(sourceObs, /* optional */selfName) { this._name = selfName ? '' + sourceObs._name + '.' + selfName : sourceObs; return this; }, log: function log() { var name = arguments[0] === undefined ? this.toString() : arguments[0]; var handler = function handler(event) { var type = '<' + event.type + '' + (event.current ? ':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 }); } this.onAny(handler); return this; }, offLog: function offLog() { var name = arguments[0] === undefined ? this.toString() : arguments[0]; 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; } }); // extend() can't handle `toString` in IE8 Observable.prototype.toString = function () { return '[' + this._name + ']'; }; module.exports = Observable; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { "use strict"; function createObj(proto) { var F = function F() {}; F.prototype = proto; return new F(); } function extend(target /*, mixin1, mixin2...*/) { var length = arguments.length, i = undefined, prop = undefined; 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 = undefined; Child.prototype = createObj(Parent.prototype); Child.prototype.constructor = Child; for (i = 2; i < length; i++) { extend(Child.prototype, arguments[i]); } return Child; } module.exports = { extend: extend, inherit: inherit }; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; exports.NOTHING = ['<nothing>']; exports.END = 'end'; exports.VALUE = 'value'; exports.ERROR = 'error'; exports.ANY = 'any'; /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var extend = _require.extend; var _require2 = __webpack_require__(3); var VALUE = _require2.VALUE; var ERROR = _require2.ERROR; var ANY = _require2.ANY; var _require3 = __webpack_require__(5); var concat = _require3.concat; var removeByPred = _require3.removeByPred; 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 = []; } extend(Dispatcher.prototype, { add: function add(type, fn) { this._items = concat(this._items, [{ type: type, fn: fn }]); return this._items.length; }, remove: function remove(type, fn) { this._items = removeByPred(this._items, function (x) { return x.type === type && x.fn === fn; }); return this._items.length; }, dispatch: function dispatch(event) { for (var i = 0, items = this._items; i < items.length; i++) { callSubscriber(items[i].type, items[i].fn, event); } } }); module.exports = { callSubscriber: callSubscriber, Dispatcher: Dispatcher }; /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { "use strict"; function concat(a, b) { var result = undefined, length = undefined, i = undefined, j = undefined; 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 circleShift(arr, distance) { var length = arr.length, result = new Array(length), i = undefined; for (i = 0; i < length; i++) { result[(i + distance) % length] = arr[i]; } return result; } function find(arr, value) { var length = arr.length, i = undefined; for (i = 0; i < length; i++) { if (arr[i] === value) { return i; } } return -1; } function findByPred(arr, pred) { var length = arr.length, i = undefined; 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 = undefined; for (i = 0; i < length; i++) { result[i] = input[i]; } return result; } function remove(input, index) { var length = input.length, result = undefined, i = undefined, j = undefined; 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 removeByPred(input, pred) { return remove(input, findByPred(input, pred)); } function map(input, fn) { var length = input.length, result = new Array(length), i = undefined; for (i = 0; i < length; i++) { result[i] = fn(input[i]); } return result; } function forEach(arr, fn) { var length = arr.length, i = undefined; for (i = 0; i < length; i++) { fn(arr[i]); } } function fillArray(arr, value) { var length = arr.length, i = undefined; 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 = undefined; for (i = offset; i < length; i++) { result[i - offset] = cur[i]; } result[length - 1] = next; return result; } module.exports = { concat: concat, circleShift: circleShift, find: find, findByPred: findByPred, cloneArray: cloneArray, remove: remove, removeByPred: removeByPred, map: map, forEach: forEach, fillArray: fillArray, contains: contains, slide: slide }; /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var inherit = _require.inherit; var Observable = __webpack_require__(1); function Stream() { Observable.call(this); } inherit(Stream, Observable, { _name: 'stream', getType: function getType() { return 'stream'; } }); module.exports = Stream; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var inherit = _require.inherit; var _require2 = __webpack_require__(3); var VALUE = _require2.VALUE; var ERROR = _require2.ERROR; var END = _require2.END; var _require3 = __webpack_require__(4); var callSubscriber = _require3.callSubscriber; var Observable = __webpack_require__(1); function Property() { Observable.call(this); this._currentEvent = null; } inherit(Property, Observable, { _name: 'property', _emitValue: function _emitValue(value) { if (this._alive) { if (!this._activating) { this._dispatcher.dispatch({ type: VALUE, value: value, current: this._activating }); } this._currentEvent = { type: VALUE, value: value, current: true }; } }, _emitError: function _emitError(value) { if (this._alive) { if (!this._activating) { this._dispatcher.dispatch({ type: ERROR, value: value, current: this._activating }); } this._currentEvent = { type: ERROR, value: value, current: true }; } }, _emitEnd: function _emitEnd() { if (this._alive) { if (!this._activating) { this._dispatcher.dispatch({ type: END, current: this._activating }); } this._clear(); } }, _on: function _on(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, current: true }); } return this; }, getType: function getType() { return 'property'; } }); module.exports = Property; /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var Stream = __webpack_require__(6); var neverS = new Stream(); neverS._emitEnd(); neverS._name = 'never'; module.exports = function never() { return neverS; }; /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var timeBased = __webpack_require__(10); var S = timeBased({ _name: 'later', _init: function _init(_ref) { var x = _ref.x; this._x = x; }, _free: function _free() { this._x = null; }, _onTick: function _onTick() { this._emitValue(this._x); this._emitEnd(); } }); module.exports = function later(wait, x) { return new S(wait, { x: x }); }; /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var inherit = _require.inherit; var Stream = __webpack_require__(6); module.exports = 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 _init(options) {}, _free: function _free() {}, _onTick: function _onTick() {}, _onActivation: function _onActivation() { this._intervalId = setInterval(this._$onTick, this._wait); }, _onDeactivation: function _onDeactivation() { if (this._intervalId !== null) { clearInterval(this._intervalId); this._intervalId = null; } }, _clear: function _clear() { Stream.prototype._clear.call(this); this._$onTick = null; this._free(); } }, mixin); return AnonymousStream; }; /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var timeBased = __webpack_require__(10); var S = timeBased({ _name: 'interval', _init: function _init(_ref) { var x = _ref.x; this._x = x; }, _free: function _free() { this._x = null; }, _onTick: function _onTick() { this._emitValue(this._x); } }); module.exports = function interval(wait, x) { return new S(wait, { x: x }); }; /***/ }, /* 12 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var timeBased = __webpack_require__(10); var _require = __webpack_require__(5); var cloneArray = _require.cloneArray; var never = __webpack_require__(8); var S = timeBased({ _name: 'sequentially', _init: function _init(_ref) { var xs = _ref.xs; this._xs = cloneArray(xs); }, _free: function _free() { this._xs = null; }, _onTick: function _onTick() { if (this._xs.length === 1) { this._emitValue(this._xs[0]); this._emitEnd(); } else { this._emitValue(this._xs.shift()); } } }); module.exports = function sequentially(wait, xs) { return xs.length === 0 ? never() : new S(wait, { xs: xs }); }; /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var timeBased = __webpack_require__(10); var S = timeBased({ _name: 'fromPoll', _init: function _init(_ref) { var fn = _ref.fn; this._fn = fn; }, _free: function _free() { this._fn = null; }, _onTick: function _onTick() { var fn = this._fn; this._emitValue(fn()); } }); module.exports = function fromPoll(wait, fn) { return new S(wait, { fn: fn }); }; /***/ }, /* 14 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var timeBased = __webpack_require__(10); var emitter = __webpack_require__(15); var S = timeBased({ _name: 'withInterval', _init: function _init(_ref) { var fn = _ref.fn; this._fn = fn; this._emitter = emitter(this); }, _free: function _free() { this._fn = null; this._emitter = null; }, _onTick: function _onTick() { var fn = this._fn; fn(this._emitter); } }); module.exports = function withInterval(wait, fn) { return new S(wait, { fn: fn }); }; /***/ }, /* 15 */ /***/ function(module, exports, __webpack_require__) { "use strict"; module.exports = 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, emit: value, emitEvent: event }; }; /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var stream = __webpack_require__(17); module.exports = function fromCallback(callbackConsumer) { var called = false; return stream(function (emitter) { if (!called) { callbackConsumer(function (x) { emitter.emit(x); emitter.end(); }); called = true; } }).setName('fromCallback'); }; /***/ }, /* 17 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var inherit = _require.inherit; var Stream = __webpack_require__(6); var emitter = __webpack_require__(15); function S(fn) { Stream.call(this); this._fn = fn; this._unsubscribe = null; } inherit(S, Stream, { _name: 'stream', _onActivation: function _onActivation() { var fn = this._fn; var unsubscribe = fn(emitter(this)); this._unsubscribe = typeof unsubscribe === 'function' ? unsubscribe : null; // fix https://github.com/rpominov/kefir/issues/35 if (!this._active) { this._callUnsubscribe(); } }, _callUnsubscribe: function _callUnsubscribe() { if (this._unsubscribe !== null) { this._unsubscribe(); this._unsubscribe = null; } }, _onDeactivation: function _onDeactivation() { this._callUnsubscribe(); }, _clear: function _clear() { Stream.prototype._clear.call(this); this._fn = null; } }); module.exports = function stream(fn) { return new S(fn); }; /***/ }, /* 18 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var stream = __webpack_require__(17); module.exports = 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'); }; /***/ }, /* 19 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var fromSubUnsub = __webpack_require__(20); var pairs = [['addEventListener', 'removeEventListener'], ['addListener', 'removeListener'], ['on', 'off']]; module.exports = function fromEvents(target, eventName, transformer) { var sub = undefined, unsub = undefined; 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'); }; /***/ }, /* 20 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var stream = __webpack_require__(17); var _require = __webpack_require__(21); var apply = _require.apply; module.exports = function fromSubUnsub(sub, unsub, transformer /* Function | falsey */) { return stream(function (emitter) { var handler = transformer ? function () { emitter.emit(apply(transformer, this, arguments)); } : emitter.emit; sub(handler); return function () { return unsub(handler); }; }).setName('fromSubUnsub'); }; /***/ }, /* 21 */ /***/ function(module, exports, __webpack_require__) { "use strict"; function spread(fn, length) { switch (length) { case 0: return function (a) { 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); } } } module.exports = { spread: spread, apply: apply }; /***/ }, /* 22 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var inherit = _require.inherit; var Property = __webpack_require__(7); // 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 }); module.exports = function constant(x) { return new P(x); }; /***/ }, /* 23 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(2); var inherit = _require.inherit; var Property = __webpack_require__(7); // 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: 'error', value: value, current: true }; } inherit(P, Property, { _name: 'constantError', _active: false, _activating: false, _alive: false, _dispatcher: null, _logHandlers: null }); module.exports = function constantError(x) { return new P(x); }; /***/ }, /* 24 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var stream = __webpack_require__(17); var toProperty = __webpack_require__(25); module.exports = function fromPromise(promise) { var called = false; var result = stream(function (emitter) { if (!called) { var onValue = function onValue(x) { emitter.emit(x); emitter.end(); }; var onError = function onError(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'); }; /***/ }, /* 25 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(26); var createProperty = _require.createProperty; var P = createProperty('toProperty', { _init: function _init(_ref) { var fn = _ref.fn; this._getInitialCurrent = fn; }, _onActivation: function _onActivation() { if (this._getInitialCurrent !== null) { var getInitial = this._getInitialCurrent; this._emitValue(getInitial()); } this._source.onAny(this._$handleAny); // copied from patterns/one-source } }); module.exports = function toProperty(obs) { var fn = arguments[1] === undefined ? null : arguments[1]; if (fn !== null && typeof fn !== 'function') { throw new Error('You should call toProperty() with a function or no arguments.'); } return new P(obs, { fn: fn }); }; /***/ }, /* 26 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var Stream = __webpack_require__(6); var Property = __webpack_require__(7); var _require = __webpack_require__(2); var inherit = _require.inherit; var _require2 = __webpack_require__(3); var VALUE = _require2.VALUE; var ERROR = _require2.ERROR; var END = _require2.END; 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 _init(options) {}, _free: function _free() {}, _handleValue: function _handleValue(x) { this._emitValue(x); }, _handleError: function _handleError(x) { this._emitError(x); }, _handleEnd: function _handleEnd() { this._emitEnd(); }, _handleAny: function _handleAny(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 _onActivation() { this._source.onAny(this._$handleAny); }, _onDeactivation: function _onDeactivation() { this._source.offAny(this._$handleAny); }, _clear: function _clear() { 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; } module.exports = { createStream: createStream, createProperty: createProperty }; /***/ }, /* 27 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(26); var createStream = _require.createStream; var S = createStream('changes', { _handleValue: function _handleValue(x) { if (!this._activating) { this._emitValue(x); } }, _handleError: function _handleError(x) { if (!this._activating) { this._emitError(x); } } }); module.exports = function changes(obs) { return new S(obs); }; /***/ }, /* 28 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; function getGlodalPromise() { if (typeof Promise === 'function') { return Promise; } else { throw new Error('There isn\'t default Promise, use shim or parameter'); } } module.exports = function (obs) { var Promise = arguments[1] === undefined ? getGlodalPromise() : arguments[1]; 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; } }); }); }; /***/ }, /* 29 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(26); var createStream = _require.createStream; var createProperty = _require.createProperty; var mixin = { _init: function _init(_ref) { var fn = _ref.fn; this._fn = fn; }, _free: function _free() { this._fn = null; }, _handleValue: function _handleValue(x) { var fn = this._fn; this._emitValue(fn(x)); } }; var S = createStream('map', mixin); var P = createProperty('map', mixin); var id = function id(x) { return x; }; module.exports = function map(obs) { var fn = arguments[1] === undefined ? id : arguments[1]; return new (obs._ofSameType(S, P))(obs, { fn: fn }); }; /***/ }, /* 30 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(26); var createStream = _require.createStream; var createProperty = _require.createProperty; var mixin = { _init: function _init(_ref) { var fn = _ref.fn; this._fn = fn; }, _free: function _free() { this._fn = null; }, _handleValue: function _handleValue(x) { var fn = this._fn; if (fn(x)) { this._emitValue(x); } } }; var S = createStream('filter', mixin); var P = createProperty('filter', mixin); var id = function id(x) { return x; }; module.exports = function filter(obs) { var fn = arguments[1] === undefined ? id : arguments[1]; return new (obs._ofSameType(S, P))(obs, { fn: fn }); }; /***/ }, /* 31 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(26); var createStream = _require.createStream; var createProperty = _require.createProperty; var mixin = { _init: function _init(_ref) { var n = _ref.n; this._n = n; if (n <= 0) { this._emitEnd(); } }, _handleValue: function _handleValue(x) { this._n--; this._emitValue(x); if (this._n === 0) { this._emitEnd(); } } }; var S = createStream('take', mixin); var P = createProperty('take', mixin); module.exports = function takeWhile(obs, n) { return new (obs._ofSameType(S, P))(obs, { n: n }); }; /***/ }, /* 32 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _require = __webpack_require__(26); var createStream = _require.createStream; var createProperty = _require.createProperty; var mixi