From 5bf4ae7ea29deedb4e929b6716a245ae4768eef4 Mon Sep 17 00:00:00 2001 From: jackh Date: Thu, 9 Jun 2016 21:57:57 -0400 Subject: [PATCH 1/2] install rxjs and redux-observable --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 401d5df..1597866 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,10 @@ "react-dom": "^0.14.5", "react-redux": "^4.4.5", "redux": "^3.5.2", + "redux-observable": "^0.6.0", "redux-saga": "^0.10.5", - "reselect": "^2.5.1" + "reselect": "^2.5.1", + "rxjs": "^5.0.0-beta.8" }, "devDependencies": { "babel-cli": "^6.3.17", From e0b697701c100f8519d78f746bb8059fbfa64ca8 Mon Sep 17 00:00:00 2001 From: jackh Date: Thu, 9 Jun 2016 22:12:10 -0400 Subject: [PATCH 2/2] uses rx instead of sagas --- bundle.js | 18664 ++++++++++++++++++++++++++++++++++++----- src/index.js | 7 +- src/timer/actions.js | 13 +- src/timer/index.js | 3 - src/timer/saga.js | 31 - 5 files changed, 16415 insertions(+), 2303 deletions(-) delete mode 100644 src/timer/saga.js diff --git a/bundle.js b/bundle.js index bd5714c..0c2cbe6 100644 --- a/bundle.js +++ b/bundle.js @@ -16941,7 +16941,7 @@ function wrapActionCreators(actionCreators) { return (0, _redux.bindActionCreators)(actionCreators, dispatch); }; } -},{"redux":381}],207:[function(require,module,exports){ +},{"redux":372}],207:[function(require,module,exports){ /** * Copyright 2013-2015, Facebook, Inc. * All rights reserved. @@ -35864,2498 +35864,16735 @@ module.exports = warning; module.exports = require('./lib/React'); },{"./lib/React":230}],363:[function(require,module,exports){ -module.exports = require('./lib/effects') -},{"./lib/effects":364}],364:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.ActionsObservable = undefined; -var _io = require('./internal/io'); +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -Object.defineProperty(exports, 'take', { - enumerable: true, - get: function get() { - return _io.take; - } -}); -Object.defineProperty(exports, 'takem', { - enumerable: true, - get: function get() { - return _io.takem; - } -}); -Object.defineProperty(exports, 'put', { - enumerable: true, - get: function get() { - return _io.put; - } -}); -Object.defineProperty(exports, 'race', { - enumerable: true, - get: function get() { - return _io.race; - } -}); -Object.defineProperty(exports, 'call', { - enumerable: true, - get: function get() { - return _io.call; - } -}); -Object.defineProperty(exports, 'apply', { - enumerable: true, - get: function get() { - return _io.apply; - } -}); -Object.defineProperty(exports, 'cps', { - enumerable: true, - get: function get() { - return _io.cps; - } -}); -Object.defineProperty(exports, 'fork', { - enumerable: true, - get: function get() { - return _io.fork; - } -}); -Object.defineProperty(exports, 'spawn', { - enumerable: true, - get: function get() { - return _io.spawn; - } -}); -Object.defineProperty(exports, 'join', { - enumerable: true, - get: function get() { - return _io.join; - } -}); -Object.defineProperty(exports, 'cancel', { - enumerable: true, - get: function get() { - return _io.cancel; - } -}); -Object.defineProperty(exports, 'select', { - enumerable: true, - get: function get() { - return _io.select; - } -}); -Object.defineProperty(exports, 'actionChannel', { - enumerable: true, - get: function get() { - return _io.actionChannel; - } -}); -Object.defineProperty(exports, 'cancelled', { - enumerable: true, - get: function get() { - return _io.cancelled; +var _Observable2 = require('rxjs/Observable'); + +var _filter = require('rxjs/operator/filter'); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var ActionsObservable = exports.ActionsObservable = function (_Observable) { + _inherits(ActionsObservable, _Observable); + + function ActionsObservable(actionsSubject) { + _classCallCheck(this, ActionsObservable); + + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ActionsObservable).call(this)); + + _this.source = actionsSubject; + return _this; } -}); -},{"./internal/io":369}],365:[function(require,module,exports){ + + _createClass(ActionsObservable, [{ + key: 'lift', + value: function lift(operator) { + var observable = new ActionsObservable(this); + observable.operator = operator; + return observable; + } + }, { + key: 'ofType', + value: function ofType() { + for (var _len = arguments.length, keys = Array(_len), _key = 0; _key < _len; _key++) { + keys[_key] = arguments[_key]; + } + + return _filter.filter.call(this, function (_ref) { + var type = _ref.type; + + var len = keys.length; + if (len === 1) { + return type === keys[0]; + } else { + for (var i = 0; i < len; i++) { + if (keys[i] === type) { + return true; + } + } + } + return false; + }); + } + }]); + + return ActionsObservable; +}(_Observable2.Observable); +},{"rxjs/Observable":378,"rxjs/operator/filter":595}],364:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); -exports.utils = exports.effects = exports.CANCEL = exports.delay = exports.takeLatest = exports.takeEvery = exports.buffers = exports.channel = exports.eventChannel = exports.END = exports.runSaga = undefined; +exports.combineDelegators = undefined; -var _runSaga = require('./internal/runSaga'); +var _merge = require('rxjs/observable/merge'); -Object.defineProperty(exports, 'runSaga', { - enumerable: true, - get: function get() { - return _runSaga.runSaga; +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +/** + merges all delegators into a single delegator. + */ +var combineDelegators = exports.combineDelegators = function combineDelegators() { + for (var _len = arguments.length, delegators = Array(_len), _key = 0; _key < _len; _key++) { + delegators[_key] = arguments[_key]; } -}); -var _channel = require('./internal/channel'); + return function (actions, store) { + return _merge.merge.apply(undefined, _toConsumableArray(delegators.map(function (delegator) { + return delegator(actions, store); + }))); + }; +}; +},{"rxjs/observable/merge":555}],365:[function(require,module,exports){ +'use strict'; -Object.defineProperty(exports, 'END', { - enumerable: true, - get: function get() { - return _channel.END; - } -}); -Object.defineProperty(exports, 'eventChannel', { - enumerable: true, - get: function get() { - return _channel.eventChannel; - } -}); -Object.defineProperty(exports, 'channel', { - enumerable: true, - get: function get() { - return _channel.channel; - } +Object.defineProperty(exports, "__esModule", { + value: true }); -var _buffers = require('./internal/buffers'); +var _reduxObservable = require('./reduxObservable'); -Object.defineProperty(exports, 'buffers', { +Object.defineProperty(exports, 'reduxObservable', { enumerable: true, get: function get() { - return _buffers.buffers; + return _reduxObservable.reduxObservable; } }); -var _sagaHelpers = require('./internal/sagaHelpers'); +var _ActionsObservable = require('./ActionsObservable'); -Object.defineProperty(exports, 'takeEvery', { +Object.defineProperty(exports, 'ActionsObservable', { enumerable: true, get: function get() { - return _sagaHelpers.takeEvery; - } -}); -Object.defineProperty(exports, 'takeLatest', { - enumerable: true, - get: function get() { - return _sagaHelpers.takeLatest; + return _ActionsObservable.ActionsObservable; } }); -var _utils = require('./internal/utils'); +var _combineDelegators = require('./combineDelegators'); -Object.defineProperty(exports, 'delay', { - enumerable: true, - get: function get() { - return _utils.delay; - } -}); -Object.defineProperty(exports, 'CANCEL', { +Object.defineProperty(exports, 'combineDelegators', { enumerable: true, get: function get() { - return _utils.CANCEL; + return _combineDelegators.combineDelegators; } }); - -var _middleware = require('./internal/middleware'); - -var _middleware2 = _interopRequireDefault(_middleware); - -var _effects = require('./effects'); - -var effects = _interopRequireWildcard(_effects); - -var _utils2 = require('./utils'); - -var utils = _interopRequireWildcard(_utils2); - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -exports.default = _middleware2.default; -exports.effects = effects; -exports.utils = utils; -},{"./effects":364,"./internal/buffers":367,"./internal/channel":368,"./internal/middleware":370,"./internal/runSaga":372,"./internal/sagaHelpers":373,"./internal/utils":374,"./utils":375}],366:[function(require,module,exports){ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = asap; -var queue = []; -var isSuspended = false; - -function asap(task) { - if (!isSuspended) { - isSuspended = true; - queue.push(task); - asap.flush(); - } else { - queue.push(task); - } -} - -asap.suspend = function () { - return isSuspended = true; -}; -asap.flush = function () { - var nextTask = void 0; - while (nextTask = queue.shift()) { - nextTask(); - } - isSuspended = false; -}; -},{}],367:[function(require,module,exports){ +},{"./ActionsObservable":363,"./combineDelegators":364,"./reduxObservable":366}],366:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); -exports.buffers = exports.BUFFER_OVERFLOW = undefined; - -var _utils = require('./utils'); +exports.reduxObservable = reduxObservable; -var BUFFER_OVERFLOW = exports.BUFFER_OVERFLOW = 'Channel\'s Buffer overflow!'; +var _Subject = require('rxjs/Subject'); -var ON_OVERFLOW_THROW = 1; -var ON_OVERFLOW_DROP = 2; -var ON_OVERFLOW_SLIDE = 3; +var _from = require('rxjs/observable/from'); -var zeroBuffer = { isEmpty: _utils.kTrue, put: _utils.noop, take: _utils.noop }; +var _ActionsObservable = require('./ActionsObservable'); -/** - TODO: Need to make a more optimized implementation: e.g. Ring buffers, linked lists with Node Object pooling... -**/ -function arrBuffer() { - var limit = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0]; - var overflowAction = arguments[1]; +function reduxObservable(processor) { + var actions = new _Subject.Subject(); + var actionsObs = new _ActionsObservable.ActionsObservable(actions); - var arr = []; - return { - isEmpty: function isEmpty() { - return !arr.length; - }, - put: function put(it) { - if (arr.length < limit) { - arr.push(it); - } else { - switch (overflowAction) { - case ON_OVERFLOW_THROW: - throw new Error(BUFFER_OVERFLOW); - case ON_OVERFLOW_SLIDE: - arr.shift(); - arr.push(it); - break; - default: - // DROP - } + var middleware = function middleware(store) { + return function (next) { + if (processor) { + processor(actionsObs, store).subscribe(store.dispatch); } - }, - take: function take() { - return arr.shift(); - } + return function (action) { + if (typeof action === 'function') { + var obs = (0, _from.from)(action(actionsObs, store)); + var sub = obs.subscribe(store.dispatch); + return sub; + } else { + var result = next(action); + actions.next(action); + return result; + } + }; + }; }; -} -var buffers = exports.buffers = { - none: function none() { - return zeroBuffer; - }, - fixed: function fixed(limit) { - return arrBuffer(limit, ON_OVERFLOW_THROW); - }, - dropping: function dropping(limit) { - return arrBuffer(limit, ON_OVERFLOW_DROP); - }, - sliding: function sliding(limit) { - return arrBuffer(limit, ON_OVERFLOW_SLIDE); - } -}; -},{"./utils":374}],368:[function(require,module,exports){ -(function (process){ + return middleware; +} +},{"./ActionsObservable":363,"rxjs/Subject":384,"rxjs/observable/from":549}],367:[function(require,module,exports){ 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.UNDEFINED_INPUT_ERROR = exports.INVALID_BUFFER = exports.isEnd = exports.END = undefined; -exports.emitter = emitter; -exports.channel = channel; -exports.eventChannel = eventChannel; +exports.__esModule = true; -var _utils = require('./utils'); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; -var _buffers = require('./buffers'); +exports["default"] = applyMiddleware; -var CHANNEL_END_TYPE = '@@redux-saga/CHANNEL_END'; -var END = exports.END = { type: CHANNEL_END_TYPE }; -var isEnd = exports.isEnd = function isEnd(a) { - return a && a.type === CHANNEL_END_TYPE; -}; +var _compose = require('./compose'); -function emitter() { - var subscribers = []; +var _compose2 = _interopRequireDefault(_compose); - function subscribe(sub) { - subscribers.push(sub); - return function () { - return (0, _utils.remove)(subscribers, sub); - }; - } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - function emit(item) { - var arr = subscribers.slice(); - for (var i = 0, len = arr.length; i < len; i++) { - arr[i](item); - } +/** + * Creates a store enhancer that applies middleware to the dispatch method + * of the Redux store. This is handy for a variety of tasks, such as expressing + * asynchronous actions in a concise manner, or logging every action payload. + * + * See `redux-thunk` package as an example of the Redux middleware. + * + * Because middleware is potentially asynchronous, this should be the first + * store enhancer in the composition chain. + * + * Note that each middleware will be given the `dispatch` and `getState` functions + * as named arguments. + * + * @param {...Function} middlewares The middleware chain to be applied. + * @returns {Function} A store enhancer applying the middleware. + */ +function applyMiddleware() { + for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) { + middlewares[_key] = arguments[_key]; } - return { - subscribe: subscribe, - emit: emit - }; -} + return function (createStore) { + return function (reducer, initialState, enhancer) { + var store = createStore(reducer, initialState, enhancer); + var _dispatch = store.dispatch; + var chain = []; -var INVALID_BUFFER = exports.INVALID_BUFFER = 'invalid buffer passed to channel factory function'; -var UNDEFINED_INPUT_ERROR = exports.UNDEFINED_INPUT_ERROR = 'Saga was provided with an undefined action'; + var middlewareAPI = { + getState: store.getState, + dispatch: function dispatch(action) { + return _dispatch(action); + } + }; + chain = middlewares.map(function (middleware) { + return middleware(middlewareAPI); + }); + _dispatch = _compose2["default"].apply(undefined, chain)(store.dispatch); -if (process.env.NODE_ENV !== 'production') { - exports.UNDEFINED_INPUT_ERROR = UNDEFINED_INPUT_ERROR += '\nHints:\n - check that your Action Creator returns a non-undefined value\n - if the Saga was started using runSaga, check that your subscribe source provides the action to its listeners\n '; + return _extends({}, store, { + dispatch: _dispatch + }); + }; + }; } +},{"./compose":370}],368:[function(require,module,exports){ +'use strict'; -function channel(buffer) { - var closed = false; - var takers = []; +exports.__esModule = true; +exports["default"] = bindActionCreators; +function bindActionCreator(actionCreator, dispatch) { + return function () { + return dispatch(actionCreator.apply(undefined, arguments)); + }; +} - if (arguments.length > 0) { - (0, _utils.check)(buffer, _utils.is.buffer, INVALID_BUFFER); - } else { - buffer = _buffers.buffers.fixed(); +/** + * Turns an object whose values are action creators, into an object with the + * same keys, but with every function wrapped into a `dispatch` call so they + * may be invoked directly. This is just a convenience method, as you can call + * `store.dispatch(MyActionCreators.doSomething())` yourself just fine. + * + * For convenience, you can also pass a single function as the first argument, + * and get a function in return. + * + * @param {Function|Object} actionCreators An object whose values are action + * creator functions. One handy way to obtain it is to use ES6 `import * as` + * syntax. You may also pass a single function. + * + * @param {Function} dispatch The `dispatch` function available on your Redux + * store. + * + * @returns {Function|Object} The object mimicking the original object, but with + * every action creator wrapped into the `dispatch` call. If you passed a + * function as `actionCreators`, the return value will also be a single + * function. + */ +function bindActionCreators(actionCreators, dispatch) { + if (typeof actionCreators === 'function') { + return bindActionCreator(actionCreators, dispatch); } - function checkForbiddenStates() { - if (closed && takers.length) { - throw (0, _utils.internalErr)('Cannot have a closed channel with pending takers'); - } - if (takers.length && !buffer.isEmpty()) { - throw (0, _utils.internalErr)('Cannot have pending takers with non empty buffer'); - } + if (typeof actionCreators !== 'object' || actionCreators === null) { + throw new Error('bindActionCreators expected an object or a function, instead received ' + (actionCreators === null ? 'null' : typeof actionCreators) + '. ' + 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'); } - function put(input) { - checkForbiddenStates(); - (0, _utils.check)(input, _utils.is.notUndef, UNDEFINED_INPUT_ERROR); - if (!closed) { - if (takers.length) { - for (var i = 0; i < takers.length; i++) { - var cb = takers[i]; - if (!cb[_utils.MATCH] || cb[_utils.MATCH](input)) { - takers.splice(i, 1); - return cb(input); - } - } - } else { - buffer.put(input); - } - } - } - - function take(cb, matcher) { - checkForbiddenStates(); - (0, _utils.check)(cb, _utils.is.func, 'channel.take\'s callback must be a function'); - if (arguments.length > 1) { - (0, _utils.check)(matcher, _utils.is.func, 'channel.take\'s matcher argument must be a function'); - cb[_utils.MATCH] = matcher; - } - if (closed && buffer.isEmpty()) { - cb(END); - } else if (!buffer.isEmpty()) { - cb(buffer.take()); - } else { - takers.push(cb); - cb.cancel = function () { - return (0, _utils.remove)(takers, cb); - }; - } - } - - function close() { - checkForbiddenStates(); - if (!closed) { - closed = true; - if (takers.length) { - var arr = takers; - takers = []; - for (var i = 0, len = arr.length; i < len; i++) { - arr[i](END); - } - takers = []; - } - } - } - - return { take: take, put: put, close: close, - get __takers__() { - return takers; - }, - get __closed__() { - return closed; + var keys = Object.keys(actionCreators); + var boundActionCreators = {}; + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var actionCreator = actionCreators[key]; + if (typeof actionCreator === 'function') { + boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); } - }; -} - -function eventChannel(subscribe) { - var buffer = arguments.length <= 1 || arguments[1] === undefined ? _buffers.buffers.none() : arguments[1]; - var matcher = arguments[2]; - - /** - should be if(typeof matcher !== undefined) instead? - see PR #273 for a background discussion - **/ - if (arguments.length > 2) { - (0, _utils.check)(matcher, _utils.is.func, 'Invalid match function passed to eventChannel'); } - - var chan = channel(buffer); - var unsubscribe = subscribe(function (input) { - if (isEnd(input)) { - chan.close(); - } else if (!matcher || matcher(input)) { - chan.put(input); - } - }); - - return { - take: chan.take, - close: function close() { - if (!chan.__closed__) { - chan.close(); - unsubscribe(); - } - } - }; + return boundActionCreators; } -}).call(this,require('_process')) -},{"./buffers":367,"./utils":374,"_process":190}],369:[function(require,module,exports){ +},{}],369:[function(require,module,exports){ +(function (process){ 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.asEffect = undefined; +exports.__esModule = true; +exports["default"] = combineReducers; -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); +var _createStore = require('./createStore'); -exports.take = take; -exports.takem = takem; -exports.put = put; -exports.race = race; -exports.call = call; -exports.apply = apply; -exports.cps = cps; -exports.fork = fork; -exports.spawn = spawn; -exports.join = join; -exports.cancel = cancel; -exports.select = select; -exports.actionChannel = actionChannel; -exports.cancelled = cancelled; - -var _utils = require('./utils'); - -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -var IO = (0, _utils.sym)('IO'); -var TAKE = 'TAKE'; -var PUT = 'PUT'; -var RACE = 'RACE'; -var CALL = 'CALL'; -var CPS = 'CPS'; -var FORK = 'FORK'; -var JOIN = 'JOIN'; -var CANCEL = 'CANCEL'; -var SELECT = 'SELECT'; -var ACTION_CHANNEL = 'ACTION_CHANNEL'; -var CANCELLED = 'CANCELLED'; - -var effect = function effect(type, payload) { - var _ref; - - return _ref = {}, _defineProperty(_ref, IO, true), _defineProperty(_ref, type, payload), _ref; -}; - -function take(channel, pattern) { - if (arguments.length >= 2) { - (0, _utils.check)(channel, _utils.is.notUndef, 'take(channel, pattern): channel is undefined'); - (0, _utils.check)(channel, _utils.is.take, 'take(channel, pattern): argument ' + String(channel) + ' is not a valid channel (channel argument must have a take method)'); - (0, _utils.check)(pattern, _utils.is.notUndef, 'take(channel, pattern): pattern is undefined'); - (0, _utils.check)(pattern, _utils.is.pattern, 'take(channel, pattern): argument ' + String(pattern) + ' is not a valid pattern (pattern must be String | Function: a => boolean | Array)'); - } else if (arguments.length === 1) { - (0, _utils.check)(channel, _utils.is.notUndef, 'take(patternOrChannel): undefined argument'); - if (!_utils.is.take(channel)) { - if (_utils.is.pattern(channel)) { - pattern = channel; - channel = null; - } else { - throw new Error('take(patternOrChannel): argument ' + String(channel) + ' is not valid channel or a valid pattern'); - } - } else { - pattern = '*'; - } - } else { - pattern = '*'; - } +var _isPlainObject = require('lodash/isPlainObject'); - return effect(TAKE, { channel: channel, pattern: pattern }); -} +var _isPlainObject2 = _interopRequireDefault(_isPlainObject); -function takem() { - var eff = take.apply(undefined, arguments); - eff[TAKE].maybe = true; - return eff; -} +var _warning = require('./utils/warning'); -function put(channel, action) { - if (arguments.length > 1) { - (0, _utils.check)(channel, _utils.is.notUndef, 'put(channel, action): argument channel is undefined'); - (0, _utils.check)(channel, _utils.is.put, 'put(channel, action): argument ' + channel + ' is not a valid channel (channel argument must have a put method)'); - (0, _utils.check)(action, _utils.is.notUndef, 'put(channel, action): argument action is undefined'); - } else { - (0, _utils.check)(channel, _utils.is.notUndef, 'put(action): argument action is undefined'); - action = channel; - channel = null; - } - return effect(PUT, { channel: channel, action: action }); -} +var _warning2 = _interopRequireDefault(_warning); -put.sync = function () { - var eff = put.apply(undefined, arguments); - eff[PUT].sync = true; - return eff; -}; +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -function race(effects) { - return effect(RACE, effects); -} +function getUndefinedStateErrorMessage(key, action) { + var actionType = action && action.type; + var actionName = actionType && '"' + actionType.toString() + '"' || 'an action'; -function getFnCallDesc(meth, fn, args) { - (0, _utils.check)(fn, _utils.is.notUndef, meth + ': argument fn is undefined'); + return 'Given action ' + actionName + ', reducer "' + key + '" returned undefined. ' + 'To ignore an action, you must explicitly return the previous state.'; +} - var context = null; - if (_utils.is.array(fn)) { - var _fn = fn; +function getUnexpectedStateShapeWarningMessage(inputState, reducers, action) { + var reducerKeys = Object.keys(reducers); + var argumentName = action && action.type === _createStore.ActionTypes.INIT ? 'initialState argument passed to createStore' : 'previous state received by the reducer'; - var _fn2 = _slicedToArray(_fn, 2); + if (reducerKeys.length === 0) { + return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.'; + } - context = _fn2[0]; - fn = _fn2[1]; - } else if (fn.fn) { - var _fn3 = fn; - context = _fn3.context; - fn = _fn3.fn; + if (!(0, _isPlainObject2["default"])(inputState)) { + return 'The ' + argumentName + ' has unexpected type of "' + {}.toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] + '". Expected argument to be an object with the following ' + ('keys: "' + reducerKeys.join('", "') + '"'); } - (0, _utils.check)(fn, _utils.is.func, meth + ': argument ' + fn + ' is not a function'); - return { context: context, fn: fn, args: args }; -} + var unexpectedKeys = Object.keys(inputState).filter(function (key) { + return !reducers.hasOwnProperty(key); + }); -function call(fn) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; + if (unexpectedKeys.length > 0) { + return 'Unexpected ' + (unexpectedKeys.length > 1 ? 'keys' : 'key') + ' ' + ('"' + unexpectedKeys.join('", "') + '" found in ' + argumentName + '. ') + 'Expected to find one of the known reducer keys instead: ' + ('"' + reducerKeys.join('", "') + '". Unexpected keys will be ignored.'); } - - return effect(CALL, getFnCallDesc('call', fn, args)); } -function apply(context, fn) { - var args = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; - - return effect(CALL, getFnCallDesc('apply', { context: context, fn: fn }, args)); -} +function assertReducerSanity(reducers) { + Object.keys(reducers).forEach(function (key) { + var reducer = reducers[key]; + var initialState = reducer(undefined, { type: _createStore.ActionTypes.INIT }); -function cps(fn) { - for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; - } + if (typeof initialState === 'undefined') { + throw new Error('Reducer "' + key + '" returned undefined during initialization. ' + 'If the state passed to the reducer is undefined, you must ' + 'explicitly return the initial state. The initial state may ' + 'not be undefined.'); + } - return effect(CPS, getFnCallDesc('cps', fn, args)); + var type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math.random().toString(36).substring(7).split('').join('.'); + if (typeof reducer(undefined, { type: type }) === 'undefined') { + throw new Error('Reducer "' + key + '" returned undefined when probed with a random type. ' + ('Don\'t try to handle ' + _createStore.ActionTypes.INIT + ' or other actions in "redux/*" ') + 'namespace. They are considered private. Instead, you must return the ' + 'current state for any unknown actions, unless it is undefined, ' + 'in which case you must return the initial state, regardless of the ' + 'action type. The initial state may not be undefined.'); + } + }); } -function fork(fn) { - for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { - args[_key3 - 1] = arguments[_key3]; +/** + * Turns an object whose values are different reducer functions, into a single + * reducer function. It will call every child reducer, and gather their results + * into a single state object, whose keys correspond to the keys of the passed + * reducer functions. + * + * @param {Object} reducers An object whose values correspond to different + * reducer functions that need to be combined into one. One handy way to obtain + * it is to use ES6 `import * as reducers` syntax. The reducers may never return + * undefined for any action. Instead, they should return their initial state + * if the state passed to them was undefined, and the current state for any + * unrecognized action. + * + * @returns {Function} A reducer function that invokes every reducer inside the + * passed object, and builds a state object with the same shape. + */ +function combineReducers(reducers) { + var reducerKeys = Object.keys(reducers); + var finalReducers = {}; + for (var i = 0; i < reducerKeys.length; i++) { + var key = reducerKeys[i]; + if (typeof reducers[key] === 'function') { + finalReducers[key] = reducers[key]; + } } + var finalReducerKeys = Object.keys(finalReducers); - return effect(FORK, getFnCallDesc('fork', fn, args)); -} - -function spawn(fn) { - for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { - args[_key4 - 1] = arguments[_key4]; + var sanityError; + try { + assertReducerSanity(finalReducers); + } catch (e) { + sanityError = e; } - var eff = fork.apply(undefined, [fn].concat(args)); - eff[FORK].detached = true; - return eff; -} + return function combination() { + var state = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + var action = arguments[1]; -var isForkedTask = function isForkedTask(task) { - return task[_utils.TASK]; -}; + if (sanityError) { + throw sanityError; + } -function join(task) { - (0, _utils.check)(task, _utils.is.notUndef, 'join(task): argument task is undefined'); - if (!isForkedTask(task)) { - throw new Error('join(task): argument ' + task + ' is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)'); - } + if (process.env.NODE_ENV !== 'production') { + var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action); + if (warningMessage) { + (0, _warning2["default"])(warningMessage); + } + } - return effect(JOIN, task); + var hasChanged = false; + var nextState = {}; + for (var i = 0; i < finalReducerKeys.length; i++) { + var key = finalReducerKeys[i]; + var reducer = finalReducers[key]; + var previousStateForKey = state[key]; + var nextStateForKey = reducer(previousStateForKey, action); + if (typeof nextStateForKey === 'undefined') { + var errorMessage = getUndefinedStateErrorMessage(key, action); + throw new Error(errorMessage); + } + nextState[key] = nextStateForKey; + hasChanged = hasChanged || nextStateForKey !== previousStateForKey; + } + return hasChanged ? nextState : state; + }; } +}).call(this,require('_process')) +},{"./createStore":371,"./utils/warning":373,"_process":190,"lodash/isPlainObject":196}],370:[function(require,module,exports){ +"use strict"; -function cancel(task) { - (0, _utils.check)(task, _utils.is.notUndef, 'cancel(task): argument task is undefined'); - if (!isForkedTask(task)) { - throw new Error('cancel(task): argument ' + task + ' is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)'); - } - - return effect(CANCEL, task); -} +exports.__esModule = true; +exports["default"] = compose; +/** + * Composes single-argument functions from right to left. The rightmost + * function can take multiple arguments as it provides the signature for + * the resulting composite function. + * + * @param {...Function} funcs The functions to compose. + * @returns {Function} A function obtained by composing the argument functions + * from right to left. For example, compose(f, g, h) is identical to doing + * (...args) => f(g(h(...args))). + */ -function select(selector) { - for (var _len5 = arguments.length, args = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { - args[_key5 - 1] = arguments[_key5]; +function compose() { + for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) { + funcs[_key] = arguments[_key]; } - if (arguments.length === 0) { - selector = _utils.ident; + if (funcs.length === 0) { + return function (arg) { + return arg; + }; } else { - (0, _utils.check)(select, _utils.is.notUndef, 'select(selector,[...]): argument selector is undefined'); - (0, _utils.check)(selector, _utils.is.func, 'select(selector,[...]): argument ' + selector + ' is not a function'); - } - return effect(SELECT, { selector: selector, args: args }); -} + var _ret = function () { + var last = funcs[funcs.length - 1]; + var rest = funcs.slice(0, -1); + return { + v: function v() { + return rest.reduceRight(function (composed, f) { + return f(composed); + }, last.apply(undefined, arguments)); + } + }; + }(); -/** - channel(pattern, [buffer]) => creates an event channel for store actions -**/ -function actionChannel(pattern, buffer) { - (0, _utils.check)(pattern, _utils.is.notUndef, 'actionChannel(pattern,...): argument pattern is undefined'); - if (arguments.length > 1) { - (0, _utils.check)(buffer, _utils.is.notUndef, 'actionChannel(pattern, buffer): argument buffer is undefined'); - (0, _utils.check)(buffer, _utils.is.notUndef, 'actionChannel(pattern, buffer): argument ' + buffer + ' is not a valid buffer'); + if (typeof _ret === "object") return _ret.v; } - return effect(ACTION_CHANNEL, { pattern: pattern, buffer: buffer }); -} - -function cancelled() { - return effect(CANCELLED, {}); } - -var asEffect = exports.asEffect = { - take: function take(effect) { - return effect && effect[IO] && effect[TAKE]; - }, - put: function put(effect) { - return effect && effect[IO] && effect[PUT]; - }, - race: function race(effect) { - return effect && effect[IO] && effect[RACE]; - }, - call: function call(effect) { - return effect && effect[IO] && effect[CALL]; - }, - cps: function cps(effect) { - return effect && effect[IO] && effect[CPS]; - }, - fork: function fork(effect) { - return effect && effect[IO] && effect[FORK]; - }, - join: function join(effect) { - return effect && effect[IO] && effect[JOIN]; - }, - cancel: function cancel(effect) { - return effect && effect[IO] && effect[CANCEL]; - }, - select: function select(effect) { - return effect && effect[IO] && effect[SELECT]; - }, - actionChannel: function actionChannel(effect) { - return effect && effect[IO] && effect[ACTION_CHANNEL]; - }, - cancelled: function cancelled(effect) { - return effect && effect[IO] && effect[CANCELLED]; - } -}; -},{"./utils":374}],370:[function(require,module,exports){ -(function (process){ +},{}],371:[function(require,module,exports){ 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = sagaMiddlewareFactory; - -var _utils = require('./utils'); - -var _proc = require('./proc'); - -var _proc2 = _interopRequireDefault(_proc); - -var _channel = require('./channel'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function sagaMiddlewareFactory() { - var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; +exports.__esModule = true; +exports.ActionTypes = undefined; +exports["default"] = createStore; - var runSagaDynamically = void 0; +var _isPlainObject = require('lodash/isPlainObject'); - if (_utils.is.func(options)) { - if (process.env.NODE_ENV === 'production') { - throw new Error('Saga middleware no longer accept Generator functions. Use sagaMiddleware.run instead'); - } else { - throw new Error('You passed a function to the Saga middleware. You are likely trying to start a Saga by directly passing it to the middleware. This is no longer possible starting from 0.10.0. To run a Saga, you must do it dynamically AFTER mounting the middleware into the store.\n Example:\n import createSagaMiddleware from \'redux-saga\'\n ... other imports\n\n const sagaMiddleware = createSagaMiddleware()\n const store = createStore(reducer, applyMiddleware(sagaMiddleware))\n sagaMiddleware.run(saga, ...args)\n '); - } - } +var _isPlainObject2 = _interopRequireDefault(_isPlainObject); - function sagaMiddleware(_ref) { - var getState = _ref.getState; - var dispatch = _ref.dispatch; +var _symbolObservable = require('symbol-observable'); - runSagaDynamically = runSaga; - var sagaEmitter = (0, _channel.emitter)(); +var _symbolObservable2 = _interopRequireDefault(_symbolObservable); - function runSaga(saga) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - return (0, _proc2.default)(saga.apply(undefined, args), sagaEmitter.subscribe, dispatch, getState, options.sagaMonitor, 0, saga.name); - } +/** + * These are private action types reserved by Redux. + * For any unknown actions, you must return the current state. + * If the current state is undefined, you must return the initial state. + * Do not reference these action types directly in your code. + */ +var ActionTypes = exports.ActionTypes = { + INIT: '@@redux/INIT' +}; - return function (next) { - return function (action) { - var result = next(action); // hit reducers - sagaEmitter.emit(action); - return result; - }; - }; +/** + * Creates a Redux store that holds the state tree. + * The only way to change the data in the store is to call `dispatch()` on it. + * + * There should only be a single store in your app. To specify how different + * parts of the state tree respond to actions, you may combine several reducers + * into a single reducer function by using `combineReducers`. + * + * @param {Function} reducer A function that returns the next state tree, given + * the current state tree and the action to handle. + * + * @param {any} [initialState] The initial state. You may optionally specify it + * to hydrate the state from the server in universal apps, or to restore a + * previously serialized user session. + * If you use `combineReducers` to produce the root reducer function, this must be + * an object with the same shape as `combineReducers` keys. + * + * @param {Function} enhancer The store enhancer. You may optionally specify it + * to enhance the store with third-party capabilities such as middleware, + * time travel, persistence, etc. The only store enhancer that ships with Redux + * is `applyMiddleware()`. + * + * @returns {Store} A Redux store that lets you read the state, dispatch actions + * and subscribe to changes. + */ +function createStore(reducer, initialState, enhancer) { + var _ref2; + + if (typeof initialState === 'function' && typeof enhancer === 'undefined') { + enhancer = initialState; + initialState = undefined; } - sagaMiddleware.run = function (saga) { - for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; + if (typeof enhancer !== 'undefined') { + if (typeof enhancer !== 'function') { + throw new Error('Expected the enhancer to be a function.'); } - (0, _utils.check)(runSagaDynamically, _utils.is.notUndef, 'Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware'); - (0, _utils.check)(saga, _utils.is.func, 'sagaMiddleware.run(saga, ...args): saga argument must be a Generator function!'); - return runSagaDynamically.apply(undefined, [saga].concat(args)); - }; - - return sagaMiddleware; -} -}).call(this,require('_process')) -},{"./channel":368,"./proc":371,"./utils":374,"_process":190}],371:[function(require,module,exports){ -(function (process){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.TASK_CANCEL = exports.CHANNEL_END = exports.NOT_ITERATOR_ERROR = undefined; -exports.default = proc; - -var _utils = require('./utils'); - -var _asap = require('./asap'); - -var _asap2 = _interopRequireDefault(_asap); - -var _io = require('./io'); - -var _channel = require('./channel'); - -var _buffers = require('./buffers'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _defineEnumerableProperties(obj, descs) { for (var key in descs) { var desc = descs[key]; desc.configurable = desc.enumerable = true; if ("value" in desc) desc.writable = true; Object.defineProperty(obj, key, desc); } return obj; } - -function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } - -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + return enhancer(createStore)(reducer, initialState); + } -var isDev = process.env.NODE_ENV === 'development'; + if (typeof reducer !== 'function') { + throw new Error('Expected the reducer to be a function.'); + } -var NOT_ITERATOR_ERROR = exports.NOT_ITERATOR_ERROR = 'proc first argument (Saga function result) must be an iterator'; + var currentReducer = reducer; + var currentState = initialState; + var currentListeners = []; + var nextListeners = currentListeners; + var isDispatching = false; -var nextEffectId = (0, _utils.autoInc)(); -var CHANNEL_END = exports.CHANNEL_END = { - toString: function toString() { - return '@@redux-saga/CHANNEL_END'; - } -}; -var TASK_CANCEL = exports.TASK_CANCEL = { - toString: function toString() { - return '@@redux-saga/TASK_CANCEL'; + function ensureCanMutateNextListeners() { + if (nextListeners === currentListeners) { + nextListeners = currentListeners.slice(); + } } -}; -var matchers = { - wildcard: function wildcard() { - return _utils.kTrue; - }, - default: function _default(pattern) { - return function (input) { - return input.type === pattern; - }; - }, - array: function array(patterns) { - return function (input) { - return patterns.some(function (p) { - return p === input.type; - }); - }; - }, - predicate: function predicate(_predicate) { - return function (input) { - return _predicate(input); - }; + /** + * Reads the state tree managed by the store. + * + * @returns {any} The current state tree of your application. + */ + function getState() { + return currentState; } -}; -function matcher(pattern) { - return (pattern === '*' ? matchers.wildcard : _utils.is.array(pattern) ? matchers.array : _utils.is.func(pattern) ? matchers.predicate : matchers.default)(pattern); -} + /** + * Adds a change listener. It will be called any time an action is dispatched, + * and some part of the state tree may potentially have changed. You may then + * call `getState()` to read the current state tree inside the callback. + * + * You may call `dispatch()` from a change listener, with the following + * caveats: + * + * 1. The subscriptions are snapshotted just before every `dispatch()` call. + * If you subscribe or unsubscribe while the listeners are being invoked, this + * will not have any effect on the `dispatch()` that is currently in progress. + * However, the next `dispatch()` call, whether nested or not, will use a more + * recent snapshot of the subscription list. + * + * 2. The listener should not expect to see all state changes, as the state + * might have been updated multiple times during a nested `dispatch()` before + * the listener is called. It is, however, guaranteed that all subscribers + * registered before the `dispatch()` started will be called with the latest + * state by the time it exits. + * + * @param {Function} listener A callback to be invoked on every dispatch. + * @returns {Function} A function to remove this change listener. + */ + function subscribe(listener) { + if (typeof listener !== 'function') { + throw new Error('Expected listener to be a function.'); + } + + var isSubscribed = true; -/** - Used to track a parent task and its forks - In the new fork model, forked tasks are attached by default to their parent - We model this using the concept of Parent task && main Task - main task is the main flow of the current Generator, the parent tasks is the - aggregation of the main tasks + all its forked tasks. - Thus the whole model represents an execution tree with multiple branches (vs the - linear execution tree in sequential (non parallel) programming) - - A parent tasks has the following semantics - - It completes iff all its forks either complete or all cancelled - - If it's cancelled, all forks are cancelled as well - - It aborts if any uncaught error bubbles up from forks - - If it completes, the return value is the one returned by the main task -**/ -function forkQueue(name, mainTask, cb) { - var tasks = [], - result = void 0, - completed = false; - addTask(mainTask); + ensureCanMutateNextListeners(); + nextListeners.push(listener); - function addTask(task) { - tasks.push(task); - task.cont = function (res, isErr) { - if (completed) { + return function unsubscribe() { + if (!isSubscribed) { return; } - (0, _utils.remove)(tasks, task); - task.cont = _utils.noop; - if (isErr) { - cancelAll(); - cb(res, true); - } else { - if (task === mainTask) { - result = res; - } - if (!tasks.length) { - completed = true; - cb(result); - } - } + isSubscribed = false; + + ensureCanMutateNextListeners(); + var index = nextListeners.indexOf(listener); + nextListeners.splice(index, 1); }; - // task.cont.cancel = task.cancel } - function cancelAll() { - if (completed) { - return; + /** + * Dispatches an action. It is the only way to trigger a state change. + * + * The `reducer` function, used to create the store, will be called with the + * current state tree and the given `action`. Its return value will + * be considered the **next** state of the tree, and the change listeners + * will be notified. + * + * The base implementation only supports plain object actions. If you want to + * dispatch a Promise, an Observable, a thunk, or something else, you need to + * wrap your store creating function into the corresponding middleware. For + * example, see the documentation for the `redux-thunk` package. Even the + * middleware will eventually dispatch plain object actions using this method. + * + * @param {Object} action A plain object representing “what changed”. It is + * a good idea to keep actions serializable so you can record and replay user + * sessions, or use the time travelling `redux-devtools`. An action must have + * a `type` property which may not be `undefined`. It is a good idea to use + * string constants for action types. + * + * @returns {Object} For convenience, the same action object you dispatched. + * + * Note that, if you use a custom middleware, it may wrap `dispatch()` to + * return something else (for example, a Promise you can await). + */ + function dispatch(action) { + if (!(0, _isPlainObject2["default"])(action)) { + throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); } - completed = true; - tasks.forEach(function (t) { - t.cont = _utils.noop; - t.cancel(); - }); - tasks = []; - } - return { - addTask: addTask, - cancelAll: cancelAll, - getTasks: function getTasks() { - return tasks; - }, - taskNames: function taskNames() { - return tasks.map(function (t) { - return t.name; - }); + if (typeof action.type === 'undefined') { + throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?'); } - }; -} -function proc(iterator) { - var subscribe = arguments.length <= 1 || arguments[1] === undefined ? function () { - return _utils.noop; - } : arguments[1]; - var dispatch = arguments.length <= 2 || arguments[2] === undefined ? _utils.noop : arguments[2]; - var getState = arguments.length <= 3 || arguments[3] === undefined ? _utils.noop : arguments[3]; - var monitor = arguments[4]; - var parentEffectId = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5]; - var name = arguments.length <= 6 || arguments[6] === undefined ? 'anonymous' : arguments[6]; - var cont = arguments[7]; - - (0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR); - - var stdChannel = (0, _channel.eventChannel)(subscribe); - /** - Tracks the current effect cancellation - Each time the generator progresses. calling runEffect will set a new value - on it. It allows propagating cancellation to child effects - **/ - next.cancel = _utils.noop; - - /** - Creates a new task descriptor for this generator, We'll also create a main task - to track the main flow (besides other forked tasks) - **/ - var task = newTask(parentEffectId, name, iterator, cont); - var mainTask = { name: name, cancel: cancelMain, isRunning: true }; - var taskQueue = forkQueue(name, mainTask, end); - - /** - cancellation of the main task. We'll simply resume the Generator with a Cancel - **/ - function cancelMain() { - if (mainTask.isRunning && !mainTask.isCancelled) { - mainTask.isCancelled = true; - next(TASK_CANCEL); - } - } - - /** - This may be called by a parent generator to trigger/propagate cancellation - cancel all pending tasks (including the main task), then end the current task. - Cancellation propagates down to the whole execution tree holded by this Parent task - It's also propagated to all joiners of this task and their execution tree/joiners - Cancellation is noop for terminated/Cancelled tasks tasks - **/ - function cancel() { - /** - We need to check both Running and Cancelled status - Tasks can be Cancelled but still Running - **/ - if (iterator._isRunning && !iterator._isCancelled) { - iterator._isCancelled = true; - taskQueue.cancelAll(); - /** - Ending with a Never result will propagate the Cancellation to all joiners - **/ - end(TASK_CANCEL); - } - } - /** - attaches cancellation logic to this task's continuation - this will permit cancellation to propagate down the call chain - **/ - cont && (cont.cancel = cancel); - - // tracks the running status - iterator._isRunning = true; - - // kicks up the generator - next(); - - // then return the task descriptor to the caller - return task; - - /** - This is the generator driver - It's a recursive async/continuation function which calls itself - until the generator terminates or throws - **/ - function next(arg, isErr) { - // Preventive measure. If we end up here, then there is really something wrong - if (!mainTask.isRunning) { - throw new Error('Trying to resume an already finished generator'); + if (isDispatching) { + throw new Error('Reducers may not dispatch actions.'); } try { - var result = void 0; - if (isErr) { - result = iterator.throw(arg); - } else if (arg === TASK_CANCEL) { - /** - getting TASK_CANCEL autoamtically cancels the main task - We can get this value here - - By cancelling the parent task manually - - By joining a Cancelled task - **/ - mainTask.isCancelled = true; - /** - Cancels the current effect; this will propagate the cancellation down to any called tasks - **/ - next.cancel(); - /** - If this Generator has a `return` method then invokes it - Thill will jump to the finally block - **/ - result = _utils.is.func(iterator.return) ? iterator.return(TASK_CANCEL) : { done: true, value: TASK_CANCEL }; - } else if (arg === CHANNEL_END) { - // We get CHANNEL_END by taking from a channel that ended using `take` (and not `takem` used to trap End of channels) - result = _utils.is.func(iterator.return) ? iterator.return() : { done: true }; - } else { - result = iterator.next(arg); - } - - if (!result.done) { - runEffect(result.value, parentEffectId, '', next); - } else { - /** - This Generator has ended, terminate the main task and notify the fork queue - **/ - mainTask.isMainRunning = false; - mainTask.cont && mainTask.cont(result.value); - } - } catch (error) { - if (mainTask.isCancelled) { - (0, _utils.log)('error', 'uncaught at ' + name, error.message); - } - mainTask.isMainRunning = false; - mainTask.cont(error, true); + isDispatching = true; + currentState = currentReducer(currentState, action); + } finally { + isDispatching = false; } - } - function end(result, isErr) { - iterator._isRunning = false; - stdChannel.close(); - if (!isErr) { - if (result === TASK_CANCEL && isDev) { - (0, _utils.log)('info', name + ' has been cancelled', ''); - } - iterator._result = result; - iterator._deferredEnd && iterator._deferredEnd.resolve(result); - } else { - if (result instanceof Error) { - result.sagaStack = 'at ' + name + ' \n ' + (result.sagaStack || result.stack); - } - if (!task.cont) { - (0, _utils.log)('error', 'uncaught', result.sagaStack || result.stack); - } - iterator._error = result; - iterator._isAborted = true; - iterator._deferredEnd && iterator._deferredEnd.reject(result); + var listeners = currentListeners = nextListeners; + for (var i = 0; i < listeners.length; i++) { + listeners[i](); } - task.cont && task.cont(result, isErr); - task.joiners.forEach(function (j) { - return j.cb(result, isErr); - }); - task.joiners = null; - } - function runEffect(effect, parentEffectId) { - var label = arguments.length <= 2 || arguments[2] === undefined ? '' : arguments[2]; - var cb = arguments[3]; + return action; + } - var effectId = nextEffectId(); - monitor && monitor.effectTriggered({ effectId: effectId, parentEffectId: parentEffectId, label: label, effect: effect }); + /** + * Replaces the reducer currently used by the store to calculate the state. + * + * You might need this if your app implements code splitting and you want to + * load some of the reducers dynamically. You might also need this if you + * implement a hot reloading mechanism for Redux. + * + * @param {Function} nextReducer The reducer for the store to use instead. + * @returns {void} + */ + function replaceReducer(nextReducer) { + if (typeof nextReducer !== 'function') { + throw new Error('Expected the nextReducer to be a function.'); + } - /** - completion callback and cancel callback are mutually exclusive - We can't cancel an already completed effect - And We can't complete an already cancelled effectId - **/ - var effectSettled = void 0; + currentReducer = nextReducer; + dispatch({ type: ActionTypes.INIT }); + } - // Completion callback passed to the appropriate effect runner - function currCb(res, isErr) { - if (effectSettled) { - return; - } + /** + * Interoperability point for observable/reactive libraries. + * @returns {observable} A minimal observable of state changes. + * For more information, see the observable proposal: + * https://github.com/zenparsing/es-observable + */ + function observable() { + var _ref; - effectSettled = true; - cb.cancel = _utils.noop; // defensive measure - if (monitor) { - isErr ? monitor.effectRejected(effectId, res) : monitor.effectResolved(effectId, res); - } + var outerSubscribe = subscribe; + return _ref = { + /** + * The minimal observable subscription method. + * @param {Object} observer Any object that can be used as an observer. + * The observer object should have a `next` method. + * @returns {subscription} An object with an `unsubscribe` method that can + * be used to unsubscribe the observable from the store, and prevent further + * emission of values from the observable. + */ - cb(res, isErr); - } - // tracks down the current cancel - currCb.cancel = _utils.noop; + subscribe: function subscribe(observer) { + if (typeof observer !== 'object') { + throw new TypeError('Expected the observer to be an object.'); + } - // setup cancellation logic on the parent cb - cb.cancel = function () { - // prevents cancelling an already completed effect - if (effectSettled) { - return; - } + function observeState() { + if (observer.next) { + observer.next(getState()); + } + } - effectSettled = true; - /** - propagates cancel downward - catch uncaught cancellations errors; since we can no longer call the completion - callback, log errors raised during cancellations into the console - **/ - try { - currCb.cancel(); - } catch (err) { - (0, _utils.log)('error', 'uncaught at ' + name, err.message); + observeState(); + var unsubscribe = outerSubscribe(observeState); + return { unsubscribe: unsubscribe }; } - currCb.cancel = _utils.noop; // defensive measure - - monitor && monitor.effectCancelled(effectId); - }; - - /** - each effect runner must attach its own logic of cancellation to the provided callback - it allows this generator to propagate cancellation downward. - ATTENTION! effect runners must setup the cancel logic by setting cb.cancel = [cancelMethod] - And the setup must occur before calling the callback - This is a sort of inversion of control: called async functions are responsible - of completing the flow by calling the provided continuation; while caller functions - are responsible for aborting the current flow by calling the attached cancel function - Library users can attach their own cancellation logic to promises by defining a - promise[CANCEL] method in their returned promises - ATTENTION! calling cancel must have no effect on an already completed or cancelled effect - **/ - var data = void 0; - return( - // Non declarative effect - _utils.is.promise(effect) ? resolvePromise(effect, currCb) : _utils.is.iterator(effect) ? resolveIterator(effect, effectId, name, currCb) - - // declarative effects - : _utils.is.array(effect) ? runParallelEffect(effect, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.take(effect)) ? runTakeEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.put(effect)) ? runPutEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.race(effect)) ? runRaceEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.call(effect)) ? runCallEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.cps(effect)) ? runCPSEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.fork(effect)) ? runForkEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.join(effect)) ? runJoinEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.cancel(effect)) ? runCancelEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.select(effect)) ? runSelectEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.actionChannel(effect)) ? runChannelEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.cancelled(effect)) ? runCancelledEffect(data, currCb) : /* anything else returned as is */currCb(effect) - ); + }, _ref[_symbolObservable2["default"]] = function () { + return this; + }, _ref; } - function resolvePromise(promise, cb) { - var cancelPromise = promise[_utils.CANCEL]; - if (typeof cancelPromise === 'function') { - cb.cancel = cancelPromise; - } - promise.then(cb, function (error) { - return cb(error, true); - }); - } - - function resolveIterator(iterator, effectId, name, cb) { - proc(iterator, subscribe, dispatch, getState, monitor, effectId, name, cb); - } + // When a store is created, an "INIT" action is dispatched so that every + // reducer returns their initial state. This effectively populates + // the initial state tree. + dispatch({ type: ActionTypes.INIT }); - function runTakeEffect(_ref, cb) { - var channel = _ref.channel; - var pattern = _ref.pattern; - var maybe = _ref.maybe; + return _ref2 = { + dispatch: dispatch, + subscribe: subscribe, + getState: getState, + replaceReducer: replaceReducer + }, _ref2[_symbolObservable2["default"]] = observable, _ref2; +} +},{"lodash/isPlainObject":196,"symbol-observable":709}],372:[function(require,module,exports){ +(function (process){ +'use strict'; - channel = channel || stdChannel; - var takeCb = function takeCb(inp) { - return inp instanceof Error ? cb(inp, true) : (0, _channel.isEnd)(inp) && !maybe ? cb(CHANNEL_END) : cb(inp); - }; - try { - channel.take(takeCb, matcher(pattern)); - } catch (err) { - return cb(err, true); - } - cb.cancel = takeCb.cancel; - } +exports.__esModule = true; +exports.compose = exports.applyMiddleware = exports.bindActionCreators = exports.combineReducers = exports.createStore = undefined; - function runPutEffect(_ref2, cb) { - var channel = _ref2.channel; - var action = _ref2.action; - var sync = _ref2.sync; +var _createStore = require('./createStore'); - /* - Use a reentrant lock `asap` to flatten all nested dispatches - If this put cause another Saga to take this action an then immediately - put an action that will be taken by this Saga. Then the outer Saga will miss - the action from the inner Saga b/c this put has not yet returned. - */ - (0, _asap2.default)(function () { - var result = void 0; - try { - result = (channel ? channel.put : dispatch)(action); - } catch (error) { - return cb(error, true); - } +var _createStore2 = _interopRequireDefault(_createStore); - if (sync && _utils.is.promise(result)) { - resolvePromise(result, cb); - } else { - return cb(result); - } - }); - // Put effects are non cancellables - } +var _combineReducers = require('./combineReducers'); - function runCallEffect(_ref3, effectId, cb) { - var context = _ref3.context; - var fn = _ref3.fn; - var args = _ref3.args; +var _combineReducers2 = _interopRequireDefault(_combineReducers); - var result = void 0; - // catch synchronous failures; see #152 - try { - result = fn.apply(context, args); - } catch (error) { - return cb(error, true); - } - return _utils.is.promise(result) ? resolvePromise(result, cb) : _utils.is.iterator(result) ? resolveIterator(result, effectId, fn.name, cb) : cb(result); - } +var _bindActionCreators = require('./bindActionCreators'); - function runCPSEffect(_ref4, cb) { - var context = _ref4.context; - var fn = _ref4.fn; - var args = _ref4.args; +var _bindActionCreators2 = _interopRequireDefault(_bindActionCreators); - // CPS (ie node style functions) can define their own cancellation logic - // by setting cancel field on the cb +var _applyMiddleware = require('./applyMiddleware'); - // catch synchronous failures; see #152 - try { - fn.apply(context, args.concat(function (err, res) { - return _utils.is.undef(err) ? cb(res) : cb(err, true); - })); - } catch (error) { - return cb(error, true); - } - } +var _applyMiddleware2 = _interopRequireDefault(_applyMiddleware); - function runForkEffect(_ref5, effectId, cb) { - var context = _ref5.context; - var fn = _ref5.fn; - var args = _ref5.args; - var detached = _ref5.detached; +var _compose = require('./compose'); - var result = void 0, - error = void 0, - _iterator = void 0; +var _compose2 = _interopRequireDefault(_compose); - // we run the function, next we'll check if this is a generator function - // (generator is a function that returns an iterator) +var _warning = require('./utils/warning'); - // catch synchronous failures; see #152 - try { - result = fn.apply(context, args); - } catch (err) { - if (!detached) { - return cb(err); - } else { - error = err; - } - } +var _warning2 = _interopRequireDefault(_warning); - // A generator function: i.e. returns an iterator - if (_utils.is.iterator(result)) { - _iterator = result; - } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - // simple effect: wrap in a generator - // do not bubble up synchronous failures for detached forks, instead create a failed task. See #152 - else { - _iterator = error ? (0, _utils.makeIterator)(function () { - throw error; - }) : (0, _utils.makeIterator)(function () { - var pc = void 0; - var eff = { done: false, value: result }; - var ret = function ret(value) { - return { done: true, value: value }; - }; - return function (arg) { - if (!pc) { - pc = true; - return eff; - } else { - return ret(arg); - } - }; - }()); - } +/* +* This is a dummy function to check if the function name has been altered by minification. +* If the function has been minified and NODE_ENV !== 'production', warn the user. +*/ +function isCrushed() {} - _asap2.default.suspend(); - var task = proc(_iterator, subscribe, dispatch, getState, monitor, effectId, fn.name, detached ? null : _utils.noop); - if (!detached) { - if (_iterator._isRunning) { - taskQueue.addTask(task); - } else if (_iterator._error) { - return cb(_iterator._error, true); - } - } - cb(task); - _asap2.default.flush(); - // Fork effects are non cancellables - } +if (process.env.NODE_ENV !== 'production' && typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') { + (0, _warning2["default"])('You are currently using minified code outside of NODE_ENV === \'production\'. ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' + 'to ensure you have the correct code for your production build.'); +} - function runJoinEffect(t, cb) { - if (t.isRunning()) { - (function () { - var joiner = { task: task, cb: cb }; - cb.cancel = function () { - return (0, _utils.remove)(t.joiners, joiner); - }; - t.joiners.push(joiner); - })(); - } else { - t.isAborted() ? cb(t.error(), true) : cb(t.result()); - } - } +exports.createStore = _createStore2["default"]; +exports.combineReducers = _combineReducers2["default"]; +exports.bindActionCreators = _bindActionCreators2["default"]; +exports.applyMiddleware = _applyMiddleware2["default"]; +exports.compose = _compose2["default"]; +}).call(this,require('_process')) +},{"./applyMiddleware":367,"./bindActionCreators":368,"./combineReducers":369,"./compose":370,"./createStore":371,"./utils/warning":373,"_process":190}],373:[function(require,module,exports){ +'use strict'; - function runCancelEffect(task, cb) { - if (task.isRunning()) { - task.cancel(); - } - cb(); - // cancel effects are non cancellables +exports.__esModule = true; +exports["default"] = warning; +/** + * Prints a warning in the console if it exists. + * + * @param {String} message The warning message. + * @returns {void} + */ +function warning(message) { + /* eslint-disable no-console */ + if (typeof console !== 'undefined' && typeof console.error === 'function') { + console.error(message); } + /* eslint-enable no-console */ + try { + // This error was thrown as a convenience so that if you enable + // "break on all exceptions" in your console, + // it would pause the execution at this line. + throw new Error(message); + /* eslint-disable no-empty */ + } catch (e) {} + /* eslint-enable no-empty */ +} +},{}],374:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('./Subject'); +var Subscription_1 = require('./Subscription'); +/** + * @class AsyncSubject + */ +var AsyncSubject = (function (_super) { + __extends(AsyncSubject, _super); + function AsyncSubject() { + _super.apply(this, arguments); + this.value = null; + this.hasNext = false; + this.hasCompleted = false; + } + AsyncSubject.prototype._subscribe = function (subscriber) { + if (this.hasCompleted && this.hasNext) { + subscriber.next(this.value); + subscriber.complete(); + return Subscription_1.Subscription.EMPTY; + } + else if (this.hasError) { + subscriber.error(this.thrownError); + return Subscription_1.Subscription.EMPTY; + } + return _super.prototype._subscribe.call(this, subscriber); + }; + AsyncSubject.prototype.next = function (value) { + this.value = value; + this.hasNext = true; + }; + AsyncSubject.prototype.complete = function () { + this.hasCompleted = true; + if (this.hasNext) { + _super.prototype.next.call(this, this.value); + } + _super.prototype.complete.call(this); + }; + return AsyncSubject; +}(Subject_1.Subject)); +exports.AsyncSubject = AsyncSubject; - function runParallelEffect(effects, effectId, cb) { - if (!effects.length) { - return cb([]); - } - - var completedCount = 0; - var completed = void 0; - var results = Array(effects.length); - - function checkEffectEnd() { - if (completedCount === results.length) { - completed = true; - cb(results); - } +},{"./Subject":384,"./Subscription":387}],375:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('./Subject'); +var throwError_1 = require('./util/throwError'); +var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError'); +/** + * @class BehaviorSubject + */ +var BehaviorSubject = (function (_super) { + __extends(BehaviorSubject, _super); + function BehaviorSubject(_value) { + _super.call(this); + this._value = _value; } - - var childCbs = effects.map(function (eff, idx) { - var chCbAtIdx = function chCbAtIdx(res, isErr) { - if (completed) { - return; + BehaviorSubject.prototype.getValue = function () { + if (this.hasError) { + throwError_1.throwError(this.thrownError); } - if (isErr || (0, _channel.isEnd)(res) || res === CHANNEL_END || res === TASK_CANCEL) { - cb.cancel(); - cb(res, isErr); - } else { - results[idx] = res; - completedCount++; - checkEffectEnd(); + else if (this.isUnsubscribed) { + throwError_1.throwError(new ObjectUnsubscribedError_1.ObjectUnsubscribedError()); + } + else { + return this._value; } - }; - chCbAtIdx.cancel = _utils.noop; - return chCbAtIdx; - }); - - cb.cancel = function () { - if (!completed) { - completed = true; - childCbs.forEach(function (chCb) { - return chCb.cancel(); - }); - } }; - - effects.forEach(function (eff, idx) { - return runEffect(eff, effectId, idx, childCbs[idx]); + Object.defineProperty(BehaviorSubject.prototype, "value", { + get: function () { + return this.getValue(); + }, + enumerable: true, + configurable: true }); - } + BehaviorSubject.prototype._subscribe = function (subscriber) { + var subscription = _super.prototype._subscribe.call(this, subscriber); + if (subscription && !subscription.isUnsubscribed) { + subscriber.next(this._value); + } + return subscription; + }; + BehaviorSubject.prototype.next = function (value) { + _super.prototype.next.call(this, this._value = value); + }; + return BehaviorSubject; +}(Subject_1.Subject)); +exports.BehaviorSubject = BehaviorSubject; - function runRaceEffect(effects, effectId, cb) { - var completed = void 0; - var keys = Object.keys(effects); - var childCbs = {}; +},{"./Subject":384,"./util/ObjectUnsubscribedError":690,"./util/throwError":706}],376:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('./Subscriber'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var InnerSubscriber = (function (_super) { + __extends(InnerSubscriber, _super); + function InnerSubscriber(parent, outerValue, outerIndex) { + _super.call(this); + this.parent = parent; + this.outerValue = outerValue; + this.outerIndex = outerIndex; + this.index = 0; + } + InnerSubscriber.prototype._next = function (value) { + this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this); + }; + InnerSubscriber.prototype._error = function (error) { + this.parent.notifyError(error, this); + this.unsubscribe(); + }; + InnerSubscriber.prototype._complete = function () { + this.parent.notifyComplete(this); + this.unsubscribe(); + }; + return InnerSubscriber; +}(Subscriber_1.Subscriber)); +exports.InnerSubscriber = InnerSubscriber; - keys.forEach(function (key) { - var chCbAtKey = function chCbAtKey(res, isErr) { - if (completed) { - return; +},{"./Subscriber":386}],377:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('./Observable'); +/** + * Represents a push-based event or value that an {@link Observable} can emit. + * This class is particularly useful for operators that manage notifications, + * like {@link materialize}, {@link dematerialize}, {@link observeOn}, and + * others. Besides wrapping the actual delivered value, it also annotates it + * with metadata of, for instance, what type of push message it is (`next`, + * `error`, or `complete`). + * + * @see {@link materialize} + * @see {@link dematerialize} + * @see {@link observeOn} + * + * @class Notification + */ +var Notification = (function () { + function Notification(kind, value, exception) { + this.kind = kind; + this.value = value; + this.exception = exception; + this.hasValue = kind === 'N'; + } + /** + * Delivers to the given `observer` the value wrapped by this Notification. + * @param {Observer} observer + * @return + */ + Notification.prototype.observe = function (observer) { + switch (this.kind) { + case 'N': + return observer.next && observer.next(this.value); + case 'E': + return observer.error && observer.error(this.exception); + case 'C': + return observer.complete && observer.complete(); } - - if (isErr) { - // Race Auto cancellation - cb.cancel(); - cb(res, true); - } else if (!(0, _channel.isEnd)(res) && res !== CHANNEL_END && res !== TASK_CANCEL) { - cb.cancel(); - completed = true; - cb(_defineProperty({}, key, res)); + }; + /** + * Given some {@link Observer} callbacks, deliver the value represented by the + * current Notification to the correctly corresponding callback. + * @param {function(value: T): void} next An Observer `next` callback. + * @param {function(err: any): void} [error] An Observer `error` callback. + * @param {function(): void} [complete] An Observer `complete` callback. + * @return {any} + */ + Notification.prototype.do = function (next, error, complete) { + var kind = this.kind; + switch (kind) { + case 'N': + return next && next(this.value); + case 'E': + return error && error(this.exception); + case 'C': + return complete && complete(); } - }; - chCbAtKey.cancel = _utils.noop; - childCbs[key] = chCbAtKey; - }); + }; + /** + * Takes an Observer or its individual callback functions, and calls `observe` + * or `do` methods accordingly. + * @param {Observer|function(value: T): void} nextOrObserver An Observer or + * the `next` callback. + * @param {function(err: any): void} [error] An Observer `error` callback. + * @param {function(): void} [complete] An Observer `complete` callback. + * @return {any} + */ + Notification.prototype.accept = function (nextOrObserver, error, complete) { + if (nextOrObserver && typeof nextOrObserver.next === 'function') { + return this.observe(nextOrObserver); + } + else { + return this.do(nextOrObserver, error, complete); + } + }; + /** + * Returns a simple Observable that just delivers the notification represented + * by this Notification instance. + * @return {any} + */ + Notification.prototype.toObservable = function () { + var kind = this.kind; + switch (kind) { + case 'N': + return Observable_1.Observable.of(this.value); + case 'E': + return Observable_1.Observable.throw(this.exception); + case 'C': + return Observable_1.Observable.empty(); + } + }; + /** + * A shortcut to create a Notification instance of the type `next` from a + * given value. + * @param {T} value The `next` value. + * @return {Notification} The "next" Notification representing the + * argument. + */ + Notification.createNext = function (value) { + if (typeof value !== 'undefined') { + return new Notification('N', value); + } + return this.undefinedValueNotification; + }; + /** + * A shortcut to create a Notification instance of the type `error` from a + * given error. + * @param {any} [err] The `error` exception. + * @return {Notification} The "error" Notification representing the + * argument. + */ + Notification.createError = function (err) { + return new Notification('E', undefined, err); + }; + /** + * A shortcut to create a Notification instance of the type `complete`. + * @return {Notification} The valueless "complete" Notification. + */ + Notification.createComplete = function () { + return this.completeNotification; + }; + Notification.completeNotification = new Notification('C'); + Notification.undefinedValueNotification = new Notification('N', undefined); + return Notification; +}()); +exports.Notification = Notification; - cb.cancel = function () { - // prevents unnecessary cancellation - if (!completed) { - completed = true; - keys.forEach(function (key) { - return childCbs[key].cancel(); +},{"./Observable":378}],378:[function(require,module,exports){ +"use strict"; +var root_1 = require('./util/root'); +var toSubscriber_1 = require('./util/toSubscriber'); +var $$observable = require('symbol-observable'); +/** + * A representation of any set of values over any amount of time. This the most basic building block + * of RxJS. + * + * @class Observable + */ +var Observable = (function () { + /** + * @constructor + * @param {Function} subscribe the function that is called when the Observable is + * initially subscribed to. This function is given a Subscriber, to which new values + * can be `next`ed, or an `error` method can be called to raise an error, or + * `complete` can be called to notify of a successful completion. + */ + function Observable(subscribe) { + this._isScalar = false; + if (subscribe) { + this._subscribe = subscribe; + } + } + /** + * Creates a new Observable, with this Observable as the source, and the passed + * operator defined as the new observable's operator. + * @method lift + * @param {Operator} operator the operator defining the operation to take on the observable + * @return {Observable} a new observable with the Operator applied + */ + Observable.prototype.lift = function (operator) { + var observable = new Observable(); + observable.source = this; + observable.operator = operator; + return observable; + }; + /** + * Registers handlers for handling emitted values, error and completions from the observable, and + * executes the observable's subscriber function, which will take action to set up the underlying data stream + * @method subscribe + * @param {PartialObserver|Function} observerOrNext (optional) either an observer defining all functions to be called, + * or the first of three possible handlers, which is the handler for each value emitted from the observable. + * @param {Function} error (optional) a handler for a terminal event resulting from an error. If no error handler is provided, + * the error will be thrown as unhandled + * @param {Function} complete (optional) a handler for a terminal event resulting from successful completion. + * @return {ISubscription} a subscription reference to the registered handlers + */ + Observable.prototype.subscribe = function (observerOrNext, error, complete) { + var operator = this.operator; + var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete); + if (operator) { + operator.call(sink, this); + } + else { + sink.add(this._subscribe(sink)); + } + if (sink.syncErrorThrowable) { + sink.syncErrorThrowable = false; + if (sink.syncErrorThrown) { + throw sink.syncErrorValue; + } + } + return sink; + }; + /** + * @method forEach + * @param {Function} next a handler for each value emitted by the observable + * @param {PromiseConstructor} [PromiseCtor] a constructor function used to instantiate the Promise + * @return {Promise} a promise that either resolves on observable completion or + * rejects with the handled error + */ + Observable.prototype.forEach = function (next, PromiseCtor) { + var _this = this; + if (!PromiseCtor) { + if (root_1.root.Rx && root_1.root.Rx.config && root_1.root.Rx.config.Promise) { + PromiseCtor = root_1.root.Rx.config.Promise; + } + else if (root_1.root.Promise) { + PromiseCtor = root_1.root.Promise; + } + } + if (!PromiseCtor) { + throw new Error('no Promise impl found'); + } + return new PromiseCtor(function (resolve, reject) { + var subscription = _this.subscribe(function (value) { + if (subscription) { + // if there is a subscription, then we can surmise + // the next handling is asynchronous. Any errors thrown + // need to be rejected explicitly and unsubscribe must be + // called manually + try { + next(value); + } + catch (err) { + reject(err); + subscription.unsubscribe(); + } + } + else { + // if there is NO subscription, then we're getting a nexted + // value synchronously during subscription. We can just call it. + // If it errors, Observable's `subscribe` imple will ensure the + // unsubscription logic is called, then synchronously rethrow the error. + // After that, Promise will trap the error and send it + // down the rejection path. + next(value); + } + }, reject, resolve); }); - } }; - keys.forEach(function (key) { - return runEffect(effects[key], effectId, key, childCbs[key]); - }); - } + Observable.prototype._subscribe = function (subscriber) { + return this.source.subscribe(subscriber); + }; + /** + * An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable + * @method Symbol.observable + * @return {Observable} this instance of the observable + */ + Observable.prototype[$$observable] = function () { + return this; + }; + // HACK: Since TypeScript inherits static properties too, we have to + // fight against TypeScript here so Subject can have a different static create signature + /** + * Creates a new cold Observable by calling the Observable constructor + * @static true + * @owner Observable + * @method create + * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor + * @return {Observable} a new cold observable + */ + Observable.create = function (subscribe) { + return new Observable(subscribe); + }; + return Observable; +}()); +exports.Observable = Observable; - function runSelectEffect(_ref6, cb) { - var selector = _ref6.selector; - var args = _ref6.args; +},{"./util/root":704,"./util/toSubscriber":707,"symbol-observable":709}],379:[function(require,module,exports){ +"use strict"; +exports.empty = { + isUnsubscribed: true, + next: function (value) { }, + error: function (err) { throw err; }, + complete: function () { } +}; - try { - var state = selector.apply(undefined, [getState()].concat(_toConsumableArray(args))); - cb(state); - } catch (error) { - cb(error, true); +},{}],380:[function(require,module,exports){ +"use strict"; +var Subscriber_1 = require('./Subscriber'); +var Operator = (function () { + function Operator() { } - } - - function runChannelEffect(_ref7, cb) { - var pattern = _ref7.pattern; - var buffer = _ref7.buffer; - - var match = matcher(pattern); - match.pattern = pattern; - cb((0, _channel.eventChannel)(subscribe, buffer || _buffers.buffers.fixed(), match)); - } - - function runCancelledEffect(data, cb) { - cb(!!mainTask.isCancelled); - } + Operator.prototype.call = function (subscriber, source) { + return source._subscribe(new Subscriber_1.Subscriber(subscriber)); + }; + return Operator; +}()); +exports.Operator = Operator; - function newTask(id, name, iterator, cont) { - var _done, _ref8, _mutatorMap; +},{"./Subscriber":386}],381:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('./Subscriber'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var OuterSubscriber = (function (_super) { + __extends(OuterSubscriber, _super); + function OuterSubscriber() { + _super.apply(this, arguments); + } + OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.destination.next(innerValue); + }; + OuterSubscriber.prototype.notifyError = function (error, innerSub) { + this.destination.error(error); + }; + OuterSubscriber.prototype.notifyComplete = function (innerSub) { + this.destination.complete(); + }; + return OuterSubscriber; +}(Subscriber_1.Subscriber)); +exports.OuterSubscriber = OuterSubscriber; - iterator._deferredEnd = null; - return _ref8 = {}, _defineProperty(_ref8, _utils.TASK, true), _defineProperty(_ref8, 'id', id), _defineProperty(_ref8, 'name', name), _done = 'done', _mutatorMap = {}, _mutatorMap[_done] = _mutatorMap[_done] || {}, _mutatorMap[_done].get = function () { - if (iterator._deferredEnd) { - return iterator._deferredEnd.promise; - } else { - var def = (0, _utils.deferred)(); - iterator._deferredEnd = def; - if (!iterator._isRunning) { - iterator._error ? def.reject(iterator._error) : def.resolve(iterator._result); +},{"./Subscriber":386}],382:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('./Subject'); +var queue_1 = require('./scheduler/queue'); +var observeOn_1 = require('./operator/observeOn'); +/** + * @class ReplaySubject + */ +var ReplaySubject = (function (_super) { + __extends(ReplaySubject, _super); + function ReplaySubject(bufferSize, windowTime, scheduler) { + if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; } + if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; } + _super.call(this); + this.scheduler = scheduler; + this._events = []; + this._bufferSize = bufferSize < 1 ? 1 : bufferSize; + this._windowTime = windowTime < 1 ? 1 : windowTime; + } + ReplaySubject.prototype.next = function (value) { + var now = this._getNow(); + this._events.push(new ReplayEvent(now, value)); + this._trimBufferThenGetEvents(); + _super.prototype.next.call(this, value); + }; + ReplaySubject.prototype._subscribe = function (subscriber) { + var _events = this._trimBufferThenGetEvents(); + var scheduler = this.scheduler; + if (scheduler) { + subscriber.add(subscriber = new observeOn_1.ObserveOnSubscriber(subscriber, scheduler)); } - return def.promise; - } - }, _defineProperty(_ref8, 'cont', cont), _defineProperty(_ref8, 'joiners', []), _defineProperty(_ref8, 'cancel', cancel), _defineProperty(_ref8, 'isRunning', function isRunning() { - return iterator._isRunning; - }), _defineProperty(_ref8, 'isCancelled', function isCancelled() { - return iterator._isCancelled; - }), _defineProperty(_ref8, 'isAborted', function isAborted() { - return iterator._isAborted; - }), _defineProperty(_ref8, 'result', function result() { - return iterator._result; - }), _defineProperty(_ref8, 'error', function error() { - return iterator._error; - }), _defineEnumerableProperties(_ref8, _mutatorMap), _ref8; - } -} -}).call(this,require('_process')) -},{"./asap":366,"./buffers":367,"./channel":368,"./io":369,"./utils":374,"_process":190}],372:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.runSaga = runSaga; - -var _utils = require('./utils'); - -var _proc = require('./proc'); - -var _proc2 = _interopRequireDefault(_proc); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function runSaga(iterator, _ref, monitor) { - var subscribe = _ref.subscribe; - var dispatch = _ref.dispatch; - var getState = _ref.getState; - - - (0, _utils.check)(iterator, _utils.is.iterator, "runSaga must be called on an iterator"); - - return (0, _proc2.default)(iterator, subscribe, dispatch, getState, monitor); -} -},{"./proc":371,"./utils":374}],373:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - -exports.takeEvery = takeEvery; -exports.takeLatest = takeLatest; - -var _channel = require('./channel'); - -var _utils = require('./utils'); - -var _io = require('./io'); - -var done = { done: true, value: undefined }; -var qEnd = {}; + var len = _events.length; + for (var i = 0; i < len && !subscriber.isUnsubscribed; i++) { + subscriber.next(_events[i].value); + } + return _super.prototype._subscribe.call(this, subscriber); + }; + ReplaySubject.prototype._getNow = function () { + return (this.scheduler || queue_1.queue).now(); + }; + ReplaySubject.prototype._trimBufferThenGetEvents = function () { + var now = this._getNow(); + var _bufferSize = this._bufferSize; + var _windowTime = this._windowTime; + var _events = this._events; + var eventsCount = _events.length; + var spliceCount = 0; + // Trim events that fall out of the time window. + // Start at the front of the list. Break early once + // we encounter an event that falls within the window. + while (spliceCount < eventsCount) { + if ((now - _events[spliceCount].time) < _windowTime) { + break; + } + spliceCount++; + } + if (eventsCount > _bufferSize) { + spliceCount = Math.max(spliceCount, eventsCount - _bufferSize); + } + if (spliceCount > 0) { + _events.splice(0, spliceCount); + } + return _events; + }; + return ReplaySubject; +}(Subject_1.Subject)); +exports.ReplaySubject = ReplaySubject; +var ReplayEvent = (function () { + function ReplayEvent(time, value) { + this.time = time; + this.value = value; + } + return ReplayEvent; +}()); + +},{"./Subject":384,"./operator/observeOn":616,"./scheduler/queue":675}],383:[function(require,module,exports){ +"use strict"; +/* tslint:disable:no-unused-variable */ +// Subject imported before Observable to bypass circular dependency issue since +// Subject extends Observable and Observable references Subject in it's +// definition +var Subject_1 = require('./Subject'); +exports.Subject = Subject_1.Subject; +/* tslint:enable:no-unused-variable */ +var Observable_1 = require('./Observable'); +exports.Observable = Observable_1.Observable; +// statics +/* tslint:disable:no-use-before-declare */ +require('./add/observable/bindCallback'); +require('./add/observable/bindNodeCallback'); +require('./add/observable/combineLatest'); +require('./add/observable/concat'); +require('./add/observable/defer'); +require('./add/observable/empty'); +require('./add/observable/forkJoin'); +require('./add/observable/from'); +require('./add/observable/fromEvent'); +require('./add/observable/fromEventPattern'); +require('./add/observable/fromPromise'); +require('./add/observable/generate'); +require('./add/observable/if'); +require('./add/observable/interval'); +require('./add/observable/merge'); +require('./add/observable/race'); +require('./add/observable/never'); +require('./add/observable/of'); +require('./add/observable/onErrorResumeNext'); +require('./add/observable/range'); +require('./add/observable/using'); +require('./add/observable/throw'); +require('./add/observable/timer'); +require('./add/observable/zip'); +//dom +require('./add/observable/dom/ajax'); +require('./add/observable/dom/webSocket'); +//operators +require('./add/operator/buffer'); +require('./add/operator/bufferCount'); +require('./add/operator/bufferTime'); +require('./add/operator/bufferToggle'); +require('./add/operator/bufferWhen'); +require('./add/operator/cache'); +require('./add/operator/catch'); +require('./add/operator/combineAll'); +require('./add/operator/combineLatest'); +require('./add/operator/concat'); +require('./add/operator/concatAll'); +require('./add/operator/concatMap'); +require('./add/operator/concatMapTo'); +require('./add/operator/count'); +require('./add/operator/dematerialize'); +require('./add/operator/debounce'); +require('./add/operator/debounceTime'); +require('./add/operator/defaultIfEmpty'); +require('./add/operator/delay'); +require('./add/operator/delayWhen'); +require('./add/operator/distinct'); +require('./add/operator/distinctKey'); +require('./add/operator/distinctUntilChanged'); +require('./add/operator/distinctUntilKeyChanged'); +require('./add/operator/do'); +require('./add/operator/exhaust'); +require('./add/operator/exhaustMap'); +require('./add/operator/expand'); +require('./add/operator/elementAt'); +require('./add/operator/filter'); +require('./add/operator/finally'); +require('./add/operator/find'); +require('./add/operator/findIndex'); +require('./add/operator/first'); +require('./add/operator/groupBy'); +require('./add/operator/ignoreElements'); +require('./add/operator/isEmpty'); +require('./add/operator/audit'); +require('./add/operator/auditTime'); +require('./add/operator/last'); +require('./add/operator/let'); +require('./add/operator/every'); +require('./add/operator/map'); +require('./add/operator/mapTo'); +require('./add/operator/materialize'); +require('./add/operator/max'); +require('./add/operator/merge'); +require('./add/operator/mergeAll'); +require('./add/operator/mergeMap'); +require('./add/operator/mergeMapTo'); +require('./add/operator/mergeScan'); +require('./add/operator/min'); +require('./add/operator/multicast'); +require('./add/operator/observeOn'); +require('./add/operator/onErrorResumeNext'); +require('./add/operator/pairwise'); +require('./add/operator/partition'); +require('./add/operator/pluck'); +require('./add/operator/publish'); +require('./add/operator/publishBehavior'); +require('./add/operator/publishReplay'); +require('./add/operator/publishLast'); +require('./add/operator/race'); +require('./add/operator/reduce'); +require('./add/operator/repeat'); +require('./add/operator/retry'); +require('./add/operator/retryWhen'); +require('./add/operator/sample'); +require('./add/operator/sampleTime'); +require('./add/operator/scan'); +require('./add/operator/share'); +require('./add/operator/single'); +require('./add/operator/skip'); +require('./add/operator/skipUntil'); +require('./add/operator/skipWhile'); +require('./add/operator/startWith'); +require('./add/operator/subscribeOn'); +require('./add/operator/switch'); +require('./add/operator/switchMap'); +require('./add/operator/switchMapTo'); +require('./add/operator/take'); +require('./add/operator/takeLast'); +require('./add/operator/takeUntil'); +require('./add/operator/takeWhile'); +require('./add/operator/throttle'); +require('./add/operator/throttleTime'); +require('./add/operator/timeInterval'); +require('./add/operator/timeout'); +require('./add/operator/timeoutWith'); +require('./add/operator/timestamp'); +require('./add/operator/toArray'); +require('./add/operator/toPromise'); +require('./add/operator/window'); +require('./add/operator/windowCount'); +require('./add/operator/windowTime'); +require('./add/operator/windowToggle'); +require('./add/operator/windowWhen'); +require('./add/operator/withLatestFrom'); +require('./add/operator/zip'); +require('./add/operator/zipAll'); +/* tslint:disable:no-unused-variable */ +var Operator_1 = require('./Operator'); +exports.Operator = Operator_1.Operator; +var Subscription_1 = require('./Subscription'); +exports.Subscription = Subscription_1.Subscription; +var Subscriber_1 = require('./Subscriber'); +exports.Subscriber = Subscriber_1.Subscriber; +var AsyncSubject_1 = require('./AsyncSubject'); +exports.AsyncSubject = AsyncSubject_1.AsyncSubject; +var ReplaySubject_1 = require('./ReplaySubject'); +exports.ReplaySubject = ReplaySubject_1.ReplaySubject; +var BehaviorSubject_1 = require('./BehaviorSubject'); +exports.BehaviorSubject = BehaviorSubject_1.BehaviorSubject; +var MulticastObservable_1 = require('./observable/MulticastObservable'); +exports.MulticastObservable = MulticastObservable_1.MulticastObservable; +var ConnectableObservable_1 = require('./observable/ConnectableObservable'); +exports.ConnectableObservable = ConnectableObservable_1.ConnectableObservable; +var Notification_1 = require('./Notification'); +exports.Notification = Notification_1.Notification; +var EmptyError_1 = require('./util/EmptyError'); +exports.EmptyError = EmptyError_1.EmptyError; +var ArgumentOutOfRangeError_1 = require('./util/ArgumentOutOfRangeError'); +exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; +var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError'); +exports.ObjectUnsubscribedError = ObjectUnsubscribedError_1.ObjectUnsubscribedError; +var UnsubscriptionError_1 = require('./util/UnsubscriptionError'); +exports.UnsubscriptionError = UnsubscriptionError_1.UnsubscriptionError; +var timeInterval_1 = require('./operator/timeInterval'); +exports.TimeInterval = timeInterval_1.TimeInterval; +var timestamp_1 = require('./operator/timestamp'); +exports.Timestamp = timestamp_1.Timestamp; +var TestScheduler_1 = require('./testing/TestScheduler'); +exports.TestScheduler = TestScheduler_1.TestScheduler; +var VirtualTimeScheduler_1 = require('./scheduler/VirtualTimeScheduler'); +exports.VirtualTimeScheduler = VirtualTimeScheduler_1.VirtualTimeScheduler; +var AjaxObservable_1 = require('./observable/dom/AjaxObservable'); +exports.AjaxResponse = AjaxObservable_1.AjaxResponse; +exports.AjaxError = AjaxObservable_1.AjaxError; +exports.AjaxTimeoutError = AjaxObservable_1.AjaxTimeoutError; +var asap_1 = require('./scheduler/asap'); +var async_1 = require('./scheduler/async'); +var queue_1 = require('./scheduler/queue'); +var animationFrame_1 = require('./scheduler/animationFrame'); +var rxSubscriber_1 = require('./symbol/rxSubscriber'); +var iterator_1 = require('./symbol/iterator'); +var observable = require('symbol-observable'); +/* tslint:enable:no-unused-variable */ +/** + * @typedef {Object} Rx.Scheduler + * @property {Scheduler} queue Schedules on a queue in the current event frame + * (trampoline scheduler). Use this for iteration operations. + * @property {Scheduler} asap Schedules on the micro task queue, which uses the + * fastest transport mechanism available, either Node.js' `process.nextTick()` + * or Web Worker MessageChannel or setTimeout or others. Use this for + * asynchronous conversions. + * @property {Scheduler} async Schedules work with `setInterval`. Use this for + * time-based operations. + */ +var Scheduler = { + asap: asap_1.asap, + async: async_1.async, + queue: queue_1.queue, + animationFrame: animationFrame_1.animationFrame +}; +exports.Scheduler = Scheduler; +/** + * @typedef {Object} Rx.Symbol + * @property {Symbol|string} rxSubscriber A symbol to use as a property name to + * retrieve an "Rx safe" Observer from an object. "Rx safety" can be defined as + * an object that has all of the traits of an Rx Subscriber, including the + * ability to add and remove subscriptions to the subscription chain and + * guarantees involving event triggering (can't "next" after unsubscription, + * etc). + * @property {Symbol|string} observable A symbol to use as a property name to + * retrieve an Observable as defined by the [ECMAScript "Observable" spec](https://github.com/zenparsing/es-observable). + * @property {Symbol|string} iterator The ES6 symbol to use as a property name + * to retrieve an iterator from an object. + */ +var Symbol = { + rxSubscriber: rxSubscriber_1.$$rxSubscriber, + observable: observable, + iterator: iterator_1.$$iterator +}; +exports.Symbol = Symbol; + +},{"./AsyncSubject":374,"./BehaviorSubject":375,"./Notification":377,"./Observable":378,"./Operator":380,"./ReplaySubject":382,"./Subject":384,"./Subscriber":386,"./Subscription":387,"./add/observable/bindCallback":388,"./add/observable/bindNodeCallback":389,"./add/observable/combineLatest":390,"./add/observable/concat":391,"./add/observable/defer":392,"./add/observable/dom/ajax":393,"./add/observable/dom/webSocket":394,"./add/observable/empty":395,"./add/observable/forkJoin":396,"./add/observable/from":397,"./add/observable/fromEvent":398,"./add/observable/fromEventPattern":399,"./add/observable/fromPromise":400,"./add/observable/generate":401,"./add/observable/if":402,"./add/observable/interval":403,"./add/observable/merge":404,"./add/observable/never":405,"./add/observable/of":406,"./add/observable/onErrorResumeNext":407,"./add/observable/race":408,"./add/observable/range":409,"./add/observable/throw":410,"./add/observable/timer":411,"./add/observable/using":412,"./add/observable/zip":413,"./add/operator/audit":414,"./add/operator/auditTime":415,"./add/operator/buffer":416,"./add/operator/bufferCount":417,"./add/operator/bufferTime":418,"./add/operator/bufferToggle":419,"./add/operator/bufferWhen":420,"./add/operator/cache":421,"./add/operator/catch":422,"./add/operator/combineAll":423,"./add/operator/combineLatest":424,"./add/operator/concat":425,"./add/operator/concatAll":426,"./add/operator/concatMap":427,"./add/operator/concatMapTo":428,"./add/operator/count":429,"./add/operator/debounce":430,"./add/operator/debounceTime":431,"./add/operator/defaultIfEmpty":432,"./add/operator/delay":433,"./add/operator/delayWhen":434,"./add/operator/dematerialize":435,"./add/operator/distinct":436,"./add/operator/distinctKey":437,"./add/operator/distinctUntilChanged":438,"./add/operator/distinctUntilKeyChanged":439,"./add/operator/do":440,"./add/operator/elementAt":441,"./add/operator/every":442,"./add/operator/exhaust":443,"./add/operator/exhaustMap":444,"./add/operator/expand":445,"./add/operator/filter":446,"./add/operator/finally":447,"./add/operator/find":448,"./add/operator/findIndex":449,"./add/operator/first":450,"./add/operator/groupBy":451,"./add/operator/ignoreElements":452,"./add/operator/isEmpty":453,"./add/operator/last":454,"./add/operator/let":455,"./add/operator/map":456,"./add/operator/mapTo":457,"./add/operator/materialize":458,"./add/operator/max":459,"./add/operator/merge":460,"./add/operator/mergeAll":461,"./add/operator/mergeMap":462,"./add/operator/mergeMapTo":463,"./add/operator/mergeScan":464,"./add/operator/min":465,"./add/operator/multicast":466,"./add/operator/observeOn":467,"./add/operator/onErrorResumeNext":468,"./add/operator/pairwise":469,"./add/operator/partition":470,"./add/operator/pluck":471,"./add/operator/publish":472,"./add/operator/publishBehavior":473,"./add/operator/publishLast":474,"./add/operator/publishReplay":475,"./add/operator/race":476,"./add/operator/reduce":477,"./add/operator/repeat":478,"./add/operator/retry":479,"./add/operator/retryWhen":480,"./add/operator/sample":481,"./add/operator/sampleTime":482,"./add/operator/scan":483,"./add/operator/share":484,"./add/operator/single":485,"./add/operator/skip":486,"./add/operator/skipUntil":487,"./add/operator/skipWhile":488,"./add/operator/startWith":489,"./add/operator/subscribeOn":490,"./add/operator/switch":491,"./add/operator/switchMap":492,"./add/operator/switchMapTo":493,"./add/operator/take":494,"./add/operator/takeLast":495,"./add/operator/takeUntil":496,"./add/operator/takeWhile":497,"./add/operator/throttle":498,"./add/operator/throttleTime":499,"./add/operator/timeInterval":500,"./add/operator/timeout":501,"./add/operator/timeoutWith":502,"./add/operator/timestamp":503,"./add/operator/toArray":504,"./add/operator/toPromise":505,"./add/operator/window":506,"./add/operator/windowCount":507,"./add/operator/windowTime":508,"./add/operator/windowToggle":509,"./add/operator/windowWhen":510,"./add/operator/withLatestFrom":511,"./add/operator/zip":512,"./add/operator/zipAll":513,"./observable/ConnectableObservable":518,"./observable/MulticastObservable":530,"./observable/dom/AjaxObservable":543,"./operator/timeInterval":649,"./operator/timestamp":652,"./scheduler/VirtualTimeScheduler":671,"./scheduler/animationFrame":672,"./scheduler/asap":673,"./scheduler/async":674,"./scheduler/queue":675,"./symbol/iterator":676,"./symbol/rxSubscriber":677,"./testing/TestScheduler":682,"./util/ArgumentOutOfRangeError":684,"./util/EmptyError":685,"./util/ObjectUnsubscribedError":690,"./util/UnsubscriptionError":691,"symbol-observable":709}],384:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('./Observable'); +var Subscriber_1 = require('./Subscriber'); +var Subscription_1 = require('./Subscription'); +var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError'); +var SubjectSubscription_1 = require('./SubjectSubscription'); +var rxSubscriber_1 = require('./symbol/rxSubscriber'); +/** + * @class SubjectSubscriber + */ +var SubjectSubscriber = (function (_super) { + __extends(SubjectSubscriber, _super); + function SubjectSubscriber(destination) { + _super.call(this, destination); + this.destination = destination; + } + return SubjectSubscriber; +}(Subscriber_1.Subscriber)); +exports.SubjectSubscriber = SubjectSubscriber; +/** + * @class Subject + */ +var Subject = (function (_super) { + __extends(Subject, _super); + function Subject() { + _super.call(this); + this.observers = []; + this.isUnsubscribed = false; + this.isStopped = false; + this.hasError = false; + this.thrownError = null; + } + Subject.prototype[rxSubscriber_1.$$rxSubscriber] = function () { + return new SubjectSubscriber(this); + }; + Subject.prototype.lift = function (operator) { + var subject = new AnonymousSubject(this, this); + subject.operator = operator; + return subject; + }; + Subject.prototype.next = function (value) { + if (this.isUnsubscribed) { + throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError(); + } + if (!this.isStopped) { + var observers = this.observers; + var len = observers.length; + var copy = observers.slice(); + for (var i = 0; i < len; i++) { + copy[i].next(value); + } + } + }; + Subject.prototype.error = function (err) { + if (this.isUnsubscribed) { + throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError(); + } + this.hasError = true; + this.thrownError = err; + this.isStopped = true; + var observers = this.observers; + var len = observers.length; + var copy = observers.slice(); + for (var i = 0; i < len; i++) { + copy[i].error(err); + } + this.observers.length = 0; + }; + Subject.prototype.complete = function () { + if (this.isUnsubscribed) { + throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError(); + } + this.isStopped = true; + var observers = this.observers; + var len = observers.length; + var copy = observers.slice(); + for (var i = 0; i < len; i++) { + copy[i].complete(); + } + this.observers.length = 0; + }; + Subject.prototype.unsubscribe = function () { + this.isStopped = true; + this.isUnsubscribed = true; + this.observers = null; + }; + Subject.prototype._subscribe = function (subscriber) { + if (this.isUnsubscribed) { + throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError(); + } + else if (this.hasError) { + subscriber.error(this.thrownError); + return Subscription_1.Subscription.EMPTY; + } + else if (this.isStopped) { + subscriber.complete(); + return Subscription_1.Subscription.EMPTY; + } + else { + this.observers.push(subscriber); + return new SubjectSubscription_1.SubjectSubscription(this, subscriber); + } + }; + Subject.prototype.asObservable = function () { + var observable = new Observable_1.Observable(); + observable.source = this; + return observable; + }; + Subject.create = function (destination, source) { + return new AnonymousSubject(destination, source); + }; + return Subject; +}(Observable_1.Observable)); +exports.Subject = Subject; +/** + * @class AnonymousSubject + */ +var AnonymousSubject = (function (_super) { + __extends(AnonymousSubject, _super); + function AnonymousSubject(destination, source) { + _super.call(this); + this.destination = destination; + this.source = source; + } + AnonymousSubject.prototype.next = function (value) { + var destination = this.destination; + if (destination && destination.next) { + destination.next(value); + } + }; + AnonymousSubject.prototype.error = function (err) { + var destination = this.destination; + if (destination && destination.error) { + this.destination.error(err); + } + }; + AnonymousSubject.prototype.complete = function () { + var destination = this.destination; + if (destination && destination.complete) { + this.destination.complete(); + } + }; + AnonymousSubject.prototype._subscribe = function (subscriber) { + var source = this.source; + if (source) { + return this.source.subscribe(subscriber); + } + else { + return Subscription_1.Subscription.EMPTY; + } + }; + return AnonymousSubject; +}(Subject)); +exports.AnonymousSubject = AnonymousSubject; -function fsmIterator(fsm, q0) { - var name = arguments.length <= 2 || arguments[2] === undefined ? 'iterator' : arguments[2]; +},{"./Observable":378,"./SubjectSubscription":385,"./Subscriber":386,"./Subscription":387,"./symbol/rxSubscriber":677,"./util/ObjectUnsubscribedError":690}],385:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscription_1 = require('./Subscription'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SubjectSubscription = (function (_super) { + __extends(SubjectSubscription, _super); + function SubjectSubscription(subject, subscriber) { + _super.call(this); + this.subject = subject; + this.subscriber = subscriber; + this.isUnsubscribed = false; + } + SubjectSubscription.prototype.unsubscribe = function () { + if (this.isUnsubscribed) { + return; + } + this.isUnsubscribed = true; + var subject = this.subject; + var observers = subject.observers; + this.subject = null; + if (!observers || observers.length === 0 || subject.isStopped || subject.isUnsubscribed) { + return; + } + var subscriberIndex = observers.indexOf(this.subscriber); + if (subscriberIndex !== -1) { + observers.splice(subscriberIndex, 1); + } + }; + return SubjectSubscription; +}(Subscription_1.Subscription)); +exports.SubjectSubscription = SubjectSubscription; - var updateState = void 0, - qNext = q0; +},{"./Subscription":387}],386:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var isFunction_1 = require('./util/isFunction'); +var Subscription_1 = require('./Subscription'); +var Observer_1 = require('./Observer'); +var rxSubscriber_1 = require('./symbol/rxSubscriber'); +/** + * Implements the {@link Observer} interface and extends the + * {@link Subscription} class. While the {@link Observer} is the public API for + * consuming the values of an {@link Observable}, all Observers get converted to + * a Subscriber, in order to provide Subscription-like capabilities such as + * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for + * implementing operators, but it is rarely used as a public API. + * + * @class Subscriber + */ +var Subscriber = (function (_super) { + __extends(Subscriber, _super); + /** + * @param {Observer|function(value: T): void} [destinationOrNext] A partially + * defined Observer or a `next` callback function. + * @param {function(e: ?any): void} [error] The `error` callback of an + * Observer. + * @param {function(): void} [complete] The `complete` callback of an + * Observer. + */ + function Subscriber(destinationOrNext, error, complete) { + _super.call(this); + this.syncErrorValue = null; + this.syncErrorThrown = false; + this.syncErrorThrowable = false; + this.isStopped = false; + switch (arguments.length) { + case 0: + this.destination = Observer_1.empty; + break; + case 1: + if (!destinationOrNext) { + this.destination = Observer_1.empty; + break; + } + if (typeof destinationOrNext === 'object') { + if (destinationOrNext instanceof Subscriber) { + this.destination = destinationOrNext; + this.destination.add(this); + } + else { + this.syncErrorThrowable = true; + this.destination = new SafeSubscriber(this, destinationOrNext); + } + break; + } + default: + this.syncErrorThrowable = true; + this.destination = new SafeSubscriber(this, destinationOrNext, error, complete); + break; + } + } + Subscriber.prototype[rxSubscriber_1.$$rxSubscriber] = function () { return this; }; + /** + * A static factory for a Subscriber, given a (potentially partial) definition + * of an Observer. + * @param {function(x: ?T): void} [next] The `next` callback of an Observer. + * @param {function(e: ?any): void} [error] The `error` callback of an + * Observer. + * @param {function(): void} [complete] The `complete` callback of an + * Observer. + * @return {Subscriber} A Subscriber wrapping the (partially defined) + * Observer represented by the given arguments. + */ + Subscriber.create = function (next, error, complete) { + var subscriber = new Subscriber(next, error, complete); + subscriber.syncErrorThrowable = false; + return subscriber; + }; + /** + * The {@link Observer} callback to receive notifications of type `next` from + * the Observable, with a value. The Observable may call this method 0 or more + * times. + * @param {T} [value] The `next` value. + * @return {void} + */ + Subscriber.prototype.next = function (value) { + if (!this.isStopped) { + this._next(value); + } + }; + /** + * The {@link Observer} callback to receive notifications of type `error` from + * the Observable, with an attached {@link Error}. Notifies the Observer that + * the Observable has experienced an error condition. + * @param {any} [err] The `error` exception. + * @return {void} + */ + Subscriber.prototype.error = function (err) { + if (!this.isStopped) { + this.isStopped = true; + this._error(err); + } + }; + /** + * The {@link Observer} callback to receive a valueless notification of type + * `complete` from the Observable. Notifies the Observer that the Observable + * has finished sending push-based notifications. + * @return {void} + */ + Subscriber.prototype.complete = function () { + if (!this.isStopped) { + this.isStopped = true; + this._complete(); + } + }; + Subscriber.prototype.unsubscribe = function () { + if (this.isUnsubscribed) { + return; + } + this.isStopped = true; + _super.prototype.unsubscribe.call(this); + }; + Subscriber.prototype._next = function (value) { + this.destination.next(value); + }; + Subscriber.prototype._error = function (err) { + this.destination.error(err); + this.unsubscribe(); + }; + Subscriber.prototype._complete = function () { + this.destination.complete(); + this.unsubscribe(); + }; + return Subscriber; +}(Subscription_1.Subscription)); +exports.Subscriber = Subscriber; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SafeSubscriber = (function (_super) { + __extends(SafeSubscriber, _super); + function SafeSubscriber(_parent, observerOrNext, error, complete) { + _super.call(this); + this._parent = _parent; + var next; + var context = this; + if (isFunction_1.isFunction(observerOrNext)) { + next = observerOrNext; + } + else if (observerOrNext) { + context = observerOrNext; + next = observerOrNext.next; + error = observerOrNext.error; + complete = observerOrNext.complete; + if (isFunction_1.isFunction(context.unsubscribe)) { + this.add(context.unsubscribe.bind(context)); + } + context.unsubscribe = this.unsubscribe.bind(this); + } + this._context = context; + this._next = next; + this._error = error; + this._complete = complete; + } + SafeSubscriber.prototype.next = function (value) { + if (!this.isStopped && this._next) { + var _parent = this._parent; + if (!_parent.syncErrorThrowable) { + this.__tryOrUnsub(this._next, value); + } + else if (this.__tryOrSetError(_parent, this._next, value)) { + this.unsubscribe(); + } + } + }; + SafeSubscriber.prototype.error = function (err) { + if (!this.isStopped) { + var _parent = this._parent; + if (this._error) { + if (!_parent.syncErrorThrowable) { + this.__tryOrUnsub(this._error, err); + this.unsubscribe(); + } + else { + this.__tryOrSetError(_parent, this._error, err); + this.unsubscribe(); + } + } + else if (!_parent.syncErrorThrowable) { + this.unsubscribe(); + throw err; + } + else { + _parent.syncErrorValue = err; + _parent.syncErrorThrown = true; + this.unsubscribe(); + } + } + }; + SafeSubscriber.prototype.complete = function () { + if (!this.isStopped) { + var _parent = this._parent; + if (this._complete) { + if (!_parent.syncErrorThrowable) { + this.__tryOrUnsub(this._complete); + this.unsubscribe(); + } + else { + this.__tryOrSetError(_parent, this._complete); + this.unsubscribe(); + } + } + else { + this.unsubscribe(); + } + } + }; + SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) { + try { + fn.call(this._context, value); + } + catch (err) { + this.unsubscribe(); + throw err; + } + }; + SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) { + try { + fn.call(this._context, value); + } + catch (err) { + parent.syncErrorValue = err; + parent.syncErrorThrown = true; + return true; + } + return false; + }; + SafeSubscriber.prototype._unsubscribe = function () { + var _parent = this._parent; + this._context = null; + this._parent = null; + _parent.unsubscribe(); + }; + return SafeSubscriber; +}(Subscriber)); - function next(arg, error) { - if (qNext === qEnd) { - return done; +},{"./Observer":379,"./Subscription":387,"./symbol/rxSubscriber":677,"./util/isFunction":697}],387:[function(require,module,exports){ +"use strict"; +var isArray_1 = require('./util/isArray'); +var isObject_1 = require('./util/isObject'); +var isFunction_1 = require('./util/isFunction'); +var tryCatch_1 = require('./util/tryCatch'); +var errorObject_1 = require('./util/errorObject'); +var UnsubscriptionError_1 = require('./util/UnsubscriptionError'); +/** + * Represents a disposable resource, such as the execution of an Observable. A + * Subscription has one important method, `unsubscribe`, that takes no argument + * and just disposes the resource held by the subscription. + * + * Additionally, subscriptions may be grouped together through the `add()` + * method, which will attach a child Subscription to the current Subscription. + * When a Subscription is unsubscribed, all its children (and its grandchildren) + * will be unsubscribed as well. + * + * @class Subscription + */ +var Subscription = (function () { + /** + * @param {function(): void} [unsubscribe] A function describing how to + * perform the disposal of resources when the `unsubscribe` method is called. + */ + function Subscription(unsubscribe) { + /** + * A flag to indicate whether this Subscription has already been unsubscribed. + * @type {boolean} + */ + this.isUnsubscribed = false; + if (unsubscribe) { + this._unsubscribe = unsubscribe; + } } + /** + * Disposes the resources held by the subscription. May, for instance, cancel + * an ongoing Observable execution or cancel any other type of work that + * started when the Subscription was created. + * @return {void} + */ + Subscription.prototype.unsubscribe = function () { + var hasErrors = false; + var errors; + if (this.isUnsubscribed) { + return; + } + this.isUnsubscribed = true; + var _a = this, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; + this._subscriptions = null; + if (isFunction_1.isFunction(_unsubscribe)) { + var trial = tryCatch_1.tryCatch(_unsubscribe).call(this); + if (trial === errorObject_1.errorObject) { + hasErrors = true; + (errors = errors || []).push(errorObject_1.errorObject.e); + } + } + if (isArray_1.isArray(_subscriptions)) { + var index = -1; + var len = _subscriptions.length; + while (++index < len) { + var sub = _subscriptions[index]; + if (isObject_1.isObject(sub)) { + var trial = tryCatch_1.tryCatch(sub.unsubscribe).call(sub); + if (trial === errorObject_1.errorObject) { + hasErrors = true; + errors = errors || []; + var err = errorObject_1.errorObject.e; + if (err instanceof UnsubscriptionError_1.UnsubscriptionError) { + errors = errors.concat(err.errors); + } + else { + errors.push(err); + } + } + } + } + } + if (hasErrors) { + throw new UnsubscriptionError_1.UnsubscriptionError(errors); + } + }; + /** + * Adds a tear down to be called during the unsubscribe() of this + * Subscription. + * + * If the tear down being added is a subscription that is already + * unsubscribed, is the same reference `add` is being called on, or is + * `Subscription.EMPTY`, it will not be added. + * + * If this subscription is already in an `isUnsubscribed` state, the passed + * tear down logic will be executed immediately. + * + * @param {TeardownLogic} teardown The additional logic to execute on + * teardown. + * @return {Subscription} Returns the Subscription used or created to be + * added to the inner subscriptions list. This Subscription can be used with + * `remove()` to remove the passed teardown logic from the inner subscriptions + * list. + */ + Subscription.prototype.add = function (teardown) { + if (!teardown || (teardown === this) || (teardown === Subscription.EMPTY)) { + return; + } + var sub = teardown; + switch (typeof teardown) { + case 'function': + sub = new Subscription(teardown); + case 'object': + if (sub.isUnsubscribed || typeof sub.unsubscribe !== 'function') { + break; + } + else if (this.isUnsubscribed) { + sub.unsubscribe(); + } + else { + (this._subscriptions || (this._subscriptions = [])).push(sub); + } + break; + default: + throw new Error('Unrecognized teardown ' + teardown + ' added to Subscription.'); + } + return sub; + }; + /** + * Removes a Subscription from the internal list of subscriptions that will + * unsubscribe during the unsubscribe process of this Subscription. + * @param {Subscription} subscription The subscription to remove. + * @return {void} + */ + Subscription.prototype.remove = function (subscription) { + // HACK: This might be redundant because of the logic in `add()` + if (subscription == null || (subscription === this) || (subscription === Subscription.EMPTY)) { + return; + } + var subscriptions = this._subscriptions; + if (subscriptions) { + var subscriptionIndex = subscriptions.indexOf(subscription); + if (subscriptionIndex !== -1) { + subscriptions.splice(subscriptionIndex, 1); + } + } + }; + Subscription.EMPTY = (function (empty) { + empty.isUnsubscribed = true; + return empty; + }(new Subscription())); + return Subscription; +}()); +exports.Subscription = Subscription; + +},{"./util/UnsubscriptionError":691,"./util/errorObject":694,"./util/isArray":695,"./util/isFunction":697,"./util/isObject":699,"./util/tryCatch":708}],388:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var bindCallback_1 = require('../../observable/bindCallback'); +Observable_1.Observable.bindCallback = bindCallback_1.bindCallback; - if (error) { - qNext = qEnd; - throw error; - } else { - updateState && updateState(arg); +},{"../../Observable":378,"../../observable/bindCallback":538}],389:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var bindNodeCallback_1 = require('../../observable/bindNodeCallback'); +Observable_1.Observable.bindNodeCallback = bindNodeCallback_1.bindNodeCallback; - var _fsm$qNext = fsm[qNext](); +},{"../../Observable":378,"../../observable/bindNodeCallback":539}],390:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var combineLatest_1 = require('../../observable/combineLatest'); +Observable_1.Observable.combineLatest = combineLatest_1.combineLatest; - var _fsm$qNext2 = _slicedToArray(_fsm$qNext, 3); +},{"../../Observable":378,"../../observable/combineLatest":540}],391:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var concat_1 = require('../../observable/concat'); +Observable_1.Observable.concat = concat_1.concat; - var q = _fsm$qNext2[0]; - var output = _fsm$qNext2[1]; - var _updateState = _fsm$qNext2[2]; +},{"../../Observable":378,"../../observable/concat":541}],392:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var defer_1 = require('../../observable/defer'); +Observable_1.Observable.defer = defer_1.defer; - qNext = q; - updateState = _updateState; - return qNext === qEnd ? done : output; - } - } +},{"../../Observable":378,"../../observable/defer":542}],393:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../../Observable'); +var ajax_1 = require('../../../observable/dom/ajax'); +Observable_1.Observable.ajax = ajax_1.ajax; - return (0, _utils.makeIterator)(next, function (error) { - return next(null, error); - }, name); -} +},{"../../../Observable":378,"../../../observable/dom/ajax":545}],394:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../../Observable'); +var webSocket_1 = require('../../../observable/dom/webSocket'); +Observable_1.Observable.webSocket = webSocket_1.webSocket; -function safeName(pattern) { - if (Array.isArray(pattern)) { - return String(pattern.map(function (entry) { - return String(entry); - })); - } else { - return String(pattern); - } -} +},{"../../../Observable":378,"../../../observable/dom/webSocket":546}],395:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var empty_1 = require('../../observable/empty'); +Observable_1.Observable.empty = empty_1.empty; -function takeEvery(pattern, worker) { - for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - args[_key - 2] = arguments[_key]; - } +},{"../../Observable":378,"../../observable/empty":547}],396:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var forkJoin_1 = require('../../observable/forkJoin'); +Observable_1.Observable.forkJoin = forkJoin_1.forkJoin; - var yTake = { done: false, value: (0, _io.take)(pattern) }; - var yFork = function yFork(ac) { - return { done: false, value: _io.fork.apply(undefined, [worker].concat(args, [ac])) }; - }; +},{"../../Observable":378,"../../observable/forkJoin":548}],397:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var from_1 = require('../../observable/from'); +Observable_1.Observable.from = from_1.from; - var action = void 0, - setAction = function setAction(ac) { - return action = ac; - }; +},{"../../Observable":378,"../../observable/from":549}],398:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var fromEvent_1 = require('../../observable/fromEvent'); +Observable_1.Observable.fromEvent = fromEvent_1.fromEvent; - return fsmIterator({ - q1: function q1() { - return ['q2', yTake, setAction]; - }, - q2: function q2() { - return action === _channel.END ? [qEnd] : ['q1', yFork(action)]; - } - }, 'q1', 'takeEvery(' + safeName(pattern) + ', ' + worker.name + ')'); -} +},{"../../Observable":378,"../../observable/fromEvent":550}],399:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var fromEventPattern_1 = require('../../observable/fromEventPattern'); +Observable_1.Observable.fromEventPattern = fromEventPattern_1.fromEventPattern; -function takeLatest(pattern, worker) { - for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { - args[_key2 - 2] = arguments[_key2]; - } +},{"../../Observable":378,"../../observable/fromEventPattern":551}],400:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var fromPromise_1 = require('../../observable/fromPromise'); +Observable_1.Observable.fromPromise = fromPromise_1.fromPromise; - var yTake = { done: false, value: (0, _io.take)(pattern) }; - var yFork = function yFork(ac) { - return { done: false, value: _io.fork.apply(undefined, [worker].concat(args, [ac])) }; - }; - var yCancel = function yCancel(task) { - return { done: false, value: (0, _io.cancel)(task) }; - }; +},{"../../Observable":378,"../../observable/fromPromise":552}],401:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var GenerateObservable_1 = require('../../observable/GenerateObservable'); +Observable_1.Observable.generate = GenerateObservable_1.GenerateObservable.create; - var task = void 0, - action = void 0; - var setTask = function setTask(t) { - return task = t; - }; - var setAction = function setAction(ac) { - return action = ac; - }; +},{"../../Observable":378,"../../observable/GenerateObservable":526}],402:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var if_1 = require('../../observable/if'); +Observable_1.Observable.if = if_1._if; - return fsmIterator({ - q1: function q1() { - return ['q2', yTake, setAction]; - }, - q2: function q2() { - return action === _channel.END ? [qEnd] : task ? ['q3', yCancel(task)] : ['q1', yFork(action), setTask]; - }, - q3: function q3() { - return ['q1', yFork(action), setTask]; - } - }, 'q1', 'takeLatest(' + safeName(pattern) + ', ' + worker.name + ')'); -} -},{"./channel":368,"./io":369,"./utils":374}],374:[function(require,module,exports){ -'use strict'; +},{"../../Observable":378,"../../observable/if":553}],403:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var interval_1 = require('../../observable/interval'); +Observable_1.Observable.interval = interval_1.interval; -Object.defineProperty(exports, "__esModule", { - value: true -}); +},{"../../Observable":378,"../../observable/interval":554}],404:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var merge_1 = require('../../observable/merge'); +Observable_1.Observable.merge = merge_1.merge; -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +},{"../../Observable":378,"../../observable/merge":555}],405:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var never_1 = require('../../observable/never'); +Observable_1.Observable.never = never_1.never; -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +},{"../../Observable":378,"../../observable/never":556}],406:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var of_1 = require('../../observable/of'); +Observable_1.Observable.of = of_1.of; -exports.check = check; -exports.remove = remove; -exports.deferred = deferred; -exports.arrayOfDeffered = arrayOfDeffered; -exports.delay = delay; -exports.createMockTask = createMockTask; -exports.autoInc = autoInc; -exports.makeIterator = makeIterator; -exports.log = log; +},{"../../Observable":378,"../../observable/of":557}],407:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var onErrorResumeNext_1 = require('../../operator/onErrorResumeNext'); +Observable_1.Observable.onErrorResumeNext = onErrorResumeNext_1.onErrorResumeNextStatic; -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +},{"../../Observable":378,"../../operator/onErrorResumeNext":617}],408:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var race_1 = require('../../operator/race'); +Observable_1.Observable.race = race_1.raceStatic; -var sym = exports.sym = function sym(id) { - return '@@redux-saga/' + id; -}; -var TASK = exports.TASK = sym('TASK'); -var MATCH = exports.MATCH = sym('MATCH'); -var CANCEL = exports.CANCEL = sym('cancelPromise'); -var konst = exports.konst = function konst(v) { - return function () { - return v; - }; -}; -var kTrue = exports.kTrue = konst(true); -var kFalse = exports.kFalse = konst(false); -var noop = exports.noop = function noop() {}; -var ident = exports.ident = function ident(v) { - return v; -}; +},{"../../Observable":378,"../../operator/race":625}],409:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var range_1 = require('../../observable/range'); +Observable_1.Observable.range = range_1.range; -function check(value, predicate, error) { - if (!predicate(value)) { - log('error', 'uncaught at check', error); - throw new Error(error); - } -} +},{"../../Observable":378,"../../observable/range":558}],410:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var throw_1 = require('../../observable/throw'); +Observable_1.Observable.throw = throw_1._throw; -var is = exports.is = { - undef: function undef(v) { - return v === null || v === undefined; - }, - notUndef: function notUndef(v) { - return v !== null && v !== undefined; - }, - func: function func(f) { - return typeof f === 'function'; - }, - number: function number(n) { - return typeof n === 'number'; - }, - array: Array.isArray, - promise: function promise(p) { - return p && is.func(p.then); - }, - iterator: function iterator(it) { - return it && is.func(it.next) && is.func(it.throw); - }, - task: function task(t) { - return t && t[TASK]; - }, - take: function take(ch) { - return ch && is.func(ch.take); - }, - put: function put(ch) { - return ch && is.func(ch.put); - }, - observable: function observable(ob) { - return ob && is.func(ob.subscribe); - }, - buffer: function buffer(buf) { - return buf && is.func(buf.isEmpty) && is.func(buf.take) && is.func(buf.put); - }, - pattern: function pattern(pat) { - return pat && (typeof pat === 'string' || (typeof pat === 'undefined' ? 'undefined' : _typeof(pat)) === 'symbol' || is.func(pat) || is.array(pat)); - } -}; +},{"../../Observable":378,"../../observable/throw":559}],411:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var timer_1 = require('../../observable/timer'); +Observable_1.Observable.timer = timer_1.timer; -function remove(array, item) { - var index = array.indexOf(item); - if (index >= 0) { - array.splice(index, 1); - } -} +},{"../../Observable":378,"../../observable/timer":560}],412:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var using_1 = require('../../observable/using'); +Observable_1.Observable.using = using_1.using; -function deferred() { - var props = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; +},{"../../Observable":378,"../../observable/using":561}],413:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var zip_1 = require('../../observable/zip'); +Observable_1.Observable.zip = zip_1.zip; - var def = _extends({}, props); - var promise = new Promise(function (resolve, reject) { - def.resolve = resolve; - def.reject = reject; - }); - def.promise = promise; - return def; -} +},{"../../Observable":378,"../../observable/zip":562}],414:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var audit_1 = require('../../operator/audit'); +Observable_1.Observable.prototype.audit = audit_1.audit; -function arrayOfDeffered(length) { - var arr = []; - for (var i = 0; i < length; i++) { - arr.push(deferred()); - } - return arr; -} +},{"../../Observable":378,"../../operator/audit":563}],415:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var auditTime_1 = require('../../operator/auditTime'); +Observable_1.Observable.prototype.auditTime = auditTime_1.auditTime; -function delay(ms) { - var val = arguments.length <= 1 || arguments[1] === undefined ? true : arguments[1]; +},{"../../Observable":378,"../../operator/auditTime":564}],416:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var buffer_1 = require('../../operator/buffer'); +Observable_1.Observable.prototype.buffer = buffer_1.buffer; - var timeoutId = void 0; - var promise = new Promise(function (resolve) { - timeoutId = setTimeout(function () { - return resolve(val); - }, ms); - }); +},{"../../Observable":378,"../../operator/buffer":565}],417:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var bufferCount_1 = require('../../operator/bufferCount'); +Observable_1.Observable.prototype.bufferCount = bufferCount_1.bufferCount; - promise[CANCEL] = function () { - return clearTimeout(timeoutId); - }; +},{"../../Observable":378,"../../operator/bufferCount":566}],418:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var bufferTime_1 = require('../../operator/bufferTime'); +Observable_1.Observable.prototype.bufferTime = bufferTime_1.bufferTime; - return promise; -} +},{"../../Observable":378,"../../operator/bufferTime":567}],419:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var bufferToggle_1 = require('../../operator/bufferToggle'); +Observable_1.Observable.prototype.bufferToggle = bufferToggle_1.bufferToggle; -function createMockTask() { - var _ref; +},{"../../Observable":378,"../../operator/bufferToggle":568}],420:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var bufferWhen_1 = require('../../operator/bufferWhen'); +Observable_1.Observable.prototype.bufferWhen = bufferWhen_1.bufferWhen; - var running = true; - var _result = void 0, - _error = void 0; +},{"../../Observable":378,"../../operator/bufferWhen":569}],421:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var cache_1 = require('../../operator/cache'); +Observable_1.Observable.prototype.cache = cache_1.cache; - return _ref = {}, _defineProperty(_ref, TASK, true), _defineProperty(_ref, 'isRunning', function isRunning() { - return running; - }), _defineProperty(_ref, 'result', function result() { - return _result; - }), _defineProperty(_ref, 'error', function error() { - return _error; - }), _defineProperty(_ref, 'setRunning', function setRunning(b) { - return running = b; - }), _defineProperty(_ref, 'setResult', function setResult(r) { - return _result = r; - }), _defineProperty(_ref, 'setError', function setError(e) { - return _error = e; - }), _ref; -} +},{"../../Observable":378,"../../operator/cache":570}],422:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var catch_1 = require('../../operator/catch'); +Observable_1.Observable.prototype.catch = catch_1._catch; -function autoInc() { - var seed = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; +},{"../../Observable":378,"../../operator/catch":571}],423:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var combineAll_1 = require('../../operator/combineAll'); +Observable_1.Observable.prototype.combineAll = combineAll_1.combineAll; - return function () { - return ++seed; - }; -} +},{"../../Observable":378,"../../operator/combineAll":572}],424:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var combineLatest_1 = require('../../operator/combineLatest'); +Observable_1.Observable.prototype.combineLatest = combineLatest_1.combineLatest; -var kThrow = function kThrow(err) { - throw err; -}; -function makeIterator(next) { - var thro = arguments.length <= 1 || arguments[1] === undefined ? kThrow : arguments[1]; - var name = arguments.length <= 2 || arguments[2] === undefined ? '' : arguments[2]; +},{"../../Observable":378,"../../operator/combineLatest":573}],425:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var concat_1 = require('../../operator/concat'); +Observable_1.Observable.prototype.concat = concat_1.concat; - var iterator = { name: name, next: next, throw: thro }; - if (typeof Symbol !== 'undefined') { - iterator[Symbol.iterator] = function () { - return iterator; - }; - } - return iterator; -} +},{"../../Observable":378,"../../operator/concat":574}],426:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var concatAll_1 = require('../../operator/concatAll'); +Observable_1.Observable.prototype.concatAll = concatAll_1.concatAll; -/** - Print error in a useful way whether in a browser environment - (with expandable error stack traces), or in a node.js environment - (text-only log output) - **/ -function log(level, message, error) { - /*eslint-disable no-console*/ - if (typeof window === 'undefined') { - console.log('redux-saga ' + level + ': ' + message + '\n' + (error && error.stack || error)); - } else { - console[level].call(console, message, error); - } -} +},{"../../Observable":378,"../../operator/concatAll":575}],427:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var concatMap_1 = require('../../operator/concatMap'); +Observable_1.Observable.prototype.concatMap = concatMap_1.concatMap; -var internalErr = exports.internalErr = function internalErr(err) { - return new Error('\n redux-saga: Error checking hooks detected an inconsisten state. This is likely a bug\n in redux-saga code and not yours. Thanks for reporting this in the project\'s github repo.\n Error: ' + err + '\n'); -}; -},{}],375:[function(require,module,exports){ -'use strict'; +},{"../../Observable":378,"../../operator/concatMap":576}],428:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var concatMapTo_1 = require('../../operator/concatMapTo'); +Observable_1.Observable.prototype.concatMapTo = concatMapTo_1.concatMapTo; -Object.defineProperty(exports, "__esModule", { - value: true -}); +},{"../../Observable":378,"../../operator/concatMapTo":577}],429:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var count_1 = require('../../operator/count'); +Observable_1.Observable.prototype.count = count_1.count; -var _utils = require('./internal/utils'); +},{"../../Observable":378,"../../operator/count":578}],430:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var debounce_1 = require('../../operator/debounce'); +Observable_1.Observable.prototype.debounce = debounce_1.debounce; -Object.defineProperty(exports, 'TASK', { - enumerable: true, - get: function get() { - return _utils.TASK; - } -}); -Object.defineProperty(exports, 'noop', { - enumerable: true, - get: function get() { - return _utils.noop; - } -}); -Object.defineProperty(exports, 'is', { - enumerable: true, - get: function get() { - return _utils.is; - } -}); -Object.defineProperty(exports, 'deferred', { - enumerable: true, - get: function get() { - return _utils.deferred; - } -}); -Object.defineProperty(exports, 'arrayOfDeffered', { - enumerable: true, - get: function get() { - return _utils.arrayOfDeffered; - } -}); -Object.defineProperty(exports, 'createMockTask', { - enumerable: true, - get: function get() { - return _utils.createMockTask; - } -}); +},{"../../Observable":378,"../../operator/debounce":579}],431:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var debounceTime_1 = require('../../operator/debounceTime'); +Observable_1.Observable.prototype.debounceTime = debounceTime_1.debounceTime; -var _io = require('./internal/io'); +},{"../../Observable":378,"../../operator/debounceTime":580}],432:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var defaultIfEmpty_1 = require('../../operator/defaultIfEmpty'); +Observable_1.Observable.prototype.defaultIfEmpty = defaultIfEmpty_1.defaultIfEmpty; -Object.defineProperty(exports, 'asEffect', { - enumerable: true, - get: function get() { - return _io.asEffect; - } -}); -},{"./internal/io":369,"./internal/utils":374}],376:[function(require,module,exports){ -'use strict'; +},{"../../Observable":378,"../../operator/defaultIfEmpty":581}],433:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var delay_1 = require('../../operator/delay'); +Observable_1.Observable.prototype.delay = delay_1.delay; -exports.__esModule = true; +},{"../../Observable":378,"../../operator/delay":582}],434:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var delayWhen_1 = require('../../operator/delayWhen'); +Observable_1.Observable.prototype.delayWhen = delayWhen_1.delayWhen; -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +},{"../../Observable":378,"../../operator/delayWhen":583}],435:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var dematerialize_1 = require('../../operator/dematerialize'); +Observable_1.Observable.prototype.dematerialize = dematerialize_1.dematerialize; -exports["default"] = applyMiddleware; +},{"../../Observable":378,"../../operator/dematerialize":584}],436:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var distinct_1 = require('../../operator/distinct'); +Observable_1.Observable.prototype.distinct = distinct_1.distinct; -var _compose = require('./compose'); +},{"../../Observable":378,"../../operator/distinct":585}],437:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var distinctKey_1 = require('../../operator/distinctKey'); +Observable_1.Observable.prototype.distinctKey = distinctKey_1.distinctKey; -var _compose2 = _interopRequireDefault(_compose); +},{"../../Observable":378,"../../operator/distinctKey":586}],438:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var distinctUntilChanged_1 = require('../../operator/distinctUntilChanged'); +Observable_1.Observable.prototype.distinctUntilChanged = distinctUntilChanged_1.distinctUntilChanged; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } +},{"../../Observable":378,"../../operator/distinctUntilChanged":587}],439:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var distinctUntilKeyChanged_1 = require('../../operator/distinctUntilKeyChanged'); +Observable_1.Observable.prototype.distinctUntilKeyChanged = distinctUntilKeyChanged_1.distinctUntilKeyChanged; -/** - * Creates a store enhancer that applies middleware to the dispatch method - * of the Redux store. This is handy for a variety of tasks, such as expressing - * asynchronous actions in a concise manner, or logging every action payload. - * - * See `redux-thunk` package as an example of the Redux middleware. - * - * Because middleware is potentially asynchronous, this should be the first - * store enhancer in the composition chain. - * - * Note that each middleware will be given the `dispatch` and `getState` functions - * as named arguments. - * - * @param {...Function} middlewares The middleware chain to be applied. - * @returns {Function} A store enhancer applying the middleware. - */ -function applyMiddleware() { - for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) { - middlewares[_key] = arguments[_key]; - } +},{"../../Observable":378,"../../operator/distinctUntilKeyChanged":588}],440:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var do_1 = require('../../operator/do'); +Observable_1.Observable.prototype.do = do_1._do; - return function (createStore) { - return function (reducer, initialState, enhancer) { - var store = createStore(reducer, initialState, enhancer); - var _dispatch = store.dispatch; - var chain = []; +},{"../../Observable":378,"../../operator/do":589}],441:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var elementAt_1 = require('../../operator/elementAt'); +Observable_1.Observable.prototype.elementAt = elementAt_1.elementAt; - var middlewareAPI = { - getState: store.getState, - dispatch: function dispatch(action) { - return _dispatch(action); - } - }; - chain = middlewares.map(function (middleware) { - return middleware(middlewareAPI); - }); - _dispatch = _compose2["default"].apply(undefined, chain)(store.dispatch); +},{"../../Observable":378,"../../operator/elementAt":590}],442:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var every_1 = require('../../operator/every'); +Observable_1.Observable.prototype.every = every_1.every; - return _extends({}, store, { - dispatch: _dispatch - }); - }; - }; -} -},{"./compose":379}],377:[function(require,module,exports){ -'use strict'; +},{"../../Observable":378,"../../operator/every":591}],443:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var exhaust_1 = require('../../operator/exhaust'); +Observable_1.Observable.prototype.exhaust = exhaust_1.exhaust; -exports.__esModule = true; -exports["default"] = bindActionCreators; -function bindActionCreator(actionCreator, dispatch) { - return function () { - return dispatch(actionCreator.apply(undefined, arguments)); - }; -} +},{"../../Observable":378,"../../operator/exhaust":592}],444:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var exhaustMap_1 = require('../../operator/exhaustMap'); +Observable_1.Observable.prototype.exhaustMap = exhaustMap_1.exhaustMap; -/** - * Turns an object whose values are action creators, into an object with the - * same keys, but with every function wrapped into a `dispatch` call so they - * may be invoked directly. This is just a convenience method, as you can call - * `store.dispatch(MyActionCreators.doSomething())` yourself just fine. - * - * For convenience, you can also pass a single function as the first argument, - * and get a function in return. - * - * @param {Function|Object} actionCreators An object whose values are action - * creator functions. One handy way to obtain it is to use ES6 `import * as` - * syntax. You may also pass a single function. - * - * @param {Function} dispatch The `dispatch` function available on your Redux - * store. - * - * @returns {Function|Object} The object mimicking the original object, but with - * every action creator wrapped into the `dispatch` call. If you passed a - * function as `actionCreators`, the return value will also be a single - * function. - */ -function bindActionCreators(actionCreators, dispatch) { - if (typeof actionCreators === 'function') { - return bindActionCreator(actionCreators, dispatch); - } +},{"../../Observable":378,"../../operator/exhaustMap":593}],445:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var expand_1 = require('../../operator/expand'); +Observable_1.Observable.prototype.expand = expand_1.expand; - if (typeof actionCreators !== 'object' || actionCreators === null) { - throw new Error('bindActionCreators expected an object or a function, instead received ' + (actionCreators === null ? 'null' : typeof actionCreators) + '. ' + 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'); - } +},{"../../Observable":378,"../../operator/expand":594}],446:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var filter_1 = require('../../operator/filter'); +Observable_1.Observable.prototype.filter = filter_1.filter; - var keys = Object.keys(actionCreators); - var boundActionCreators = {}; - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - var actionCreator = actionCreators[key]; - if (typeof actionCreator === 'function') { - boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); - } - } - return boundActionCreators; -} -},{}],378:[function(require,module,exports){ -(function (process){ -'use strict'; +},{"../../Observable":378,"../../operator/filter":595}],447:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var finally_1 = require('../../operator/finally'); +Observable_1.Observable.prototype.finally = finally_1._finally; -exports.__esModule = true; -exports["default"] = combineReducers; +},{"../../Observable":378,"../../operator/finally":596}],448:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var find_1 = require('../../operator/find'); +Observable_1.Observable.prototype.find = find_1.find; -var _createStore = require('./createStore'); +},{"../../Observable":378,"../../operator/find":597}],449:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var findIndex_1 = require('../../operator/findIndex'); +Observable_1.Observable.prototype.findIndex = findIndex_1.findIndex; -var _isPlainObject = require('lodash/isPlainObject'); +},{"../../Observable":378,"../../operator/findIndex":598}],450:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var first_1 = require('../../operator/first'); +Observable_1.Observable.prototype.first = first_1.first; -var _isPlainObject2 = _interopRequireDefault(_isPlainObject); +},{"../../Observable":378,"../../operator/first":599}],451:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var groupBy_1 = require('../../operator/groupBy'); +Observable_1.Observable.prototype.groupBy = groupBy_1.groupBy; -var _warning = require('./utils/warning'); +},{"../../Observable":378,"../../operator/groupBy":600}],452:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var ignoreElements_1 = require('../../operator/ignoreElements'); +Observable_1.Observable.prototype.ignoreElements = ignoreElements_1.ignoreElements; -var _warning2 = _interopRequireDefault(_warning); +},{"../../Observable":378,"../../operator/ignoreElements":601}],453:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var isEmpty_1 = require('../../operator/isEmpty'); +Observable_1.Observable.prototype.isEmpty = isEmpty_1.isEmpty; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } +},{"../../Observable":378,"../../operator/isEmpty":602}],454:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var last_1 = require('../../operator/last'); +Observable_1.Observable.prototype.last = last_1.last; -function getUndefinedStateErrorMessage(key, action) { - var actionType = action && action.type; - var actionName = actionType && '"' + actionType.toString() + '"' || 'an action'; +},{"../../Observable":378,"../../operator/last":603}],455:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var let_1 = require('../../operator/let'); +Observable_1.Observable.prototype.let = let_1.letProto; +Observable_1.Observable.prototype.letBind = let_1.letProto; - return 'Given action ' + actionName + ', reducer "' + key + '" returned undefined. ' + 'To ignore an action, you must explicitly return the previous state.'; -} +},{"../../Observable":378,"../../operator/let":604}],456:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var map_1 = require('../../operator/map'); +Observable_1.Observable.prototype.map = map_1.map; -function getUnexpectedStateShapeWarningMessage(inputState, reducers, action) { - var reducerKeys = Object.keys(reducers); - var argumentName = action && action.type === _createStore.ActionTypes.INIT ? 'initialState argument passed to createStore' : 'previous state received by the reducer'; +},{"../../Observable":378,"../../operator/map":605}],457:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var mapTo_1 = require('../../operator/mapTo'); +Observable_1.Observable.prototype.mapTo = mapTo_1.mapTo; - if (reducerKeys.length === 0) { - return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.'; - } +},{"../../Observable":378,"../../operator/mapTo":606}],458:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var materialize_1 = require('../../operator/materialize'); +Observable_1.Observable.prototype.materialize = materialize_1.materialize; - if (!(0, _isPlainObject2["default"])(inputState)) { - return 'The ' + argumentName + ' has unexpected type of "' + {}.toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] + '". Expected argument to be an object with the following ' + ('keys: "' + reducerKeys.join('", "') + '"'); - } +},{"../../Observable":378,"../../operator/materialize":607}],459:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var max_1 = require('../../operator/max'); +Observable_1.Observable.prototype.max = max_1.max; - var unexpectedKeys = Object.keys(inputState).filter(function (key) { - return !reducers.hasOwnProperty(key); - }); +},{"../../Observable":378,"../../operator/max":608}],460:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var merge_1 = require('../../operator/merge'); +Observable_1.Observable.prototype.merge = merge_1.merge; - if (unexpectedKeys.length > 0) { - return 'Unexpected ' + (unexpectedKeys.length > 1 ? 'keys' : 'key') + ' ' + ('"' + unexpectedKeys.join('", "') + '" found in ' + argumentName + '. ') + 'Expected to find one of the known reducer keys instead: ' + ('"' + reducerKeys.join('", "') + '". Unexpected keys will be ignored.'); - } -} +},{"../../Observable":378,"../../operator/merge":609}],461:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var mergeAll_1 = require('../../operator/mergeAll'); +Observable_1.Observable.prototype.mergeAll = mergeAll_1.mergeAll; -function assertReducerSanity(reducers) { - Object.keys(reducers).forEach(function (key) { - var reducer = reducers[key]; - var initialState = reducer(undefined, { type: _createStore.ActionTypes.INIT }); +},{"../../Observable":378,"../../operator/mergeAll":610}],462:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var mergeMap_1 = require('../../operator/mergeMap'); +Observable_1.Observable.prototype.mergeMap = mergeMap_1.mergeMap; +Observable_1.Observable.prototype.flatMap = mergeMap_1.mergeMap; - if (typeof initialState === 'undefined') { - throw new Error('Reducer "' + key + '" returned undefined during initialization. ' + 'If the state passed to the reducer is undefined, you must ' + 'explicitly return the initial state. The initial state may ' + 'not be undefined.'); - } +},{"../../Observable":378,"../../operator/mergeMap":611}],463:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var mergeMapTo_1 = require('../../operator/mergeMapTo'); +Observable_1.Observable.prototype.flatMapTo = mergeMapTo_1.mergeMapTo; +Observable_1.Observable.prototype.mergeMapTo = mergeMapTo_1.mergeMapTo; - var type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math.random().toString(36).substring(7).split('').join('.'); - if (typeof reducer(undefined, { type: type }) === 'undefined') { - throw new Error('Reducer "' + key + '" returned undefined when probed with a random type. ' + ('Don\'t try to handle ' + _createStore.ActionTypes.INIT + ' or other actions in "redux/*" ') + 'namespace. They are considered private. Instead, you must return the ' + 'current state for any unknown actions, unless it is undefined, ' + 'in which case you must return the initial state, regardless of the ' + 'action type. The initial state may not be undefined.'); - } - }); -} +},{"../../Observable":378,"../../operator/mergeMapTo":612}],464:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var mergeScan_1 = require('../../operator/mergeScan'); +Observable_1.Observable.prototype.mergeScan = mergeScan_1.mergeScan; -/** - * Turns an object whose values are different reducer functions, into a single - * reducer function. It will call every child reducer, and gather their results - * into a single state object, whose keys correspond to the keys of the passed - * reducer functions. - * - * @param {Object} reducers An object whose values correspond to different - * reducer functions that need to be combined into one. One handy way to obtain - * it is to use ES6 `import * as reducers` syntax. The reducers may never return - * undefined for any action. Instead, they should return their initial state - * if the state passed to them was undefined, and the current state for any - * unrecognized action. - * - * @returns {Function} A reducer function that invokes every reducer inside the - * passed object, and builds a state object with the same shape. - */ -function combineReducers(reducers) { - var reducerKeys = Object.keys(reducers); - var finalReducers = {}; - for (var i = 0; i < reducerKeys.length; i++) { - var key = reducerKeys[i]; - if (typeof reducers[key] === 'function') { - finalReducers[key] = reducers[key]; - } - } - var finalReducerKeys = Object.keys(finalReducers); +},{"../../Observable":378,"../../operator/mergeScan":613}],465:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var min_1 = require('../../operator/min'); +Observable_1.Observable.prototype.min = min_1.min; - var sanityError; - try { - assertReducerSanity(finalReducers); - } catch (e) { - sanityError = e; - } +},{"../../Observable":378,"../../operator/min":614}],466:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var multicast_1 = require('../../operator/multicast'); +Observable_1.Observable.prototype.multicast = multicast_1.multicast; - return function combination() { - var state = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - var action = arguments[1]; +},{"../../Observable":378,"../../operator/multicast":615}],467:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var observeOn_1 = require('../../operator/observeOn'); +Observable_1.Observable.prototype.observeOn = observeOn_1.observeOn; - if (sanityError) { - throw sanityError; - } +},{"../../Observable":378,"../../operator/observeOn":616}],468:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var onErrorResumeNext_1 = require('../../operator/onErrorResumeNext'); +Observable_1.Observable.prototype.onErrorResumeNext = onErrorResumeNext_1.onErrorResumeNext; - if (process.env.NODE_ENV !== 'production') { - var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action); - if (warningMessage) { - (0, _warning2["default"])(warningMessage); - } - } +},{"../../Observable":378,"../../operator/onErrorResumeNext":617}],469:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var pairwise_1 = require('../../operator/pairwise'); +Observable_1.Observable.prototype.pairwise = pairwise_1.pairwise; - var hasChanged = false; - var nextState = {}; - for (var i = 0; i < finalReducerKeys.length; i++) { - var key = finalReducerKeys[i]; - var reducer = finalReducers[key]; - var previousStateForKey = state[key]; - var nextStateForKey = reducer(previousStateForKey, action); - if (typeof nextStateForKey === 'undefined') { - var errorMessage = getUndefinedStateErrorMessage(key, action); - throw new Error(errorMessage); - } - nextState[key] = nextStateForKey; - hasChanged = hasChanged || nextStateForKey !== previousStateForKey; - } - return hasChanged ? nextState : state; - }; -} -}).call(this,require('_process')) -},{"./createStore":380,"./utils/warning":382,"_process":190,"lodash/isPlainObject":196}],379:[function(require,module,exports){ +},{"../../Observable":378,"../../operator/pairwise":618}],470:[function(require,module,exports){ "use strict"; +var Observable_1 = require('../../Observable'); +var partition_1 = require('../../operator/partition'); +Observable_1.Observable.prototype.partition = partition_1.partition; -exports.__esModule = true; -exports["default"] = compose; -/** - * Composes single-argument functions from right to left. The rightmost - * function can take multiple arguments as it provides the signature for - * the resulting composite function. - * - * @param {...Function} funcs The functions to compose. - * @returns {Function} A function obtained by composing the argument functions - * from right to left. For example, compose(f, g, h) is identical to doing - * (...args) => f(g(h(...args))). - */ +},{"../../Observable":378,"../../operator/partition":619}],471:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var pluck_1 = require('../../operator/pluck'); +Observable_1.Observable.prototype.pluck = pluck_1.pluck; -function compose() { - for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) { - funcs[_key] = arguments[_key]; - } +},{"../../Observable":378,"../../operator/pluck":620}],472:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var publish_1 = require('../../operator/publish'); +Observable_1.Observable.prototype.publish = publish_1.publish; - if (funcs.length === 0) { - return function (arg) { - return arg; - }; - } else { - var _ret = function () { - var last = funcs[funcs.length - 1]; - var rest = funcs.slice(0, -1); - return { - v: function v() { - return rest.reduceRight(function (composed, f) { - return f(composed); - }, last.apply(undefined, arguments)); - } - }; - }(); +},{"../../Observable":378,"../../operator/publish":621}],473:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var publishBehavior_1 = require('../../operator/publishBehavior'); +Observable_1.Observable.prototype.publishBehavior = publishBehavior_1.publishBehavior; - if (typeof _ret === "object") return _ret.v; - } -} -},{}],380:[function(require,module,exports){ -'use strict'; +},{"../../Observable":378,"../../operator/publishBehavior":622}],474:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var publishLast_1 = require('../../operator/publishLast'); +Observable_1.Observable.prototype.publishLast = publishLast_1.publishLast; -exports.__esModule = true; -exports.ActionTypes = undefined; -exports["default"] = createStore; +},{"../../Observable":378,"../../operator/publishLast":623}],475:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var publishReplay_1 = require('../../operator/publishReplay'); +Observable_1.Observable.prototype.publishReplay = publishReplay_1.publishReplay; -var _isPlainObject = require('lodash/isPlainObject'); +},{"../../Observable":378,"../../operator/publishReplay":624}],476:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var race_1 = require('../../operator/race'); +Observable_1.Observable.prototype.race = race_1.race; -var _isPlainObject2 = _interopRequireDefault(_isPlainObject); +},{"../../Observable":378,"../../operator/race":625}],477:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var reduce_1 = require('../../operator/reduce'); +Observable_1.Observable.prototype.reduce = reduce_1.reduce; -var _symbolObservable = require('symbol-observable'); +},{"../../Observable":378,"../../operator/reduce":626}],478:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var repeat_1 = require('../../operator/repeat'); +Observable_1.Observable.prototype.repeat = repeat_1.repeat; -var _symbolObservable2 = _interopRequireDefault(_symbolObservable); +},{"../../Observable":378,"../../operator/repeat":627}],479:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var retry_1 = require('../../operator/retry'); +Observable_1.Observable.prototype.retry = retry_1.retry; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } +},{"../../Observable":378,"../../operator/retry":628}],480:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var retryWhen_1 = require('../../operator/retryWhen'); +Observable_1.Observable.prototype.retryWhen = retryWhen_1.retryWhen; -/** - * These are private action types reserved by Redux. - * For any unknown actions, you must return the current state. - * If the current state is undefined, you must return the initial state. - * Do not reference these action types directly in your code. - */ -var ActionTypes = exports.ActionTypes = { - INIT: '@@redux/INIT' -}; +},{"../../Observable":378,"../../operator/retryWhen":629}],481:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var sample_1 = require('../../operator/sample'); +Observable_1.Observable.prototype.sample = sample_1.sample; -/** - * Creates a Redux store that holds the state tree. - * The only way to change the data in the store is to call `dispatch()` on it. - * - * There should only be a single store in your app. To specify how different - * parts of the state tree respond to actions, you may combine several reducers - * into a single reducer function by using `combineReducers`. - * - * @param {Function} reducer A function that returns the next state tree, given - * the current state tree and the action to handle. - * - * @param {any} [initialState] The initial state. You may optionally specify it - * to hydrate the state from the server in universal apps, or to restore a - * previously serialized user session. - * If you use `combineReducers` to produce the root reducer function, this must be - * an object with the same shape as `combineReducers` keys. - * - * @param {Function} enhancer The store enhancer. You may optionally specify it - * to enhance the store with third-party capabilities such as middleware, - * time travel, persistence, etc. The only store enhancer that ships with Redux - * is `applyMiddleware()`. - * - * @returns {Store} A Redux store that lets you read the state, dispatch actions - * and subscribe to changes. - */ -function createStore(reducer, initialState, enhancer) { - var _ref2; +},{"../../Observable":378,"../../operator/sample":630}],482:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var sampleTime_1 = require('../../operator/sampleTime'); +Observable_1.Observable.prototype.sampleTime = sampleTime_1.sampleTime; - if (typeof initialState === 'function' && typeof enhancer === 'undefined') { - enhancer = initialState; - initialState = undefined; - } +},{"../../Observable":378,"../../operator/sampleTime":631}],483:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var scan_1 = require('../../operator/scan'); +Observable_1.Observable.prototype.scan = scan_1.scan; - if (typeof enhancer !== 'undefined') { - if (typeof enhancer !== 'function') { - throw new Error('Expected the enhancer to be a function.'); - } +},{"../../Observable":378,"../../operator/scan":632}],484:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var share_1 = require('../../operator/share'); +Observable_1.Observable.prototype.share = share_1.share; - return enhancer(createStore)(reducer, initialState); - } +},{"../../Observable":378,"../../operator/share":633}],485:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var single_1 = require('../../operator/single'); +Observable_1.Observable.prototype.single = single_1.single; - if (typeof reducer !== 'function') { - throw new Error('Expected the reducer to be a function.'); - } +},{"../../Observable":378,"../../operator/single":634}],486:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var skip_1 = require('../../operator/skip'); +Observable_1.Observable.prototype.skip = skip_1.skip; - var currentReducer = reducer; - var currentState = initialState; - var currentListeners = []; - var nextListeners = currentListeners; - var isDispatching = false; +},{"../../Observable":378,"../../operator/skip":635}],487:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var skipUntil_1 = require('../../operator/skipUntil'); +Observable_1.Observable.prototype.skipUntil = skipUntil_1.skipUntil; - function ensureCanMutateNextListeners() { - if (nextListeners === currentListeners) { - nextListeners = currentListeners.slice(); - } - } +},{"../../Observable":378,"../../operator/skipUntil":636}],488:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var skipWhile_1 = require('../../operator/skipWhile'); +Observable_1.Observable.prototype.skipWhile = skipWhile_1.skipWhile; - /** - * Reads the state tree managed by the store. - * - * @returns {any} The current state tree of your application. - */ - function getState() { - return currentState; - } +},{"../../Observable":378,"../../operator/skipWhile":637}],489:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var startWith_1 = require('../../operator/startWith'); +Observable_1.Observable.prototype.startWith = startWith_1.startWith; - /** - * Adds a change listener. It will be called any time an action is dispatched, - * and some part of the state tree may potentially have changed. You may then - * call `getState()` to read the current state tree inside the callback. - * - * You may call `dispatch()` from a change listener, with the following - * caveats: - * - * 1. The subscriptions are snapshotted just before every `dispatch()` call. - * If you subscribe or unsubscribe while the listeners are being invoked, this - * will not have any effect on the `dispatch()` that is currently in progress. - * However, the next `dispatch()` call, whether nested or not, will use a more - * recent snapshot of the subscription list. - * - * 2. The listener should not expect to see all state changes, as the state - * might have been updated multiple times during a nested `dispatch()` before - * the listener is called. It is, however, guaranteed that all subscribers - * registered before the `dispatch()` started will be called with the latest - * state by the time it exits. - * - * @param {Function} listener A callback to be invoked on every dispatch. - * @returns {Function} A function to remove this change listener. - */ - function subscribe(listener) { - if (typeof listener !== 'function') { - throw new Error('Expected listener to be a function.'); - } +},{"../../Observable":378,"../../operator/startWith":638}],490:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var subscribeOn_1 = require('../../operator/subscribeOn'); +Observable_1.Observable.prototype.subscribeOn = subscribeOn_1.subscribeOn; - var isSubscribed = true; +},{"../../Observable":378,"../../operator/subscribeOn":639}],491:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var switch_1 = require('../../operator/switch'); +Observable_1.Observable.prototype.switch = switch_1._switch; - ensureCanMutateNextListeners(); - nextListeners.push(listener); +},{"../../Observable":378,"../../operator/switch":640}],492:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var switchMap_1 = require('../../operator/switchMap'); +Observable_1.Observable.prototype.switchMap = switchMap_1.switchMap; - return function unsubscribe() { - if (!isSubscribed) { - return; - } +},{"../../Observable":378,"../../operator/switchMap":641}],493:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var switchMapTo_1 = require('../../operator/switchMapTo'); +Observable_1.Observable.prototype.switchMapTo = switchMapTo_1.switchMapTo; - isSubscribed = false; +},{"../../Observable":378,"../../operator/switchMapTo":642}],494:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var take_1 = require('../../operator/take'); +Observable_1.Observable.prototype.take = take_1.take; - ensureCanMutateNextListeners(); - var index = nextListeners.indexOf(listener); - nextListeners.splice(index, 1); - }; - } +},{"../../Observable":378,"../../operator/take":643}],495:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var takeLast_1 = require('../../operator/takeLast'); +Observable_1.Observable.prototype.takeLast = takeLast_1.takeLast; - /** - * Dispatches an action. It is the only way to trigger a state change. - * - * The `reducer` function, used to create the store, will be called with the - * current state tree and the given `action`. Its return value will - * be considered the **next** state of the tree, and the change listeners - * will be notified. - * - * The base implementation only supports plain object actions. If you want to - * dispatch a Promise, an Observable, a thunk, or something else, you need to - * wrap your store creating function into the corresponding middleware. For - * example, see the documentation for the `redux-thunk` package. Even the - * middleware will eventually dispatch plain object actions using this method. - * - * @param {Object} action A plain object representing “what changed”. It is - * a good idea to keep actions serializable so you can record and replay user - * sessions, or use the time travelling `redux-devtools`. An action must have - * a `type` property which may not be `undefined`. It is a good idea to use - * string constants for action types. - * - * @returns {Object} For convenience, the same action object you dispatched. - * - * Note that, if you use a custom middleware, it may wrap `dispatch()` to - * return something else (for example, a Promise you can await). - */ - function dispatch(action) { - if (!(0, _isPlainObject2["default"])(action)) { - throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); - } +},{"../../Observable":378,"../../operator/takeLast":644}],496:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var takeUntil_1 = require('../../operator/takeUntil'); +Observable_1.Observable.prototype.takeUntil = takeUntil_1.takeUntil; - if (typeof action.type === 'undefined') { - throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?'); - } +},{"../../Observable":378,"../../operator/takeUntil":645}],497:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var takeWhile_1 = require('../../operator/takeWhile'); +Observable_1.Observable.prototype.takeWhile = takeWhile_1.takeWhile; - if (isDispatching) { - throw new Error('Reducers may not dispatch actions.'); +},{"../../Observable":378,"../../operator/takeWhile":646}],498:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var throttle_1 = require('../../operator/throttle'); +Observable_1.Observable.prototype.throttle = throttle_1.throttle; + +},{"../../Observable":378,"../../operator/throttle":647}],499:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var throttleTime_1 = require('../../operator/throttleTime'); +Observable_1.Observable.prototype.throttleTime = throttleTime_1.throttleTime; + +},{"../../Observable":378,"../../operator/throttleTime":648}],500:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var timeInterval_1 = require('../../operator/timeInterval'); +Observable_1.Observable.prototype.timeInterval = timeInterval_1.timeInterval; + +},{"../../Observable":378,"../../operator/timeInterval":649}],501:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var timeout_1 = require('../../operator/timeout'); +Observable_1.Observable.prototype.timeout = timeout_1.timeout; + +},{"../../Observable":378,"../../operator/timeout":650}],502:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var timeoutWith_1 = require('../../operator/timeoutWith'); +Observable_1.Observable.prototype.timeoutWith = timeoutWith_1.timeoutWith; + +},{"../../Observable":378,"../../operator/timeoutWith":651}],503:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var timestamp_1 = require('../../operator/timestamp'); +Observable_1.Observable.prototype.timestamp = timestamp_1.timestamp; + +},{"../../Observable":378,"../../operator/timestamp":652}],504:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var toArray_1 = require('../../operator/toArray'); +Observable_1.Observable.prototype.toArray = toArray_1.toArray; + +},{"../../Observable":378,"../../operator/toArray":653}],505:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var toPromise_1 = require('../../operator/toPromise'); +Observable_1.Observable.prototype.toPromise = toPromise_1.toPromise; + +},{"../../Observable":378,"../../operator/toPromise":654}],506:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var window_1 = require('../../operator/window'); +Observable_1.Observable.prototype.window = window_1.window; + +},{"../../Observable":378,"../../operator/window":655}],507:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var windowCount_1 = require('../../operator/windowCount'); +Observable_1.Observable.prototype.windowCount = windowCount_1.windowCount; + +},{"../../Observable":378,"../../operator/windowCount":656}],508:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var windowTime_1 = require('../../operator/windowTime'); +Observable_1.Observable.prototype.windowTime = windowTime_1.windowTime; + +},{"../../Observable":378,"../../operator/windowTime":657}],509:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var windowToggle_1 = require('../../operator/windowToggle'); +Observable_1.Observable.prototype.windowToggle = windowToggle_1.windowToggle; + +},{"../../Observable":378,"../../operator/windowToggle":658}],510:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var windowWhen_1 = require('../../operator/windowWhen'); +Observable_1.Observable.prototype.windowWhen = windowWhen_1.windowWhen; + +},{"../../Observable":378,"../../operator/windowWhen":659}],511:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var withLatestFrom_1 = require('../../operator/withLatestFrom'); +Observable_1.Observable.prototype.withLatestFrom = withLatestFrom_1.withLatestFrom; + +},{"../../Observable":378,"../../operator/withLatestFrom":660}],512:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var zip_1 = require('../../operator/zip'); +Observable_1.Observable.prototype.zip = zip_1.zipProto; + +},{"../../Observable":378,"../../operator/zip":661}],513:[function(require,module,exports){ +"use strict"; +var Observable_1 = require('../../Observable'); +var zipAll_1 = require('../../operator/zipAll'); +Observable_1.Observable.prototype.zipAll = zipAll_1.zipAll; + +},{"../../Observable":378,"../../operator/zipAll":662}],514:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var ScalarObservable_1 = require('./ScalarObservable'); +var EmptyObservable_1 = require('./EmptyObservable'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var ArrayLikeObservable = (function (_super) { + __extends(ArrayLikeObservable, _super); + function ArrayLikeObservable(arrayLike, mapFn, thisArg, scheduler) { + _super.call(this); + this.arrayLike = arrayLike; + this.scheduler = scheduler; + if (!mapFn && !scheduler && arrayLike.length === 1) { + this._isScalar = true; + this.value = arrayLike[0]; + } + if (mapFn) { + this.mapFn = mapFn.bind(thisArg); + } + } + ArrayLikeObservable.create = function (arrayLike, mapFn, thisArg, scheduler) { + var length = arrayLike.length; + if (length === 0) { + return new EmptyObservable_1.EmptyObservable(); + } + else if (length === 1 && !mapFn) { + return new ScalarObservable_1.ScalarObservable(arrayLike[0], scheduler); + } + else { + return new ArrayLikeObservable(arrayLike, mapFn, thisArg, scheduler); + } + }; + ArrayLikeObservable.dispatch = function (state) { + var arrayLike = state.arrayLike, index = state.index, length = state.length, mapFn = state.mapFn, subscriber = state.subscriber; + if (subscriber.isUnsubscribed) { + return; + } + if (index >= length) { + subscriber.complete(); + return; + } + var result = mapFn ? mapFn(arrayLike[index], index) : arrayLike[index]; + subscriber.next(result); + state.index = index + 1; + this.schedule(state); + }; + ArrayLikeObservable.prototype._subscribe = function (subscriber) { + var index = 0; + var _a = this, arrayLike = _a.arrayLike, mapFn = _a.mapFn, scheduler = _a.scheduler; + var length = arrayLike.length; + if (scheduler) { + return scheduler.schedule(ArrayLikeObservable.dispatch, 0, { + arrayLike: arrayLike, index: index, length: length, mapFn: mapFn, subscriber: subscriber + }); + } + else { + for (var i = 0; i < length && !subscriber.isUnsubscribed; i++) { + var result = mapFn ? mapFn(arrayLike[i], i) : arrayLike[i]; + subscriber.next(result); + } + subscriber.complete(); + } + }; + return ArrayLikeObservable; +}(Observable_1.Observable)); +exports.ArrayLikeObservable = ArrayLikeObservable; + +},{"../Observable":378,"./EmptyObservable":520,"./ScalarObservable":534}],515:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var ScalarObservable_1 = require('./ScalarObservable'); +var EmptyObservable_1 = require('./EmptyObservable'); +var isScheduler_1 = require('../util/isScheduler'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var ArrayObservable = (function (_super) { + __extends(ArrayObservable, _super); + function ArrayObservable(array, scheduler) { + _super.call(this); + this.array = array; + this.scheduler = scheduler; + if (!scheduler && array.length === 1) { + this._isScalar = true; + this.value = array[0]; + } + } + ArrayObservable.create = function (array, scheduler) { + return new ArrayObservable(array, scheduler); + }; + /** + * Creates an Observable that emits some values you specify as arguments, + * immediately one after the other, and then emits a complete notification. + * + * Emits the arguments you provide, then completes. + * + * + * + * + * This static operator is useful for creating a simple Observable that only + * emits the arguments given, and the complete notification thereafter. It can + * be used for composing with other Observables, such as with {@link concat}. + * By default, it uses a `null` Scheduler, which means the `next` + * notifications are sent synchronously, although with a different Scheduler + * it is possible to determine when those notifications will be delivered. + * + * @example Emit 10, 20, 30, then 'a', 'b', 'c', then start ticking every second. + * var numbers = Rx.Observable.of(10, 20, 30); + * var letters = Rx.Observable.of('a', 'b', 'c'); + * var interval = Rx.Observable.interval(1000); + * var result = numbers.concat(letters).concat(interval); + * result.subscribe(x => console.log(x)); + * + * @see {@link create} + * @see {@link empty} + * @see {@link never} + * @see {@link throw} + * + * @param {...T} values Arguments that represent `next` values to be emitted. + * @param {Scheduler} [scheduler] A {@link Scheduler} to use for scheduling + * the emissions of the `next` notifications. + * @return {Observable} An Observable that emits each given input value. + * @static true + * @name of + * @owner Observable + */ + ArrayObservable.of = function () { + var array = []; + for (var _i = 0; _i < arguments.length; _i++) { + array[_i - 0] = arguments[_i]; + } + var scheduler = array[array.length - 1]; + if (isScheduler_1.isScheduler(scheduler)) { + array.pop(); + } + else { + scheduler = null; + } + var len = array.length; + if (len > 1) { + return new ArrayObservable(array, scheduler); + } + else if (len === 1) { + return new ScalarObservable_1.ScalarObservable(array[0], scheduler); + } + else { + return new EmptyObservable_1.EmptyObservable(scheduler); + } + }; + ArrayObservable.dispatch = function (state) { + var array = state.array, index = state.index, count = state.count, subscriber = state.subscriber; + if (index >= count) { + subscriber.complete(); + return; + } + subscriber.next(array[index]); + if (subscriber.isUnsubscribed) { + return; + } + state.index = index + 1; + this.schedule(state); + }; + ArrayObservable.prototype._subscribe = function (subscriber) { + var index = 0; + var array = this.array; + var count = array.length; + var scheduler = this.scheduler; + if (scheduler) { + return scheduler.schedule(ArrayObservable.dispatch, 0, { + array: array, index: index, count: count, subscriber: subscriber + }); + } + else { + for (var i = 0; i < count && !subscriber.isUnsubscribed; i++) { + subscriber.next(array[i]); + } + subscriber.complete(); + } + }; + return ArrayObservable; +}(Observable_1.Observable)); +exports.ArrayObservable = ArrayObservable; + +},{"../Observable":378,"../util/isScheduler":701,"./EmptyObservable":520,"./ScalarObservable":534}],516:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var AsyncSubject_1 = require('../AsyncSubject'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var BoundCallbackObservable = (function (_super) { + __extends(BoundCallbackObservable, _super); + function BoundCallbackObservable(callbackFunc, selector, args, scheduler) { + _super.call(this); + this.callbackFunc = callbackFunc; + this.selector = selector; + this.args = args; + this.scheduler = scheduler; + } + /* tslint:enable:max-line-length */ + /** + * Converts a callback API to a function that returns an Observable. + * + * Give it a function `f` of type `f(x, callback)` and + * it will return a function `g` that when called as `g(x)` will output an + * Observable. + * + * `bindCallback` is not an operator because its input and output are not + * Observables. The input is a function `func` with some parameters, but the + * last parameter must be a callback function that `func` calls when it is + * done. The output of `bindCallback` is a function that takes the same + * parameters as `func`, except the last one (the callback). When the output + * function is called with arguments, it will return an Observable where the + * results will be delivered to. + * + * @example Convert jQuery's getJSON to an Observable API + * // Suppose we have jQuery.getJSON('/my/url', callback) + * var getJSONAsObservable = Rx.Observable.bindCallback(jQuery.getJSON); + * var result = getJSONAsObservable('/my/url'); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @see {@link bindNodeCallback} + * @see {@link from} + * @see {@link fromPromise} + * + * @param {function} func Function with a callback as the last parameter. + * @param {function} selector A function which takes the arguments from the + * callback and maps those a value to emit on the output Observable. + * @param {Scheduler} [scheduler] The scheduler on which to schedule the + * callbacks. + * @return {function(...params: *): Observable} A function which returns the + * Observable that delivers the same values the callback would deliver. + * @static true + * @name bindCallback + * @owner Observable + */ + BoundCallbackObservable.create = function (func, selector, scheduler) { + if (selector === void 0) { selector = undefined; } + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + return new BoundCallbackObservable(func, selector, args, scheduler); + }; + }; + BoundCallbackObservable.prototype._subscribe = function (subscriber) { + var callbackFunc = this.callbackFunc; + var args = this.args; + var scheduler = this.scheduler; + var subject = this.subject; + if (!scheduler) { + if (!subject) { + subject = this.subject = new AsyncSubject_1.AsyncSubject(); + var handler = function handlerFn() { + var innerArgs = []; + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i - 0] = arguments[_i]; + } + var source = handlerFn.source; + var selector = source.selector, subject = source.subject; + if (selector) { + var result_1 = tryCatch_1.tryCatch(selector).apply(this, innerArgs); + if (result_1 === errorObject_1.errorObject) { + subject.error(errorObject_1.errorObject.e); + } + else { + subject.next(result_1); + subject.complete(); + } + } + else { + subject.next(innerArgs.length === 1 ? innerArgs[0] : innerArgs); + subject.complete(); + } + }; + // use named function instance to avoid closure. + handler.source = this; + var result = tryCatch_1.tryCatch(callbackFunc).apply(this, args.concat(handler)); + if (result === errorObject_1.errorObject) { + subject.error(errorObject_1.errorObject.e); + } + } + return subject.subscribe(subscriber); + } + else { + return scheduler.schedule(dispatch, 0, { source: this, subscriber: subscriber }); + } + }; + return BoundCallbackObservable; +}(Observable_1.Observable)); +exports.BoundCallbackObservable = BoundCallbackObservable; +function dispatch(state) { + var self = this; + var source = state.source, subscriber = state.subscriber; + var callbackFunc = source.callbackFunc, args = source.args, scheduler = source.scheduler; + var subject = source.subject; + if (!subject) { + subject = source.subject = new AsyncSubject_1.AsyncSubject(); + var handler = function handlerFn() { + var innerArgs = []; + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i - 0] = arguments[_i]; + } + var source = handlerFn.source; + var selector = source.selector, subject = source.subject; + if (selector) { + var result_2 = tryCatch_1.tryCatch(selector).apply(this, innerArgs); + if (result_2 === errorObject_1.errorObject) { + self.add(scheduler.schedule(dispatchError, 0, { err: errorObject_1.errorObject.e, subject: subject })); + } + else { + self.add(scheduler.schedule(dispatchNext, 0, { value: result_2, subject: subject })); + } + } + else { + var value = innerArgs.length === 1 ? innerArgs[0] : innerArgs; + self.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject })); + } + }; + // use named function to pass values in without closure + handler.source = source; + var result = tryCatch_1.tryCatch(callbackFunc).apply(this, args.concat(handler)); + if (result === errorObject_1.errorObject) { + subject.error(errorObject_1.errorObject.e); + } + } + self.add(subject.subscribe(subscriber)); +} +function dispatchNext(arg) { + var value = arg.value, subject = arg.subject; + subject.next(value); + subject.complete(); +} +function dispatchError(arg) { + var err = arg.err, subject = arg.subject; + subject.error(err); +} + +},{"../AsyncSubject":374,"../Observable":378,"../util/errorObject":694,"../util/tryCatch":708}],517:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var AsyncSubject_1 = require('../AsyncSubject'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var BoundNodeCallbackObservable = (function (_super) { + __extends(BoundNodeCallbackObservable, _super); + function BoundNodeCallbackObservable(callbackFunc, selector, args, scheduler) { + _super.call(this); + this.callbackFunc = callbackFunc; + this.selector = selector; + this.args = args; + this.scheduler = scheduler; + } + /* tslint:enable:max-line-length */ + /** + * Converts a Node.js-style callback API to a function that returns an + * Observable. + * + * It's just like {@link bindCallback}, but the + * callback is expected to be of type `callback(error, result)`. + * + * `bindNodeCallback` is not an operator because its input and output are not + * Observables. The input is a function `func` with some parameters, but the + * last parameter must be a callback function that `func` calls when it is + * done. The callback function is expected to follow Node.js conventions, + * where the first argument to the callback is an error, while remaining + * arguments are the callback result. The output of `bindNodeCallback` is a + * function that takes the same parameters as `func`, except the last one (the + * callback). When the output function is called with arguments, it will + * return an Observable where the results will be delivered to. + * + * @example Read a file from the filesystem and get the data as an Observable + * import * as fs from 'fs'; + * var readFileAsObservable = Rx.Observable.bindNodeCallback(fs.readFile); + * var result = readFileAsObservable('./roadNames.txt', 'utf8'); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @see {@link bindCallback} + * @see {@link from} + * @see {@link fromPromise} + * + * @param {function} func Function with a callback as the last parameter. + * @param {function} selector A function which takes the arguments from the + * callback and maps those a value to emit on the output Observable. + * @param {Scheduler} [scheduler] The scheduler on which to schedule the + * callbacks. + * @return {function(...params: *): Observable} A function which returns the + * Observable that delivers the same values the Node.js callback would + * deliver. + * @static true + * @name bindNodeCallback + * @owner Observable + */ + BoundNodeCallbackObservable.create = function (func, selector, scheduler) { + if (selector === void 0) { selector = undefined; } + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + return new BoundNodeCallbackObservable(func, selector, args, scheduler); + }; + }; + BoundNodeCallbackObservable.prototype._subscribe = function (subscriber) { + var callbackFunc = this.callbackFunc; + var args = this.args; + var scheduler = this.scheduler; + var subject = this.subject; + if (!scheduler) { + if (!subject) { + subject = this.subject = new AsyncSubject_1.AsyncSubject(); + var handler = function handlerFn() { + var innerArgs = []; + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i - 0] = arguments[_i]; + } + var source = handlerFn.source; + var selector = source.selector, subject = source.subject; + var err = innerArgs.shift(); + if (err) { + subject.error(err); + } + else if (selector) { + var result_1 = tryCatch_1.tryCatch(selector).apply(this, innerArgs); + if (result_1 === errorObject_1.errorObject) { + subject.error(errorObject_1.errorObject.e); + } + else { + subject.next(result_1); + subject.complete(); + } + } + else { + subject.next(innerArgs.length === 1 ? innerArgs[0] : innerArgs); + subject.complete(); + } + }; + // use named function instance to avoid closure. + handler.source = this; + var result = tryCatch_1.tryCatch(callbackFunc).apply(this, args.concat(handler)); + if (result === errorObject_1.errorObject) { + subject.error(errorObject_1.errorObject.e); + } + } + return subject.subscribe(subscriber); + } + else { + return scheduler.schedule(dispatch, 0, { source: this, subscriber: subscriber }); + } + }; + return BoundNodeCallbackObservable; +}(Observable_1.Observable)); +exports.BoundNodeCallbackObservable = BoundNodeCallbackObservable; +function dispatch(state) { + var self = this; + var source = state.source, subscriber = state.subscriber; + var callbackFunc = source.callbackFunc, args = source.args, scheduler = source.scheduler; + var subject = source.subject; + if (!subject) { + subject = source.subject = new AsyncSubject_1.AsyncSubject(); + var handler = function handlerFn() { + var innerArgs = []; + for (var _i = 0; _i < arguments.length; _i++) { + innerArgs[_i - 0] = arguments[_i]; + } + var source = handlerFn.source; + var selector = source.selector, subject = source.subject; + var err = innerArgs.shift(); + if (err) { + subject.error(err); + } + else if (selector) { + var result_2 = tryCatch_1.tryCatch(selector).apply(this, innerArgs); + if (result_2 === errorObject_1.errorObject) { + self.add(scheduler.schedule(dispatchError, 0, { err: errorObject_1.errorObject.e, subject: subject })); + } + else { + self.add(scheduler.schedule(dispatchNext, 0, { value: result_2, subject: subject })); + } + } + else { + var value = innerArgs.length === 1 ? innerArgs[0] : innerArgs; + self.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject })); + } + }; + // use named function to pass values in without closure + handler.source = source; + var result = tryCatch_1.tryCatch(callbackFunc).apply(this, args.concat(handler)); + if (result === errorObject_1.errorObject) { + subject.error(errorObject_1.errorObject.e); + } + } + self.add(subject.subscribe(subscriber)); +} +function dispatchNext(arg) { + var value = arg.value, subject = arg.subject; + subject.next(value); + subject.complete(); +} +function dispatchError(arg) { + var err = arg.err, subject = arg.subject; + subject.error(err); +} + +},{"../AsyncSubject":374,"../Observable":378,"../util/errorObject":694,"../util/tryCatch":708}],518:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../Subject'); +var Observable_1 = require('../Observable'); +var Subscriber_1 = require('../Subscriber'); +var Subscription_1 = require('../Subscription'); +/** + * @class ConnectableObservable + */ +var ConnectableObservable = (function (_super) { + __extends(ConnectableObservable, _super); + function ConnectableObservable(source, subjectFactory) { + _super.call(this); + this.source = source; + this.subjectFactory = subjectFactory; + this._refCount = 0; + } + ConnectableObservable.prototype._subscribe = function (subscriber) { + return this.getSubject().subscribe(subscriber); + }; + ConnectableObservable.prototype.getSubject = function () { + var subject = this._subject; + if (!subject || subject.isStopped) { + this._subject = this.subjectFactory(); + } + return this._subject; + }; + ConnectableObservable.prototype.connect = function () { + var connection = this._connection; + if (!connection) { + connection = this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this)); + if (connection.isUnsubscribed) { + this._connection = null; + connection = Subscription_1.Subscription.EMPTY; + } + else { + this._connection = connection; + } + } + return connection; + }; + ConnectableObservable.prototype.refCount = function () { + return this.lift(new RefCountOperator(this)); + }; + return ConnectableObservable; +}(Observable_1.Observable)); +exports.ConnectableObservable = ConnectableObservable; +var ConnectableSubscriber = (function (_super) { + __extends(ConnectableSubscriber, _super); + function ConnectableSubscriber(destination, connectable) { + _super.call(this, destination); + this.connectable = connectable; + } + ConnectableSubscriber.prototype._error = function (err) { + this._unsubscribe(); + _super.prototype._error.call(this, err); + }; + ConnectableSubscriber.prototype._complete = function () { + this._unsubscribe(); + _super.prototype._complete.call(this); + }; + ConnectableSubscriber.prototype._unsubscribe = function () { + var connectable = this.connectable; + if (connectable) { + this.connectable = null; + connectable._refCount = 0; + connectable._subject = null; + connectable._connection = null; + } + }; + return ConnectableSubscriber; +}(Subject_1.SubjectSubscriber)); +var RefCountOperator = (function () { + function RefCountOperator(connectable) { + this.connectable = connectable; + } + RefCountOperator.prototype.call = function (subscriber, source) { + var connectable = this.connectable; + connectable._refCount++; + var refCounter = new RefCountSubscriber(subscriber, connectable); + var subscription = source._subscribe(refCounter); + if (!refCounter.isUnsubscribed) { + refCounter.connection = connectable.connect(); + } + return subscription; + }; + return RefCountOperator; +}()); +var RefCountSubscriber = (function (_super) { + __extends(RefCountSubscriber, _super); + function RefCountSubscriber(destination, connectable) { + _super.call(this, destination); + this.connectable = connectable; + } + RefCountSubscriber.prototype._unsubscribe = function () { + var connectable = this.connectable; + if (!connectable) { + this.connection = null; + return; + } + this.connectable = null; + var refCount = connectable._refCount; + if (refCount <= 0) { + this.connection = null; + return; + } + connectable._refCount = refCount - 1; + if (refCount > 1) { + this.connection = null; + return; + } + var connection = this.connection; + if (connection) { + this.connection = null; + connection.unsubscribe(); + } + }; + return RefCountSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Observable":378,"../Subject":384,"../Subscriber":386,"../Subscription":387}],519:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var DeferObservable = (function (_super) { + __extends(DeferObservable, _super); + function DeferObservable(observableFactory) { + _super.call(this); + this.observableFactory = observableFactory; + } + /** + * Creates an Observable that, on subscribe, calls an Observable factory to + * make an Observable for each new Observer. + * + * Creates the Observable lazily, that is, only when it + * is subscribed. + * + * + * + * + * `defer` allows you to create the Observable only when the Observer + * subscribes, and create a fresh Observable for each Observer. It waits until + * an Observer subscribes to it, and then it generates an Observable, + * typically with an Observable factory function. It does this afresh for each + * subscriber, so although each subscriber may think it is subscribing to the + * same Observable, in fact each subscriber gets its own individual + * Observable. + * + * @example Subscribe to either an Observable of clicks or an Observable of interval, at random + * var clicksOrInterval = Rx.Observable.defer(function () { + * if (Math.random() > 0.5) { + * return Rx.Observable.fromEvent(document, 'click'); + * } else { + * return Rx.Observable.interval(1000); + * } + * }); + * clicksOrInterval.subscribe(x => console.log(x)); + * + * @see {@link create} + * + * @param {function(): Observable|Promise} observableFactory The Observable + * factory function to invoke for each Observer that subscribes to the output + * Observable. May also return a Promise, which will be converted on the fly + * to an Observable. + * @return {Observable} An Observable whose Observers' subscriptions trigger + * an invocation of the given Observable factory function. + * @static true + * @name defer + * @owner Observable + */ + DeferObservable.create = function (observableFactory) { + return new DeferObservable(observableFactory); + }; + DeferObservable.prototype._subscribe = function (subscriber) { + return new DeferSubscriber(subscriber, this.observableFactory); + }; + return DeferObservable; +}(Observable_1.Observable)); +exports.DeferObservable = DeferObservable; +var DeferSubscriber = (function (_super) { + __extends(DeferSubscriber, _super); + function DeferSubscriber(destination, factory) { + _super.call(this, destination); + this.factory = factory; + this.tryDefer(); + } + DeferSubscriber.prototype.tryDefer = function () { + try { + this._callFactory(); + } + catch (err) { + this._error(err); + } + }; + DeferSubscriber.prototype._callFactory = function () { + var result = this.factory(); + if (result) { + this.add(subscribeToResult_1.subscribeToResult(this, result)); + } + }; + return DeferSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../Observable":378,"../OuterSubscriber":381,"../util/subscribeToResult":705}],520:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var EmptyObservable = (function (_super) { + __extends(EmptyObservable, _super); + function EmptyObservable(scheduler) { + _super.call(this); + this.scheduler = scheduler; + } + /** + * Creates an Observable that emits no items to the Observer and immediately + * emits a complete notification. + * + * Just emits 'complete', and nothing else. + * + * + * + * + * This static operator is useful for creating a simple Observable that only + * emits the complete notification. It can be used for composing with other + * Observables, such as in a {@link mergeMap}. + * + * @example Emit the number 7, then complete. + * var result = Rx.Observable.empty().startWith(7); + * result.subscribe(x => console.log(x)); + * + * @example Map and flatten only odd numbers to the sequence 'a', 'b', 'c' + * var interval = Rx.Observable.interval(1000); + * var result = interval.mergeMap(x => + * x % 2 === 1 ? Rx.Observable.of('a', 'b', 'c') : Rx.Observable.empty() + * ); + * result.subscribe(x => console.log(x)); + * + * @see {@link create} + * @see {@link never} + * @see {@link of} + * @see {@link throw} + * + * @param {Scheduler} [scheduler] A {@link Scheduler} to use for scheduling + * the emission of the complete notification. + * @return {Observable} An "empty" Observable: emits only the complete + * notification. + * @static true + * @name empty + * @owner Observable + */ + EmptyObservable.create = function (scheduler) { + return new EmptyObservable(scheduler); + }; + EmptyObservable.dispatch = function (arg) { + var subscriber = arg.subscriber; + subscriber.complete(); + }; + EmptyObservable.prototype._subscribe = function (subscriber) { + var scheduler = this.scheduler; + if (scheduler) { + return scheduler.schedule(EmptyObservable.dispatch, 0, { subscriber: subscriber }); + } + else { + subscriber.complete(); + } + }; + return EmptyObservable; +}(Observable_1.Observable)); +exports.EmptyObservable = EmptyObservable; + +},{"../Observable":378}],521:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var ErrorObservable = (function (_super) { + __extends(ErrorObservable, _super); + function ErrorObservable(error, scheduler) { + _super.call(this); + this.error = error; + this.scheduler = scheduler; + } + /** + * Creates an Observable that emits no items to the Observer and immediately + * emits an error notification. + * + * Just emits 'error', and nothing else. + * + * + * + * + * This static operator is useful for creating a simple Observable that only + * emits the error notification. It can be used for composing with other + * Observables, such as in a {@link mergeMap}. + * + * @example Emit the number 7, then emit an error. + * var result = Rx.Observable.throw(new Error('oops!')).startWith(7); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @example Map and flattens numbers to the sequence 'a', 'b', 'c', but throw an error for 13 + * var interval = Rx.Observable.interval(1000); + * var result = interval.mergeMap(x => + * x === 13 ? + * Rx.Observable.throw('Thirteens are bad') : + * Rx.Observable.of('a', 'b', 'c') + * ); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @see {@link create} + * @see {@link empty} + * @see {@link never} + * @see {@link of} + * + * @param {any} error The particular Error to pass to the error notification. + * @param {Scheduler} [scheduler] A {@link Scheduler} to use for scheduling + * the emission of the error notification. + * @return {Observable} An error Observable: emits only the error notification + * using the given error argument. + * @static true + * @name throw + * @owner Observable + */ + ErrorObservable.create = function (error, scheduler) { + return new ErrorObservable(error, scheduler); + }; + ErrorObservable.dispatch = function (arg) { + var error = arg.error, subscriber = arg.subscriber; + subscriber.error(error); + }; + ErrorObservable.prototype._subscribe = function (subscriber) { + var error = this.error; + var scheduler = this.scheduler; + if (scheduler) { + return scheduler.schedule(ErrorObservable.dispatch, 0, { + error: error, subscriber: subscriber + }); + } + else { + subscriber.error(error); + } + }; + return ErrorObservable; +}(Observable_1.Observable)); +exports.ErrorObservable = ErrorObservable; + +},{"../Observable":378}],522:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var EmptyObservable_1 = require('./EmptyObservable'); +var isArray_1 = require('../util/isArray'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var ForkJoinObservable = (function (_super) { + __extends(ForkJoinObservable, _super); + function ForkJoinObservable(sources, resultSelector) { + _super.call(this); + this.sources = sources; + this.resultSelector = resultSelector; + } + /** + * @param sources + * @return {any} + * @static true + * @name forkJoin + * @owner Observable + */ + ForkJoinObservable.create = function () { + var sources = []; + for (var _i = 0; _i < arguments.length; _i++) { + sources[_i - 0] = arguments[_i]; + } + if (sources === null || arguments.length === 0) { + return new EmptyObservable_1.EmptyObservable(); + } + var resultSelector = null; + if (typeof sources[sources.length - 1] === 'function') { + resultSelector = sources.pop(); + } + // if the first and only other argument besides the resultSelector is an array + // assume it's been called with `forkJoin([obs1, obs2, obs3], resultSelector)` + if (sources.length === 1 && isArray_1.isArray(sources[0])) { + sources = sources[0]; + } + if (sources.length === 0) { + return new EmptyObservable_1.EmptyObservable(); + } + return new ForkJoinObservable(sources, resultSelector); + }; + ForkJoinObservable.prototype._subscribe = function (subscriber) { + return new ForkJoinSubscriber(subscriber, this.sources, this.resultSelector); + }; + return ForkJoinObservable; +}(Observable_1.Observable)); +exports.ForkJoinObservable = ForkJoinObservable; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ForkJoinSubscriber = (function (_super) { + __extends(ForkJoinSubscriber, _super); + function ForkJoinSubscriber(destination, sources, resultSelector) { + _super.call(this, destination); + this.sources = sources; + this.resultSelector = resultSelector; + this.completed = 0; + this.haveValues = 0; + var len = sources.length; + this.total = len; + this.values = new Array(len); + for (var i = 0; i < len; i++) { + var source = sources[i]; + var innerSubscription = subscribeToResult_1.subscribeToResult(this, source, null, i); + if (innerSubscription) { + innerSubscription.outerIndex = i; + this.add(innerSubscription); + } + } + } + ForkJoinSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.values[outerIndex] = innerValue; + if (!innerSub._hasValue) { + innerSub._hasValue = true; + this.haveValues++; + } + }; + ForkJoinSubscriber.prototype.notifyComplete = function (innerSub) { + var destination = this.destination; + var _a = this, haveValues = _a.haveValues, resultSelector = _a.resultSelector, values = _a.values; + var len = values.length; + if (!innerSub._hasValue) { + destination.complete(); + return; + } + this.completed++; + if (this.completed !== len) { + return; + } + if (haveValues === len) { + var value = resultSelector ? resultSelector.apply(this, values) : values; + destination.next(value); + } + destination.complete(); + }; + return ForkJoinSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../Observable":378,"../OuterSubscriber":381,"../util/isArray":695,"../util/subscribeToResult":705,"./EmptyObservable":520}],523:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var Subscription_1 = require('../Subscription'); +function isNodeStyleEventEmmitter(sourceObj) { + return !!sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function'; +} +function isJQueryStyleEventEmitter(sourceObj) { + return !!sourceObj && typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function'; +} +function isNodeList(sourceObj) { + return !!sourceObj && sourceObj.toString() === '[object NodeList]'; +} +function isHTMLCollection(sourceObj) { + return !!sourceObj && sourceObj.toString() === '[object HTMLCollection]'; +} +function isEventTarget(sourceObj) { + return !!sourceObj && typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function'; +} +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var FromEventObservable = (function (_super) { + __extends(FromEventObservable, _super); + function FromEventObservable(sourceObj, eventName, selector) { + _super.call(this); + this.sourceObj = sourceObj; + this.eventName = eventName; + this.selector = selector; + } + /** + * Creates an Observable that emits events of a specific type coming from the + * given event target. + * + * Creates an Observable from DOM events, or Node + * EventEmitter events or others. + * + * + * + * Creates an Observable by attaching an event listener to an "event target", + * which may be an object with `addEventListener` and `removeEventListener`, + * a Node.js EventEmitter, a jQuery style EventEmitter, a NodeList from the + * DOM, or an HTMLCollection from the DOM. The event handler is attached when + * the output Observable is subscribed, and removed when the Subscription is + * unsubscribed. + * + * @example Emits clicks happening on the DOM document + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * clicks.subscribe(x => console.log(x)); + * + * @see {@link from} + * @see {@link fromEventPattern} + * + * @param {EventTargetLike} target The DOMElement, event target, Node.js + * EventEmitter, NodeList or HTMLCollection to attach the event handler to. + * @param {string} eventName The event name of interest, being emitted by the + * `target`. + * @param {function(...args: any): T} [selector] An optional function to + * post-process results. It takes the arguments from the event handler and + * should return a single value. + * @return {Observable} + * @static true + * @name fromEvent + * @owner Observable + */ + FromEventObservable.create = function (target, eventName, selector) { + return new FromEventObservable(target, eventName, selector); + }; + FromEventObservable.setupSubscription = function (sourceObj, eventName, handler, subscriber) { + var unsubscribe; + if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { + for (var i = 0, len = sourceObj.length; i < len; i++) { + FromEventObservable.setupSubscription(sourceObj[i], eventName, handler, subscriber); + } + } + else if (isEventTarget(sourceObj)) { + sourceObj.addEventListener(eventName, handler); + unsubscribe = function () { return sourceObj.removeEventListener(eventName, handler); }; + } + else if (isJQueryStyleEventEmitter(sourceObj)) { + sourceObj.on(eventName, handler); + unsubscribe = function () { return sourceObj.off(eventName, handler); }; + } + else if (isNodeStyleEventEmmitter(sourceObj)) { + sourceObj.addListener(eventName, handler); + unsubscribe = function () { return sourceObj.removeListener(eventName, handler); }; + } + subscriber.add(new Subscription_1.Subscription(unsubscribe)); + }; + FromEventObservable.prototype._subscribe = function (subscriber) { + var sourceObj = this.sourceObj; + var eventName = this.eventName; + var selector = this.selector; + var handler = selector ? function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + var result = tryCatch_1.tryCatch(selector).apply(void 0, args); + if (result === errorObject_1.errorObject) { + subscriber.error(errorObject_1.errorObject.e); + } + else { + subscriber.next(result); + } + } : function (e) { return subscriber.next(e); }; + FromEventObservable.setupSubscription(sourceObj, eventName, handler, subscriber); + }; + return FromEventObservable; +}(Observable_1.Observable)); +exports.FromEventObservable = FromEventObservable; + +},{"../Observable":378,"../Subscription":387,"../util/errorObject":694,"../util/tryCatch":708}],524:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var Subscription_1 = require('../Subscription'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var FromEventPatternObservable = (function (_super) { + __extends(FromEventPatternObservable, _super); + function FromEventPatternObservable(addHandler, removeHandler, selector) { + _super.call(this); + this.addHandler = addHandler; + this.removeHandler = removeHandler; + this.selector = selector; + } + /** + * Creates an Observable from an API based on addHandler/removeHandler + * functions. + * + * Converts any addHandler/removeHandler API to an + * Observable. + * + * + * + * Creates an Observable by using the `addHandler` and `removeHandler` + * functions to add and remove the handlers, with an optional selector + * function to project the event arguments to a result. The `addHandler` is + * called when the output Observable is subscribed, and `removeHandler` is + * called when the Subscription is unsubscribed. + * + * @example Emits clicks happening on the DOM document + * function addClickHandler(handler) { + * document.addEventListener('click', handler); + * } + * + * function removeClickHandler(handler) { + * document.removeEventListener('click', handler); + * } + * + * var clicks = Rx.Observable.fromEventPattern( + * addClickHandler, + * removeClickHandler + * ); + * clicks.subscribe(x => console.log(x)); + * + * @see {@link from} + * @see {@link fromEvent} + * + * @param {function(handler: Function): any} addHandler A function that takes + * a `handler` function as argument and attaches it somehow to the actual + * source of events. + * @param {function(handler: Function): void} removeHandler A function that + * takes a `handler` function as argument and removes it in case it was + * previously attached using `addHandler`. + * @param {function(...args: any): T} [selector] An optional function to + * post-process results. It takes the arguments from the event handler and + * should return a single value. + * @return {Observable} + * @static true + * @name fromEventPattern + * @owner Observable + */ + FromEventPatternObservable.create = function (addHandler, removeHandler, selector) { + return new FromEventPatternObservable(addHandler, removeHandler, selector); + }; + FromEventPatternObservable.prototype._subscribe = function (subscriber) { + var addHandler = this.addHandler; + var removeHandler = this.removeHandler; + var selector = this.selector; + var handler = selector ? function (e) { + var result = tryCatch_1.tryCatch(selector).apply(null, arguments); + if (result === errorObject_1.errorObject) { + subscriber.error(result.e); + } + else { + subscriber.next(result); + } + } : function (e) { subscriber.next(e); }; + var result = tryCatch_1.tryCatch(addHandler)(handler); + if (result === errorObject_1.errorObject) { + subscriber.error(result.e); + } + subscriber.add(new Subscription_1.Subscription(function () { + //TODO: determine whether or not to forward to error handler + removeHandler(handler); + })); + }; + return FromEventPatternObservable; +}(Observable_1.Observable)); +exports.FromEventPatternObservable = FromEventPatternObservable; + +},{"../Observable":378,"../Subscription":387,"../util/errorObject":694,"../util/tryCatch":708}],525:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var isArray_1 = require('../util/isArray'); +var isFunction_1 = require('../util/isFunction'); +var isPromise_1 = require('../util/isPromise'); +var isScheduler_1 = require('../util/isScheduler'); +var PromiseObservable_1 = require('./PromiseObservable'); +var IteratorObservable_1 = require('./IteratorObservable'); +var ArrayObservable_1 = require('./ArrayObservable'); +var ArrayLikeObservable_1 = require('./ArrayLikeObservable'); +var iterator_1 = require('../symbol/iterator'); +var Observable_1 = require('../Observable'); +var observeOn_1 = require('../operator/observeOn'); +var $$observable = require('symbol-observable'); +var isArrayLike = (function (x) { return x && typeof x.length === 'number'; }); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var FromObservable = (function (_super) { + __extends(FromObservable, _super); + function FromObservable(ish, scheduler) { + _super.call(this, null); + this.ish = ish; + this.scheduler = scheduler; + } + /** + * Creates an Observable from an Array, an array-like object, a Promise, an + * iterable object, or an Observable-like object. + * + * Converts almost anything to an Observable. + * + * + * + * Convert various other objects and data types into Observables. `from` + * converts a Promise or an array-like or an + * [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable) + * object into an Observable that emits the items in that promise or array or + * iterable. A String, in this context, is treated as an array of characters. + * Observable-like objects (contains a function named with the ES2015 Symbol + * for Observable) can also be converted through this operator. + * + * @example Converts an array to an Observable + * var array = [10, 20, 30]; + * var result = Rx.Observable.from(array); + * result.subscribe(x => console.log(x)); + * + * @example Convert an infinite iterable (from a generator) to an Observable + * function* generateDoubles(seed) { + * var i = seed; + * while (true) { + * yield i; + * i = 2 * i; // double it + * } + * } + * + * var iterator = generateDoubles(3); + * var result = Rx.Observable.from(iterator).take(10); + * result.subscribe(x => console.log(x)); + * + * @see {@link create} + * @see {@link fromEvent} + * @see {@link fromEventPattern} + * @see {@link fromPromise} + * + * @param {ObservableInput} ish A subscribable object, a Promise, an + * Observable-like, an Array, an iterable or an array-like object to be + * converted. + * @param {function(x: any, i: number): T} [mapFn] A "map" function to call + * when converting array-like objects, where `x` is a value from the + * array-like and `i` is the index of that value in the sequence. + * @param {any} [thisArg] The context object to use when calling the `mapFn`, + * if provided. + * @param {Scheduler} [scheduler] The scheduler on which to schedule the + * emissions of values. + * @return {Observable} The Observable whose values are originally from the + * input object that was converted. + * @static true + * @name from + * @owner Observable + */ + FromObservable.create = function (ish, mapFnOrScheduler, thisArg, lastScheduler) { + var scheduler = null; + var mapFn = null; + if (isFunction_1.isFunction(mapFnOrScheduler)) { + scheduler = lastScheduler || null; + mapFn = mapFnOrScheduler; + } + else if (isScheduler_1.isScheduler(scheduler)) { + scheduler = mapFnOrScheduler; + } + if (ish != null) { + if (typeof ish[$$observable] === 'function') { + if (ish instanceof Observable_1.Observable && !scheduler) { + return ish; + } + return new FromObservable(ish, scheduler); + } + else if (isArray_1.isArray(ish)) { + return new ArrayObservable_1.ArrayObservable(ish, scheduler); + } + else if (isPromise_1.isPromise(ish)) { + return new PromiseObservable_1.PromiseObservable(ish, scheduler); + } + else if (typeof ish[iterator_1.$$iterator] === 'function' || typeof ish === 'string') { + return new IteratorObservable_1.IteratorObservable(ish, null, null, scheduler); + } + else if (isArrayLike(ish)) { + return new ArrayLikeObservable_1.ArrayLikeObservable(ish, mapFn, thisArg, scheduler); + } + } + throw new TypeError((ish !== null && typeof ish || ish) + ' is not observable'); + }; + FromObservable.prototype._subscribe = function (subscriber) { + var ish = this.ish; + var scheduler = this.scheduler; + if (scheduler == null) { + return ish[$$observable]().subscribe(subscriber); + } + else { + return ish[$$observable]().subscribe(new observeOn_1.ObserveOnSubscriber(subscriber, scheduler, 0)); + } + }; + return FromObservable; +}(Observable_1.Observable)); +exports.FromObservable = FromObservable; + +},{"../Observable":378,"../operator/observeOn":616,"../symbol/iterator":676,"../util/isArray":695,"../util/isFunction":697,"../util/isPromise":700,"../util/isScheduler":701,"./ArrayLikeObservable":514,"./ArrayObservable":515,"./IteratorObservable":529,"./PromiseObservable":532,"symbol-observable":709}],526:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var isScheduler_1 = require('../util/isScheduler'); +var selfSelector = function (value) { return value; }; +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var GenerateObservable = (function (_super) { + __extends(GenerateObservable, _super); + function GenerateObservable(initialState, condition, iterate, resultSelector, scheduler) { + _super.call(this); + this.initialState = initialState; + this.condition = condition; + this.iterate = iterate; + this.resultSelector = resultSelector; + this.scheduler = scheduler; + } + GenerateObservable.create = function (initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) { + if (arguments.length == 1) { + return new GenerateObservable(initialStateOrOptions.initialState, initialStateOrOptions.condition, initialStateOrOptions.iterate, initialStateOrOptions.resultSelector || selfSelector, initialStateOrOptions.scheduler); + } + if (resultSelectorOrObservable === undefined || isScheduler_1.isScheduler(resultSelectorOrObservable)) { + return new GenerateObservable(initialStateOrOptions, condition, iterate, selfSelector, resultSelectorOrObservable); + } + return new GenerateObservable(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler); + }; + GenerateObservable.prototype._subscribe = function (subscriber) { + var state = this.initialState; + if (this.scheduler) { + return this.scheduler.schedule(GenerateObservable.dispatch, 0, { + subscriber: subscriber, + iterate: this.iterate, + condition: this.condition, + resultSelector: this.resultSelector, + state: state }); + } + var _a = this, condition = _a.condition, resultSelector = _a.resultSelector, iterate = _a.iterate; + do { + if (condition) { + var conditionResult = void 0; + try { + conditionResult = condition(state); + } + catch (err) { + subscriber.error(err); + return; + } + if (!conditionResult) { + subscriber.complete(); + break; + } + } + var value = void 0; + try { + value = resultSelector(state); + } + catch (err) { + subscriber.error(err); + return; + } + subscriber.next(value); + if (subscriber.isUnsubscribed) { + break; + } + try { + state = iterate(state); + } + catch (err) { + subscriber.error(err); + return; + } + } while (true); + }; + GenerateObservable.dispatch = function (state) { + var subscriber = state.subscriber, condition = state.condition; + if (subscriber.isUnsubscribed) { + return; + } + if (state.needIterate) { + try { + state.state = state.iterate(state.state); + } + catch (err) { + subscriber.error(err); + return; + } + } + else { + state.needIterate = true; + } + if (condition) { + var conditionResult = void 0; + try { + conditionResult = condition(state.state); + } + catch (err) { + subscriber.error(err); + return; + } + if (!conditionResult) { + subscriber.complete(); + return; + } + if (subscriber.isUnsubscribed) { + return; + } + } + var value; + try { + value = state.resultSelector(state.state); + } + catch (err) { + subscriber.error(err); + return; + } + if (subscriber.isUnsubscribed) { + return; + } + subscriber.next(value); + if (subscriber.isUnsubscribed) { + return; + } + return this.schedule(state); + }; + return GenerateObservable; +}(Observable_1.Observable)); +exports.GenerateObservable = GenerateObservable; + +},{"../Observable":378,"../util/isScheduler":701}],527:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var IfObservable = (function (_super) { + __extends(IfObservable, _super); + function IfObservable(condition, thenSource, elseSource) { + _super.call(this); + this.condition = condition; + this.thenSource = thenSource; + this.elseSource = elseSource; + } + IfObservable.create = function (condition, thenSource, elseSource) { + return new IfObservable(condition, thenSource, elseSource); + }; + IfObservable.prototype._subscribe = function (subscriber) { + var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource; + return new IfSubscriber(subscriber, condition, thenSource, elseSource); + }; + return IfObservable; +}(Observable_1.Observable)); +exports.IfObservable = IfObservable; +var IfSubscriber = (function (_super) { + __extends(IfSubscriber, _super); + function IfSubscriber(destination, condition, thenSource, elseSource) { + _super.call(this, destination); + this.condition = condition; + this.thenSource = thenSource; + this.elseSource = elseSource; + this.tryIf(); + } + IfSubscriber.prototype.tryIf = function () { + var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource; + var result; + try { + result = condition(); + var source = result ? thenSource : elseSource; + if (source) { + this.add(subscribeToResult_1.subscribeToResult(this, source)); + } + else { + this._complete(); + } + } + catch (err) { + this._error(err); + } + }; + return IfSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../Observable":378,"../OuterSubscriber":381,"../util/subscribeToResult":705}],528:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var isNumeric_1 = require('../util/isNumeric'); +var Observable_1 = require('../Observable'); +var async_1 = require('../scheduler/async'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var IntervalObservable = (function (_super) { + __extends(IntervalObservable, _super); + function IntervalObservable(period, scheduler) { + if (period === void 0) { period = 0; } + if (scheduler === void 0) { scheduler = async_1.async; } + _super.call(this); + this.period = period; + this.scheduler = scheduler; + if (!isNumeric_1.isNumeric(period) || period < 0) { + this.period = 0; + } + if (!scheduler || typeof scheduler.schedule !== 'function') { + this.scheduler = async_1.async; + } + } + /** + * Creates an Observable that emits sequential numbers every specified + * interval of time, on a specified Scheduler. + * + * Emits incremental numbers periodically in time. + * + * + * + * + * `interval` returns an Observable that emits an infinite sequence of + * ascending integers, with a constant interval of time of your choosing + * between those emissions. The first emission is not sent immediately, but + * only after the first period has passed. By default, this operator uses the + * `async` Scheduler to provide a notion of time, but you may pass any + * Scheduler to it. + * + * @example Emits ascending numbers, one every second (1000ms) + * var numbers = Rx.Observable.interval(1000); + * numbers.subscribe(x => console.log(x)); + * + * @see {@link timer} + * @see {@link delay} + * + * @param {number} [period=0] The interval size in milliseconds (by default) + * or the time unit determined by the scheduler's clock. + * @param {Scheduler} [scheduler=async] The Scheduler to use for scheduling + * the emission of values, and providing a notion of "time". + * @return {Observable} An Observable that emits a sequential number each time + * interval. + * @static true + * @name interval + * @owner Observable + */ + IntervalObservable.create = function (period, scheduler) { + if (period === void 0) { period = 0; } + if (scheduler === void 0) { scheduler = async_1.async; } + return new IntervalObservable(period, scheduler); + }; + IntervalObservable.dispatch = function (state) { + var index = state.index, subscriber = state.subscriber, period = state.period; + subscriber.next(index); + if (subscriber.isUnsubscribed) { + return; + } + state.index += 1; + this.schedule(state, period); + }; + IntervalObservable.prototype._subscribe = function (subscriber) { + var index = 0; + var period = this.period; + var scheduler = this.scheduler; + subscriber.add(scheduler.schedule(IntervalObservable.dispatch, period, { + index: index, subscriber: subscriber, period: period + })); + }; + return IntervalObservable; +}(Observable_1.Observable)); +exports.IntervalObservable = IntervalObservable; + +},{"../Observable":378,"../scheduler/async":674,"../util/isNumeric":698}],529:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var root_1 = require('../util/root'); +var isObject_1 = require('../util/isObject'); +var tryCatch_1 = require('../util/tryCatch'); +var Observable_1 = require('../Observable'); +var isFunction_1 = require('../util/isFunction'); +var iterator_1 = require('../symbol/iterator'); +var errorObject_1 = require('../util/errorObject'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var IteratorObservable = (function (_super) { + __extends(IteratorObservable, _super); + function IteratorObservable(iterator, project, thisArg, scheduler) { + _super.call(this); + if (iterator == null) { + throw new Error('iterator cannot be null.'); + } + if (isObject_1.isObject(project)) { + this.thisArg = project; + this.scheduler = thisArg; + } + else if (isFunction_1.isFunction(project)) { + this.project = project; + this.thisArg = thisArg; + this.scheduler = scheduler; + } + else if (project != null) { + throw new Error('When provided, `project` must be a function.'); + } + this.iterator = getIterator(iterator); + } + IteratorObservable.create = function (iterator, project, thisArg, scheduler) { + return new IteratorObservable(iterator, project, thisArg, scheduler); + }; + IteratorObservable.dispatch = function (state) { + var index = state.index, hasError = state.hasError, thisArg = state.thisArg, project = state.project, iterator = state.iterator, subscriber = state.subscriber; + if (hasError) { + subscriber.error(state.error); + return; + } + var result = iterator.next(); + if (result.done) { + subscriber.complete(); + return; + } + if (project) { + result = tryCatch_1.tryCatch(project).call(thisArg, result.value, index); + if (result === errorObject_1.errorObject) { + state.error = errorObject_1.errorObject.e; + state.hasError = true; + } + else { + subscriber.next(result); + state.index = index + 1; + } + } + else { + subscriber.next(result.value); + state.index = index + 1; + } + if (subscriber.isUnsubscribed) { + return; + } + this.schedule(state); + }; + IteratorObservable.prototype._subscribe = function (subscriber) { + var index = 0; + var _a = this, iterator = _a.iterator, project = _a.project, thisArg = _a.thisArg, scheduler = _a.scheduler; + if (scheduler) { + return scheduler.schedule(IteratorObservable.dispatch, 0, { + index: index, thisArg: thisArg, project: project, iterator: iterator, subscriber: subscriber + }); + } + else { + do { + var result = iterator.next(); + if (result.done) { + subscriber.complete(); + break; + } + else if (project) { + result = tryCatch_1.tryCatch(project).call(thisArg, result.value, index++); + if (result === errorObject_1.errorObject) { + subscriber.error(errorObject_1.errorObject.e); + break; + } + subscriber.next(result); + } + else { + subscriber.next(result.value); + } + if (subscriber.isUnsubscribed) { + break; + } + } while (true); + } + }; + return IteratorObservable; +}(Observable_1.Observable)); +exports.IteratorObservable = IteratorObservable; +var StringIterator = (function () { + function StringIterator(str, idx, len) { + if (idx === void 0) { idx = 0; } + if (len === void 0) { len = str.length; } + this.str = str; + this.idx = idx; + this.len = len; + } + StringIterator.prototype[iterator_1.$$iterator] = function () { return (this); }; + StringIterator.prototype.next = function () { + return this.idx < this.len ? { + done: false, + value: this.str.charAt(this.idx++) + } : { + done: true, + value: undefined + }; + }; + return StringIterator; +}()); +var ArrayIterator = (function () { + function ArrayIterator(arr, idx, len) { + if (idx === void 0) { idx = 0; } + if (len === void 0) { len = toLength(arr); } + this.arr = arr; + this.idx = idx; + this.len = len; + } + ArrayIterator.prototype[iterator_1.$$iterator] = function () { return this; }; + ArrayIterator.prototype.next = function () { + return this.idx < this.len ? { + done: false, + value: this.arr[this.idx++] + } : { + done: true, + value: undefined + }; + }; + return ArrayIterator; +}()); +function getIterator(obj) { + var i = obj[iterator_1.$$iterator]; + if (!i && typeof obj === 'string') { + return new StringIterator(obj); + } + if (!i && obj.length !== undefined) { + return new ArrayIterator(obj); + } + if (!i) { + throw new TypeError('Object is not iterable'); + } + return obj[iterator_1.$$iterator](); +} +var maxSafeInteger = Math.pow(2, 53) - 1; +function toLength(o) { + var len = +o.length; + if (isNaN(len)) { + return 0; + } + if (len === 0 || !numberIsFinite(len)) { + return len; + } + len = sign(len) * Math.floor(Math.abs(len)); + if (len <= 0) { + return 0; + } + if (len > maxSafeInteger) { + return maxSafeInteger; + } + return len; +} +function numberIsFinite(value) { + return typeof value === 'number' && root_1.root.isFinite(value); +} +function sign(value) { + var valueAsNumber = +value; + if (valueAsNumber === 0) { + return valueAsNumber; + } + if (isNaN(valueAsNumber)) { + return valueAsNumber; + } + return valueAsNumber < 0 ? -1 : 1; +} + +},{"../Observable":378,"../symbol/iterator":676,"../util/errorObject":694,"../util/isFunction":697,"../util/isObject":699,"../util/root":704,"../util/tryCatch":708}],530:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var MulticastObservable = (function (_super) { + __extends(MulticastObservable, _super); + function MulticastObservable(source, connectable, selector) { + _super.call(this); + this.source = source; + this.connectable = connectable; + this.selector = selector; + } + MulticastObservable.prototype._subscribe = function (subscriber) { + var _a = this, selector = _a.selector, connectable = _a.connectable; + var subscription = selector(connectable).subscribe(subscriber); + subscription.add(connectable.connect()); + return subscription; + }; + return MulticastObservable; +}(Observable_1.Observable)); +exports.MulticastObservable = MulticastObservable; + +},{"../Observable":378}],531:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var noop_1 = require('../util/noop'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var NeverObservable = (function (_super) { + __extends(NeverObservable, _super); + function NeverObservable() { + _super.call(this); + } + /** + * Creates an Observable that emits no items to the Observer. + * + * An Observable that never emits anything. + * + * + * + * This static operator is useful for creating a simple Observable that emits + * neither values nor errors nor the completion notification. It can be used + * for testing purposes or for composing with other Observables. Please not + * that by never emitting a complete notification, this Observable keeps the + * subscription from being disposed automatically. Subscriptions need to be + * manually disposed. + * + * @example Emit the number 7, then never emit anything else (not even complete). + * function info() { + * console.log('Will not be called'); + * } + * var result = Rx.Observable.never().startWith(7); + * result.subscribe(x => console.log(x), info, info); + * + * @see {@link create} + * @see {@link empty} + * @see {@link of} + * @see {@link throw} + * + * @return {Observable} A "never" Observable: never emits anything. + * @static true + * @name never + * @owner Observable + */ + NeverObservable.create = function () { + return new NeverObservable(); + }; + NeverObservable.prototype._subscribe = function (subscriber) { + noop_1.noop(); + }; + return NeverObservable; +}(Observable_1.Observable)); +exports.NeverObservable = NeverObservable; + +},{"../Observable":378,"../util/noop":702}],532:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var root_1 = require('../util/root'); +var Observable_1 = require('../Observable'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var PromiseObservable = (function (_super) { + __extends(PromiseObservable, _super); + function PromiseObservable(promise, scheduler) { + if (scheduler === void 0) { scheduler = null; } + _super.call(this); + this.promise = promise; + this.scheduler = scheduler; + } + /** + * Converts a Promise to an Observable. + * + * Returns an Observable that just emits the Promise's + * resolved value, then completes. + * + * Converts an ES2015 Promise or a Promises/A+ spec compliant Promise to an + * Observable. If the Promise resolves with a value, the output Observable + * emits that resolved value as a `next`, and then completes. If the Promise + * is rejected, then the output Observable emits the corresponding Error. + * + * @example Convert the Promise returned by Fetch to an Observable + * var result = Rx.Observable.fromPromise(fetch('http://myserver.com/')); + * result.subscribe(x => console.log(x), e => console.error(e)); + * + * @see {@link bindCallback} + * @see {@link from} + * + * @param {Promise} promise The promise to be converted. + * @param {Scheduler} [scheduler] An optional Scheduler to use for scheduling + * the delivery of the resolved value (or the rejection). + * @return {Observable} An Observable which wraps the Promise. + * @static true + * @name fromPromise + * @owner Observable + */ + PromiseObservable.create = function (promise, scheduler) { + if (scheduler === void 0) { scheduler = null; } + return new PromiseObservable(promise, scheduler); + }; + PromiseObservable.prototype._subscribe = function (subscriber) { + var _this = this; + var promise = this.promise; + var scheduler = this.scheduler; + if (scheduler == null) { + if (this._isScalar) { + if (!subscriber.isUnsubscribed) { + subscriber.next(this.value); + subscriber.complete(); + } + } + else { + promise.then(function (value) { + _this.value = value; + _this._isScalar = true; + if (!subscriber.isUnsubscribed) { + subscriber.next(value); + subscriber.complete(); + } + }, function (err) { + if (!subscriber.isUnsubscribed) { + subscriber.error(err); + } + }) + .then(null, function (err) { + // escape the promise trap, throw unhandled errors + root_1.root.setTimeout(function () { throw err; }); + }); + } + } + else { + if (this._isScalar) { + if (!subscriber.isUnsubscribed) { + return scheduler.schedule(dispatchNext, 0, { value: this.value, subscriber: subscriber }); + } + } + else { + promise.then(function (value) { + _this.value = value; + _this._isScalar = true; + if (!subscriber.isUnsubscribed) { + subscriber.add(scheduler.schedule(dispatchNext, 0, { value: value, subscriber: subscriber })); + } + }, function (err) { + if (!subscriber.isUnsubscribed) { + subscriber.add(scheduler.schedule(dispatchError, 0, { err: err, subscriber: subscriber })); + } + }) + .then(null, function (err) { + // escape the promise trap, throw unhandled errors + root_1.root.setTimeout(function () { throw err; }); + }); + } + } + }; + return PromiseObservable; +}(Observable_1.Observable)); +exports.PromiseObservable = PromiseObservable; +function dispatchNext(arg) { + var value = arg.value, subscriber = arg.subscriber; + if (!subscriber.isUnsubscribed) { + subscriber.next(value); + subscriber.complete(); + } +} +function dispatchError(arg) { + var err = arg.err, subscriber = arg.subscriber; + if (!subscriber.isUnsubscribed) { + subscriber.error(err); + } +} + +},{"../Observable":378,"../util/root":704}],533:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var RangeObservable = (function (_super) { + __extends(RangeObservable, _super); + function RangeObservable(start, count, scheduler) { + _super.call(this); + this.start = start; + this._count = count; + this.scheduler = scheduler; + } + /** + * Creates an Observable that emits a sequence of numbers within a specified + * range. + * + * Emits a sequence of numbers in a range. + * + * + * + * `range` operator emits a range of sequential integers, in order, where you + * select the `start` of the range and its `length`. By default, uses no + * Scheduler and just delivers the notifications synchronously, but may use + * an optional Scheduler to regulate those deliveries. + * + * @example Emits the numbers 1 to 10 + * var numbers = Rx.Observable.range(1, 10); + * numbers.subscribe(x => console.log(x)); + * + * @see {@link timer} + * @see {@link interval} + * + * @param {number} [start=0] The value of the first integer in the sequence. + * @param {number} [count=0] The number of sequential integers to generate. + * @param {Scheduler} [scheduler] A {@link Scheduler} to use for scheduling + * the emissions of the notifications. + * @return {Observable} An Observable of numbers that emits a finite range of + * sequential integers. + * @static true + * @name range + * @owner Observable + */ + RangeObservable.create = function (start, count, scheduler) { + if (start === void 0) { start = 0; } + if (count === void 0) { count = 0; } + return new RangeObservable(start, count, scheduler); + }; + RangeObservable.dispatch = function (state) { + var start = state.start, index = state.index, count = state.count, subscriber = state.subscriber; + if (index >= count) { + subscriber.complete(); + return; + } + subscriber.next(start); + if (subscriber.isUnsubscribed) { + return; + } + state.index = index + 1; + state.start = start + 1; + this.schedule(state); + }; + RangeObservable.prototype._subscribe = function (subscriber) { + var index = 0; + var start = this.start; + var count = this._count; + var scheduler = this.scheduler; + if (scheduler) { + return scheduler.schedule(RangeObservable.dispatch, 0, { + index: index, count: count, start: start, subscriber: subscriber + }); + } + else { + do { + if (index++ >= count) { + subscriber.complete(); + break; + } + subscriber.next(start++); + if (subscriber.isUnsubscribed) { + break; + } + } while (true); + } + }; + return RangeObservable; +}(Observable_1.Observable)); +exports.RangeObservable = RangeObservable; + +},{"../Observable":378}],534:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var ScalarObservable = (function (_super) { + __extends(ScalarObservable, _super); + function ScalarObservable(value, scheduler) { + _super.call(this); + this.value = value; + this.scheduler = scheduler; + this._isScalar = true; + if (scheduler) { + this._isScalar = false; + } + } + ScalarObservable.create = function (value, scheduler) { + return new ScalarObservable(value, scheduler); + }; + ScalarObservable.dispatch = function (state) { + var done = state.done, value = state.value, subscriber = state.subscriber; + if (done) { + subscriber.complete(); + return; + } + subscriber.next(value); + if (subscriber.isUnsubscribed) { + return; + } + state.done = true; + this.schedule(state); + }; + ScalarObservable.prototype._subscribe = function (subscriber) { + var value = this.value; + var scheduler = this.scheduler; + if (scheduler) { + return scheduler.schedule(ScalarObservable.dispatch, 0, { + done: false, value: value, subscriber: subscriber + }); + } + else { + subscriber.next(value); + if (!subscriber.isUnsubscribed) { + subscriber.complete(); + } + } + }; + return ScalarObservable; +}(Observable_1.Observable)); +exports.ScalarObservable = ScalarObservable; + +},{"../Observable":378}],535:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var asap_1 = require('../scheduler/asap'); +var isNumeric_1 = require('../util/isNumeric'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var SubscribeOnObservable = (function (_super) { + __extends(SubscribeOnObservable, _super); + function SubscribeOnObservable(source, delayTime, scheduler) { + if (delayTime === void 0) { delayTime = 0; } + if (scheduler === void 0) { scheduler = asap_1.asap; } + _super.call(this); + this.source = source; + this.delayTime = delayTime; + this.scheduler = scheduler; + if (!isNumeric_1.isNumeric(delayTime) || delayTime < 0) { + this.delayTime = 0; + } + if (!scheduler || typeof scheduler.schedule !== 'function') { + this.scheduler = asap_1.asap; + } + } + SubscribeOnObservable.create = function (source, delay, scheduler) { + if (delay === void 0) { delay = 0; } + if (scheduler === void 0) { scheduler = asap_1.asap; } + return new SubscribeOnObservable(source, delay, scheduler); + }; + SubscribeOnObservable.dispatch = function (arg) { + var source = arg.source, subscriber = arg.subscriber; + return source.subscribe(subscriber); + }; + SubscribeOnObservable.prototype._subscribe = function (subscriber) { + var delay = this.delayTime; + var source = this.source; + var scheduler = this.scheduler; + return scheduler.schedule(SubscribeOnObservable.dispatch, delay, { + source: source, subscriber: subscriber + }); + }; + return SubscribeOnObservable; +}(Observable_1.Observable)); +exports.SubscribeOnObservable = SubscribeOnObservable; + +},{"../Observable":378,"../scheduler/asap":673,"../util/isNumeric":698}],536:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var isNumeric_1 = require('../util/isNumeric'); +var Observable_1 = require('../Observable'); +var async_1 = require('../scheduler/async'); +var isScheduler_1 = require('../util/isScheduler'); +var isDate_1 = require('../util/isDate'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var TimerObservable = (function (_super) { + __extends(TimerObservable, _super); + function TimerObservable(dueTime, period, scheduler) { + if (dueTime === void 0) { dueTime = 0; } + _super.call(this); + this.period = -1; + this.dueTime = 0; + if (isNumeric_1.isNumeric(period)) { + this.period = Number(period) < 1 && 1 || Number(period); + } + else if (isScheduler_1.isScheduler(period)) { + scheduler = period; + } + if (!isScheduler_1.isScheduler(scheduler)) { + scheduler = async_1.async; + } + this.scheduler = scheduler; + this.dueTime = isDate_1.isDate(dueTime) ? + (+dueTime - this.scheduler.now()) : + dueTime; + } + /** + * Creates an Observable that starts emitting after an `initialDelay` and + * emits ever increasing numbers after each `period` of time thereafter. + * + * Its like {@link interval}, but you can specify when + * should the emissions start. + * + * + * + * `timer` returns an Observable that emits an infinite sequence of ascending + * integers, with a constant interval of time, `period` of your choosing + * between those emissions. The first emission happens after the specified + * `initialDelay`. The initial delay may be a {@link Date}. By default, this + * operator uses the `async` Scheduler to provide a notion of time, but you + * may pass any Scheduler to it. If `period` is not specified, the output + * Observable emits only one value, `0`. Otherwise, it emits an infinite + * sequence. + * + * @example Emits ascending numbers, one every second (1000ms), starting after 3 seconds + * var numbers = Rx.Observable.timer(3000, 1000); + * numbers.subscribe(x => console.log(x)); + * + * @example Emits one number after five seconds + * var numbers = Rx.Observable.timer(5000); + * numbers.subscribe(x => console.log(x)); + * + * @see {@link interval} + * @see {@link delay} + * + * @param {number|Date} initialDelay The initial delay time to wait before + * emitting the first value of `0`. + * @param {number} [period] The period of time between emissions of the + * subsequent numbers. + * @param {Scheduler} [scheduler=async] The Scheduler to use for scheduling + * the emission of values, and providing a notion of "time". + * @return {Observable} An Observable that emits a `0` after the + * `initialDelay` and ever increasing numbers after each `period` of time + * thereafter. + * @static true + * @name timer + * @owner Observable + */ + TimerObservable.create = function (initialDelay, period, scheduler) { + if (initialDelay === void 0) { initialDelay = 0; } + return new TimerObservable(initialDelay, period, scheduler); + }; + TimerObservable.dispatch = function (state) { + var index = state.index, period = state.period, subscriber = state.subscriber; + var action = this; + subscriber.next(index); + if (subscriber.isUnsubscribed) { + return; + } + else if (period === -1) { + return subscriber.complete(); + } + state.index = index + 1; + action.schedule(state, period); + }; + TimerObservable.prototype._subscribe = function (subscriber) { + var index = 0; + var _a = this, period = _a.period, dueTime = _a.dueTime, scheduler = _a.scheduler; + return scheduler.schedule(TimerObservable.dispatch, dueTime, { + index: index, period: period, subscriber: subscriber + }); + }; + return TimerObservable; +}(Observable_1.Observable)); +exports.TimerObservable = TimerObservable; + +},{"../Observable":378,"../scheduler/async":674,"../util/isDate":696,"../util/isNumeric":698,"../util/isScheduler":701}],537:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var UsingObservable = (function (_super) { + __extends(UsingObservable, _super); + function UsingObservable(resourceFactory, observableFactory) { + _super.call(this); + this.resourceFactory = resourceFactory; + this.observableFactory = observableFactory; + } + UsingObservable.create = function (resourceFactory, observableFactory) { + return new UsingObservable(resourceFactory, observableFactory); + }; + UsingObservable.prototype._subscribe = function (subscriber) { + var _a = this, resourceFactory = _a.resourceFactory, observableFactory = _a.observableFactory; + var resource; + try { + resource = resourceFactory(); + return new UsingSubscriber(subscriber, resource, observableFactory); + } + catch (err) { + subscriber.error(err); + } + }; + return UsingObservable; +}(Observable_1.Observable)); +exports.UsingObservable = UsingObservable; +var UsingSubscriber = (function (_super) { + __extends(UsingSubscriber, _super); + function UsingSubscriber(destination, resource, observableFactory) { + _super.call(this, destination); + this.resource = resource; + this.observableFactory = observableFactory; + destination.add(resource); + this.tryUse(); + } + UsingSubscriber.prototype.tryUse = function () { + try { + var source = this.observableFactory.call(this, this.resource); + if (source) { + this.add(subscribeToResult_1.subscribeToResult(this, source)); + } + } + catch (err) { + this._error(err); + } + }; + return UsingSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../Observable":378,"../OuterSubscriber":381,"../util/subscribeToResult":705}],538:[function(require,module,exports){ +"use strict"; +var BoundCallbackObservable_1 = require('./BoundCallbackObservable'); +exports.bindCallback = BoundCallbackObservable_1.BoundCallbackObservable.create; + +},{"./BoundCallbackObservable":516}],539:[function(require,module,exports){ +"use strict"; +var BoundNodeCallbackObservable_1 = require('./BoundNodeCallbackObservable'); +exports.bindNodeCallback = BoundNodeCallbackObservable_1.BoundNodeCallbackObservable.create; + +},{"./BoundNodeCallbackObservable":517}],540:[function(require,module,exports){ +"use strict"; +var isScheduler_1 = require('../util/isScheduler'); +var isArray_1 = require('../util/isArray'); +var ArrayObservable_1 = require('./ArrayObservable'); +var combineLatest_1 = require('../operator/combineLatest'); +/* tslint:enable:max-line-length */ +/** + * Combines multiple Observables to create an Observable whose values are + * calculated from the latest values of each of its input Observables. + * + * Whenever any input Observable emits a value, it + * computes a formula using the latest values from all the inputs, then emits + * the output of that formula. + * + * + * + * `combineLatest` combines the values from all the Observables passed as + * arguments. This is done by subscribing to each Observable, in order, and + * collecting an array of each of the most recent values any time any of the + * input Observables emits, then either taking that array and passing it as + * arguments to an optional `project` function and emitting the return value of + * that, or just emitting the array of recent values directly if there is no + * `project` function. + * + * @example Dynamically calculate the Body-Mass Index from an Observable of weight and one for height + * var weight = Rx.Observable.of(70, 72, 76, 79, 75); + * var height = Rx.Observable.of(1.76, 1.77, 1.78); + * var bmi = Rx.Observable.combineLatest(weight, height, (w, h) => w / (h * h)); + * bmi.subscribe(x => console.log('BMI is ' + x)); + * + * @see {@link combineAll} + * @see {@link merge} + * @see {@link withLatestFrom} + * + * @param {Observable} observable1 An input Observable to combine with the + * source Observable. + * @param {Observable} observable2 An input Observable to combine with the + * source Observable. More than one input Observables may be given as argument. + * @param {function} [project] An optional function to project the values from + * the combined latest values into a new value on the output Observable. + * @param {Scheduler} [scheduler=null] The Scheduler to use for subscribing to + * each input Observable. + * @return {Observable} An Observable of projected values from the most recent + * values from each input Observable, or an array of the most recent values from + * each input Observable. + * @static true + * @name combineLatest + * @owner Observable + */ +function combineLatest() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + var project = null; + var scheduler = null; + if (isScheduler_1.isScheduler(observables[observables.length - 1])) { + scheduler = observables.pop(); + } + if (typeof observables[observables.length - 1] === 'function') { + project = observables.pop(); + } + // if the first and only other argument besides the resultSelector is an array + // assume it's been called with `combineLatest([obs1, obs2, obs3], project)` + if (observables.length === 1 && isArray_1.isArray(observables[0])) { + observables = observables[0]; + } + return new ArrayObservable_1.ArrayObservable(observables, scheduler).lift(new combineLatest_1.CombineLatestOperator(project)); +} +exports.combineLatest = combineLatest; + +},{"../operator/combineLatest":573,"../util/isArray":695,"../util/isScheduler":701,"./ArrayObservable":515}],541:[function(require,module,exports){ +"use strict"; +var concat_1 = require('../operator/concat'); +exports.concat = concat_1.concatStatic; + +},{"../operator/concat":574}],542:[function(require,module,exports){ +"use strict"; +var DeferObservable_1 = require('./DeferObservable'); +exports.defer = DeferObservable_1.DeferObservable.create; + +},{"./DeferObservable":519}],543:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var root_1 = require('../../util/root'); +var tryCatch_1 = require('../../util/tryCatch'); +var errorObject_1 = require('../../util/errorObject'); +var Observable_1 = require('../../Observable'); +var Subscriber_1 = require('../../Subscriber'); +function createXHRDefault() { + var xhr = new root_1.root.XMLHttpRequest(); + if (this.crossDomain) { + if ('withCredentials' in xhr) { + xhr.withCredentials = true; + return xhr; + } + else if (!!root_1.root.XDomainRequest) { + return new root_1.root.XDomainRequest(); + } + else { + throw new Error('CORS is not supported by your browser'); + } + } + else { + return xhr; + } +} +function defaultGetResultSelector(response) { + return response.response; +} +function ajaxGet(url, resultSelector, headers) { + if (resultSelector === void 0) { resultSelector = defaultGetResultSelector; } + if (headers === void 0) { headers = null; } + return new AjaxObservable({ method: 'GET', url: url, resultSelector: resultSelector, headers: headers }); +} +exports.ajaxGet = ajaxGet; +; +function ajaxPost(url, body, headers) { + return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers }); +} +exports.ajaxPost = ajaxPost; +; +function ajaxDelete(url, headers) { + return new AjaxObservable({ method: 'DELETE', url: url, headers: headers }); +} +exports.ajaxDelete = ajaxDelete; +; +function ajaxPut(url, body, headers) { + return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers }); +} +exports.ajaxPut = ajaxPut; +; +function ajaxGetJSON(url, resultSelector, headers) { + var finalResultSelector = resultSelector ? function (res) { return resultSelector(res.response); } : function (res) { return res.response; }; + return new AjaxObservable({ method: 'GET', url: url, responseType: 'json', resultSelector: finalResultSelector, headers: headers }); +} +exports.ajaxGetJSON = ajaxGetJSON; +; +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var AjaxObservable = (function (_super) { + __extends(AjaxObservable, _super); + function AjaxObservable(urlOrRequest) { + _super.call(this); + var request = { + async: true, + createXHR: createXHRDefault, + crossDomain: false, + headers: {}, + method: 'GET', + responseType: 'json', + timeout: 0 + }; + if (typeof urlOrRequest === 'string') { + request.url = urlOrRequest; + } + else { + for (var prop in urlOrRequest) { + if (urlOrRequest.hasOwnProperty(prop)) { + request[prop] = urlOrRequest[prop]; + } + } + } + this.request = request; + } + /** + * Creates an observable for an Ajax request with either a request object with + * url, headers, etc or a string for a URL. + * + * @example + * source = Rx.Observable.ajax('/products'); + * source = Rx.Observable.ajax({ url: 'products', method: 'GET' }); + * + * @param {string|Object} request Can be one of the following: + * A string of the URL to make the Ajax call. + * An object with the following properties + * - url: URL of the request + * - body: The body of the request + * - method: Method of the request, such as GET, POST, PUT, PATCH, DELETE + * - async: Whether the request is async + * - headers: Optional headers + * - crossDomain: true if a cross domain request, else false + * - createXHR: a function to override if you need to use an alternate + * XMLHttpRequest implementation. + * - resultSelector: a function to use to alter the output value type of + * the Observable. Gets {@link AjaxResponse} as an argument. + * @return {Observable} An observable sequence containing the XMLHttpRequest. + * @static true + * @name ajax + * @owner Observable + */ + AjaxObservable._create_stub = function () { return null; }; + AjaxObservable.prototype._subscribe = function (subscriber) { + return new AjaxSubscriber(subscriber, this.request); + }; + AjaxObservable.create = (function () { + var create = function (urlOrRequest) { + return new AjaxObservable(urlOrRequest); + }; + create.get = ajaxGet; + create.post = ajaxPost; + create.delete = ajaxDelete; + create.put = ajaxPut; + create.getJSON = ajaxGetJSON; + return create; + })(); + return AjaxObservable; +}(Observable_1.Observable)); +exports.AjaxObservable = AjaxObservable; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var AjaxSubscriber = (function (_super) { + __extends(AjaxSubscriber, _super); + function AjaxSubscriber(destination, request) { + _super.call(this, destination); + this.request = request; + this.done = false; + var headers = request.headers = request.headers || {}; + // force CORS if requested + if (!request.crossDomain && !headers['X-Requested-With']) { + headers['X-Requested-With'] = 'XMLHttpRequest'; + } + // ensure content type is set + if (!('Content-Type' in headers)) { + headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; + } + // properly serialize body + request.body = this.serializeBody(request.body, request.headers['Content-Type']); + this.resultSelector = request.resultSelector; + this.send(); + } + AjaxSubscriber.prototype.next = function (e) { + this.done = true; + var _a = this, resultSelector = _a.resultSelector, xhr = _a.xhr, request = _a.request, destination = _a.destination; + var response = new AjaxResponse(e, xhr, request); + if (resultSelector) { + var result = tryCatch_1.tryCatch(resultSelector)(response); + if (result === errorObject_1.errorObject) { + this.error(errorObject_1.errorObject.e); + } + else { + destination.next(result); + } + } + else { + destination.next(response); + } + }; + AjaxSubscriber.prototype.send = function () { + var _a = this, request = _a.request, _b = _a.request, user = _b.user, method = _b.method, url = _b.url, async = _b.async, password = _b.password, headers = _b.headers, body = _b.body; + var createXHR = request.createXHR; + var xhr = tryCatch_1.tryCatch(createXHR).call(request); + if (xhr === errorObject_1.errorObject) { + this.error(errorObject_1.errorObject.e); + } + else { + this.xhr = xhr; + // open XHR first + var result = void 0; + if (user) { + result = tryCatch_1.tryCatch(xhr.open).call(xhr, method, url, async, user, password); + } + else { + result = tryCatch_1.tryCatch(xhr.open).call(xhr, method, url, async); + } + if (result === errorObject_1.errorObject) { + this.error(errorObject_1.errorObject.e); + return; + } + // timeout and responseType can be set once the XHR is open + xhr.timeout = request.timeout; + xhr.responseType = request.responseType; + // set headers + this.setHeaders(xhr, headers); + // now set up the events + this.setupEvents(xhr, request); + // finally send the request + if (body) { + xhr.send(body); + } + else { + xhr.send(); + } + } + }; + AjaxSubscriber.prototype.serializeBody = function (body, contentType) { + if (!body || typeof body === 'string') { + return body; + } + else if (root_1.root.FormData && body instanceof root_1.root.FormData) { + return body; + } + var splitIndex = contentType.indexOf(';'); + if (splitIndex !== -1) { + contentType = contentType.substring(0, splitIndex); + } + switch (contentType) { + case 'application/x-www-form-urlencoded': + return Object.keys(body).map(function (key) { return (encodeURI(key) + "=" + encodeURI(body[key])); }).join('&'); + case 'application/json': + return JSON.stringify(body); + } + }; + AjaxSubscriber.prototype.setHeaders = function (xhr, headers) { + for (var key in headers) { + if (headers.hasOwnProperty(key)) { + xhr.setRequestHeader(key, headers[key]); + } + } + }; + AjaxSubscriber.prototype.setupEvents = function (xhr, request) { + var progressSubscriber = request.progressSubscriber; + xhr.ontimeout = function xhrTimeout(e) { + var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request; + if (progressSubscriber) { + progressSubscriber.error(e); + } + subscriber.error(new AjaxTimeoutError(this, request)); //TODO: Make betterer. + }; + xhr.ontimeout.request = request; + xhr.ontimeout.subscriber = this; + xhr.ontimeout.progressSubscriber = progressSubscriber; + if (xhr.upload && 'withCredentials' in xhr && root_1.root.XDomainRequest) { + if (progressSubscriber) { + xhr.onprogress = function xhrProgress(e) { + var progressSubscriber = xhrProgress.progressSubscriber; + progressSubscriber.next(e); + }; + xhr.onprogress.progressSubscriber = progressSubscriber; + } + xhr.onerror = function xhrError(e) { + var _a = xhrError, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request; + if (progressSubscriber) { + progressSubscriber.error(e); + } + subscriber.error(new AjaxError('ajax error', this, request)); + }; + xhr.onerror.request = request; + xhr.onerror.subscriber = this; + xhr.onerror.progressSubscriber = progressSubscriber; + } + xhr.onreadystatechange = function xhrReadyStateChange(e) { + var _a = xhrReadyStateChange, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request; + if (this.readyState === 4) { + // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) + var status_1 = this.status === 1223 ? 204 : this.status; + var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response); + // fix status code when it is 0 (0 status is undocumented). + // Occurs when accessing file resources or on Android 4.1 stock browser + // while retrieving files from application cache. + if (status_1 === 0) { + status_1 = response ? 200 : 0; + } + if (200 <= status_1 && status_1 < 300) { + if (progressSubscriber) { + progressSubscriber.complete(); + } + subscriber.next(e); + subscriber.complete(); + } + else { + if (progressSubscriber) { + progressSubscriber.error(e); + } + subscriber.error(new AjaxError('ajax error ' + status_1, this, request)); + } + } + }; + xhr.onreadystatechange.subscriber = this; + xhr.onreadystatechange.progressSubscriber = progressSubscriber; + xhr.onreadystatechange.request = request; + }; + AjaxSubscriber.prototype.unsubscribe = function () { + var _a = this, done = _a.done, xhr = _a.xhr; + if (!done && xhr && xhr.readyState !== 4) { + xhr.abort(); + } + _super.prototype.unsubscribe.call(this); + }; + return AjaxSubscriber; +}(Subscriber_1.Subscriber)); +exports.AjaxSubscriber = AjaxSubscriber; +/** + * A normalized AJAX response. + * + * @see {@link ajax} + * + * @class AjaxResponse + */ +var AjaxResponse = (function () { + function AjaxResponse(originalEvent, xhr, request) { + this.originalEvent = originalEvent; + this.xhr = xhr; + this.request = request; + this.status = xhr.status; + this.responseType = xhr.responseType || request.responseType; + switch (this.responseType) { + case 'json': + if ('response' in xhr) { + //IE does not support json as responseType, parse it internally + this.response = xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || ''); + } + else { + this.response = JSON.parse(xhr.responseText || ''); + } + break; + case 'xml': + this.response = xhr.responseXML; + break; + case 'text': + default: + this.response = ('response' in xhr) ? xhr.response : xhr.responseText; + break; + } + } + return AjaxResponse; +}()); +exports.AjaxResponse = AjaxResponse; +/** + * A normalized AJAX error. + * + * @see {@link ajax} + * + * @class AjaxError + */ +var AjaxError = (function (_super) { + __extends(AjaxError, _super); + function AjaxError(message, xhr, request) { + _super.call(this, message); + this.message = message; + this.xhr = xhr; + this.request = request; + this.status = xhr.status; + } + return AjaxError; +}(Error)); +exports.AjaxError = AjaxError; +/** + * @see {@link ajax} + * + * @class AjaxTimeoutError + */ +var AjaxTimeoutError = (function (_super) { + __extends(AjaxTimeoutError, _super); + function AjaxTimeoutError(xhr, request) { + _super.call(this, 'ajax timeout', xhr, request); + } + return AjaxTimeoutError; +}(AjaxError)); +exports.AjaxTimeoutError = AjaxTimeoutError; + +},{"../../Observable":378,"../../Subscriber":386,"../../util/errorObject":694,"../../util/root":704,"../../util/tryCatch":708}],544:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../../Subject'); +var Subscriber_1 = require('../../Subscriber'); +var Observable_1 = require('../../Observable'); +var Subscription_1 = require('../../Subscription'); +var root_1 = require('../../util/root'); +var ReplaySubject_1 = require('../../ReplaySubject'); +var tryCatch_1 = require('../../util/tryCatch'); +var errorObject_1 = require('../../util/errorObject'); +var assign_1 = require('../../util/assign'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @extends {Ignored} + * @hide true + */ +var WebSocketSubject = (function (_super) { + __extends(WebSocketSubject, _super); + function WebSocketSubject(urlConfigOrSource, destination) { + _super.call(this); + this._output = new Subject_1.Subject(); + this.WebSocketCtor = root_1.root.WebSocket; + if (typeof urlConfigOrSource === 'string') { + this.url = urlConfigOrSource; + } + else { + // WARNING: config object could override important members here. + assign_1.assign(this, urlConfigOrSource); + } + if (!this.WebSocketCtor) { + throw new Error('no WebSocket constructor can be found'); + } + this.destination = new ReplaySubject_1.ReplaySubject(); + } + WebSocketSubject.prototype.resultSelector = function (e) { + return JSON.parse(e.data); + }; + /** + * @param urlConfigOrSource + * @return {WebSocketSubject} + * @static true + * @name webSocket + * @owner Observable + */ + WebSocketSubject.create = function (urlConfigOrSource) { + return new WebSocketSubject(urlConfigOrSource); + }; + WebSocketSubject.prototype.lift = function (operator) { + var sock = new WebSocketSubject(this, this.destination); + sock.operator = operator; + return sock; + }; + // TODO: factor this out to be a proper Operator/Subscriber implementation and eliminate closures + WebSocketSubject.prototype.multiplex = function (subMsg, unsubMsg, messageFilter) { + var self = this; + return new Observable_1.Observable(function (observer) { + var result = tryCatch_1.tryCatch(subMsg)(); + if (result === errorObject_1.errorObject) { + observer.error(errorObject_1.errorObject.e); + } + else { + self.next(result); + } + var subscription = self.subscribe(function (x) { + var result = tryCatch_1.tryCatch(messageFilter)(x); + if (result === errorObject_1.errorObject) { + observer.error(errorObject_1.errorObject.e); + } + else if (result) { + observer.next(x); + } + }, function (err) { return observer.error(err); }, function () { return observer.complete(); }); + return function () { + var result = tryCatch_1.tryCatch(unsubMsg)(); + if (result === errorObject_1.errorObject) { + observer.error(errorObject_1.errorObject.e); + } + else { + self.next(result); + } + subscription.unsubscribe(); + }; + }); + }; + WebSocketSubject.prototype._connectSocket = function () { + var _this = this; + var socket = this.protocol ? new WebSocket(this.url, this.protocol) : new WebSocket(this.url); + this.socket = socket; + var subscription = new Subscription_1.Subscription(function () { + _this.socket = null; + if (socket && socket.readyState === 1) { + socket.close(); + } + }); + var observer = this._output; + socket.onopen = function (e) { + var openObserver = _this.openObserver; + if (openObserver) { + openObserver.next(e); + } + var queue = _this.destination; + _this.destination = Subscriber_1.Subscriber.create(function (x) { return socket.readyState === 1 && socket.send(x); }, function (e) { + var closingObserver = _this.closingObserver; + if (closingObserver) { + closingObserver.next(undefined); + } + if (e && e.code) { + socket.close(e.code, e.reason); + } + else { + observer.error(new TypeError('WebSocketSubject.error must be called with an object with an error code, ' + + 'and an optional reason: { code: number, reason: string }')); + } + _this.destination = new ReplaySubject_1.ReplaySubject(); + _this.socket = null; + }, function () { + var closingObserver = _this.closingObserver; + if (closingObserver) { + closingObserver.next(undefined); + } + socket.close(); + _this.destination = new ReplaySubject_1.ReplaySubject(); + _this.socket = null; + }); + if (queue && queue instanceof ReplaySubject_1.ReplaySubject) { + subscription.add(queue.subscribe(_this.destination)); + } + }; + socket.onerror = function (e) { return observer.error(e); }; + socket.onclose = function (e) { + var closeObserver = _this.closeObserver; + if (closeObserver) { + closeObserver.next(e); + } + if (e.wasClean) { + observer.complete(); + } + else { + observer.error(e); + } + }; + socket.onmessage = function (e) { + var result = tryCatch_1.tryCatch(_this.resultSelector)(e); + if (result === errorObject_1.errorObject) { + observer.error(errorObject_1.errorObject.e); + } + else { + observer.next(result); + } + }; + }; + WebSocketSubject.prototype._subscribe = function (subscriber) { + var _this = this; + if (!this.socket) { + this._connectSocket(); + } + var subscription = new Subscription_1.Subscription(); + subscription.add(this._output.subscribe(subscriber)); + subscription.add(function () { + var socket = _this.socket; + if (socket && socket.readyState === 1) { + socket.close(); + _this.socket = null; + } + }); + return subscription; + }; + WebSocketSubject.prototype.unsubscribe = function () { + var socket = this.socket; + if (socket && socket.readyState === 1) { + socket.close(); + this.socket = null; + } + _super.prototype.unsubscribe.call(this); + this.destination = new ReplaySubject_1.ReplaySubject(); + }; + return WebSocketSubject; +}(Subject_1.AnonymousSubject)); +exports.WebSocketSubject = WebSocketSubject; + +},{"../../Observable":378,"../../ReplaySubject":382,"../../Subject":384,"../../Subscriber":386,"../../Subscription":387,"../../util/assign":693,"../../util/errorObject":694,"../../util/root":704,"../../util/tryCatch":708}],545:[function(require,module,exports){ +"use strict"; +var AjaxObservable_1 = require('./AjaxObservable'); +exports.ajax = AjaxObservable_1.AjaxObservable.create; + +},{"./AjaxObservable":543}],546:[function(require,module,exports){ +"use strict"; +var WebSocketSubject_1 = require('./WebSocketSubject'); +exports.webSocket = WebSocketSubject_1.WebSocketSubject.create; + +},{"./WebSocketSubject":544}],547:[function(require,module,exports){ +"use strict"; +var EmptyObservable_1 = require('./EmptyObservable'); +exports.empty = EmptyObservable_1.EmptyObservable.create; + +},{"./EmptyObservable":520}],548:[function(require,module,exports){ +"use strict"; +var ForkJoinObservable_1 = require('./ForkJoinObservable'); +exports.forkJoin = ForkJoinObservable_1.ForkJoinObservable.create; + +},{"./ForkJoinObservable":522}],549:[function(require,module,exports){ +"use strict"; +var FromObservable_1 = require('./FromObservable'); +exports.from = FromObservable_1.FromObservable.create; + +},{"./FromObservable":525}],550:[function(require,module,exports){ +"use strict"; +var FromEventObservable_1 = require('./FromEventObservable'); +exports.fromEvent = FromEventObservable_1.FromEventObservable.create; + +},{"./FromEventObservable":523}],551:[function(require,module,exports){ +"use strict"; +var FromEventPatternObservable_1 = require('./FromEventPatternObservable'); +exports.fromEventPattern = FromEventPatternObservable_1.FromEventPatternObservable.create; + +},{"./FromEventPatternObservable":524}],552:[function(require,module,exports){ +"use strict"; +var PromiseObservable_1 = require('./PromiseObservable'); +exports.fromPromise = PromiseObservable_1.PromiseObservable.create; + +},{"./PromiseObservable":532}],553:[function(require,module,exports){ +"use strict"; +var IfObservable_1 = require('./IfObservable'); +exports._if = IfObservable_1.IfObservable.create; + +},{"./IfObservable":527}],554:[function(require,module,exports){ +"use strict"; +var IntervalObservable_1 = require('./IntervalObservable'); +exports.interval = IntervalObservable_1.IntervalObservable.create; + +},{"./IntervalObservable":528}],555:[function(require,module,exports){ +"use strict"; +var merge_1 = require('../operator/merge'); +exports.merge = merge_1.mergeStatic; + +},{"../operator/merge":609}],556:[function(require,module,exports){ +"use strict"; +var NeverObservable_1 = require('./NeverObservable'); +exports.never = NeverObservable_1.NeverObservable.create; + +},{"./NeverObservable":531}],557:[function(require,module,exports){ +"use strict"; +var ArrayObservable_1 = require('./ArrayObservable'); +exports.of = ArrayObservable_1.ArrayObservable.of; + +},{"./ArrayObservable":515}],558:[function(require,module,exports){ +"use strict"; +var RangeObservable_1 = require('./RangeObservable'); +exports.range = RangeObservable_1.RangeObservable.create; + +},{"./RangeObservable":533}],559:[function(require,module,exports){ +"use strict"; +var ErrorObservable_1 = require('./ErrorObservable'); +exports._throw = ErrorObservable_1.ErrorObservable.create; + +},{"./ErrorObservable":521}],560:[function(require,module,exports){ +"use strict"; +var TimerObservable_1 = require('./TimerObservable'); +exports.timer = TimerObservable_1.TimerObservable.create; + +},{"./TimerObservable":536}],561:[function(require,module,exports){ +"use strict"; +var UsingObservable_1 = require('./UsingObservable'); +exports.using = UsingObservable_1.UsingObservable.create; + +},{"./UsingObservable":537}],562:[function(require,module,exports){ +"use strict"; +var zip_1 = require('../operator/zip'); +exports.zip = zip_1.zipStatic; + +},{"../operator/zip":661}],563:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Ignores source values for a duration determined by another Observable, then + * emits the most recent value from the source Observable, then repeats this + * process. + * + * It's like {@link auditTime}, but the silencing + * duration is determined by a second Observable. + * + * + * + * `audit` is similar to `throttle`, but emits the last value from the silenced + * time window, instead of the first value. `audit` emits the most recent value + * from the source Observable on the output Observable as soon as its internal + * timer becomes disabled, and ignores source values while the timer is enabled. + * Initially, the timer is disabled. As soon as the first source value arrives, + * the timer is enabled by calling the `durationSelector` function with the + * source value, which returns the "duration" Observable. When the duration + * Observable emits a value or completes, the timer is disabled, then the most + * recent source value is emitted on the output Observable, and this process + * repeats for the next source value. + * + * @example Emit clicks at a rate of at most one click per second + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.audit(ev => Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link auditTime} + * @see {@link debounce} + * @see {@link delayWhen} + * @see {@link sample} + * @see {@link throttle} + * + * @param {function(value: T): Observable|Promise} durationSelector A function + * that receives a value from the source Observable, for computing the silencing + * duration, returned as an Observable or a Promise. + * @return {Observable} An Observable that performs rate-limiting of + * emissions from the source Observable. + * @method audit + * @owner Observable + */ +function audit(durationSelector) { + return this.lift(new AuditOperator(durationSelector)); +} +exports.audit = audit; +var AuditOperator = (function () { + function AuditOperator(durationSelector) { + this.durationSelector = durationSelector; + } + AuditOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new AuditSubscriber(subscriber, this.durationSelector)); + }; + return AuditOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var AuditSubscriber = (function (_super) { + __extends(AuditSubscriber, _super); + function AuditSubscriber(destination, durationSelector) { + _super.call(this, destination); + this.durationSelector = durationSelector; + this.hasValue = false; + } + AuditSubscriber.prototype._next = function (value) { + this.value = value; + this.hasValue = true; + if (!this.throttled) { + var duration = tryCatch_1.tryCatch(this.durationSelector)(value); + if (duration === errorObject_1.errorObject) { + this.destination.error(errorObject_1.errorObject.e); + } + else { + this.add(this.throttled = subscribeToResult_1.subscribeToResult(this, duration)); + } + } + }; + AuditSubscriber.prototype.clearThrottle = function () { + var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled; + if (throttled) { + this.remove(throttled); + this.throttled = null; + throttled.unsubscribe(); + } + if (hasValue) { + this.value = null; + this.hasValue = false; + this.destination.next(value); + } + }; + AuditSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) { + this.clearThrottle(); + }; + AuditSubscriber.prototype.notifyComplete = function () { + this.clearThrottle(); + }; + return AuditSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],564:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var async_1 = require('../scheduler/async'); +var Subscriber_1 = require('../Subscriber'); +/** + * Ignores source values for `duration` milliseconds, then emits the most recent + * value from the source Observable, then repeats this process. + * + * When it sees a source values, it ignores that plus + * the next ones for `duration` milliseconds, and then it emits the most recent + * value from the source. + * + * + * + * `auditTime` is similar to `throttleTime`, but emits the last value from the + * silenced time window, instead of the first value. `auditTime` emits the most + * recent value from the source Observable on the output Observable as soon as + * its internal timer becomes disabled, and ignores source values while the + * timer is enabled. Initially, the timer is disabled. As soon as the first + * source value arrives, the timer is enabled. After `duration` milliseconds (or + * the time unit determined internally by the optional `scheduler`) has passed, + * the timer is disabled, then the most recent source value is emitted on the + * output Observable, and this process repeats for the next source value. + * Optionally takes a {@link Scheduler} for managing timers. + * + * @example Emit clicks at a rate of at most one click per second + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.auditTime(1000); + * result.subscribe(x => console.log(x)); + * + * @see {@link audit} + * @see {@link debounceTime} + * @see {@link delay} + * @see {@link sampleTime} + * @see {@link throttleTime} + * + * @param {number} duration Time to wait before emitting the most recent source + * value, measured in milliseconds or the time unit determined internally + * by the optional `scheduler`. + * @param {Scheduler} [scheduler=async] The {@link Scheduler} to use for + * managing the timers that handle the rate-limiting behavior. + * @return {Observable} An Observable that performs rate-limiting of + * emissions from the source Observable. + * @method auditTime + * @owner Observable + */ +function auditTime(duration, scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new AuditTimeOperator(duration, scheduler)); +} +exports.auditTime = auditTime; +var AuditTimeOperator = (function () { + function AuditTimeOperator(duration, scheduler) { + this.duration = duration; + this.scheduler = scheduler; + } + AuditTimeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new AuditTimeSubscriber(subscriber, this.duration, this.scheduler)); + }; + return AuditTimeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var AuditTimeSubscriber = (function (_super) { + __extends(AuditTimeSubscriber, _super); + function AuditTimeSubscriber(destination, duration, scheduler) { + _super.call(this, destination); + this.duration = duration; + this.scheduler = scheduler; + this.hasValue = false; + } + AuditTimeSubscriber.prototype._next = function (value) { + this.value = value; + this.hasValue = true; + if (!this.throttled) { + this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, this)); + } + }; + AuditTimeSubscriber.prototype.clearThrottle = function () { + var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled; + if (throttled) { + this.remove(throttled); + this.throttled = null; + throttled.unsubscribe(); + } + if (hasValue) { + this.value = null; + this.hasValue = false; + this.destination.next(value); + } + }; + return AuditTimeSubscriber; +}(Subscriber_1.Subscriber)); +function dispatchNext(subscriber) { + subscriber.clearThrottle(); +} + +},{"../Subscriber":386,"../scheduler/async":674}],565:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Buffers the source Observable values until `closingNotifier` emits. + * + * Collects values from the past as an array, and emits + * that array only when another Observable emits. + * + * + * + * Buffers the incoming Observable values until the given `closingNotifier` + * Observable emits a value, at which point it emits the buffer on the output + * Observable and starts a new buffer internally, awaiting the next time + * `closingNotifier` emits. + * + * @example On every click, emit array of most recent interval events + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var interval = Rx.Observable.interval(1000); + * var buffered = interval.buffer(clicks); + * buffered.subscribe(x => console.log(x)); + * + * @see {@link bufferCount} + * @see {@link bufferTime} + * @see {@link bufferToggle} + * @see {@link bufferWhen} + * @see {@link window} + * + * @param {Observable} closingNotifier An Observable that signals the + * buffer to be emitted on the output Observable. + * @return {Observable} An Observable of buffers, which are arrays of + * values. + * @method buffer + * @owner Observable + */ +function buffer(closingNotifier) { + return this.lift(new BufferOperator(closingNotifier)); +} +exports.buffer = buffer; +var BufferOperator = (function () { + function BufferOperator(closingNotifier) { + this.closingNotifier = closingNotifier; + } + BufferOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new BufferSubscriber(subscriber, this.closingNotifier)); + }; + return BufferOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var BufferSubscriber = (function (_super) { + __extends(BufferSubscriber, _super); + function BufferSubscriber(destination, closingNotifier) { + _super.call(this, destination); + this.buffer = []; + this.add(subscribeToResult_1.subscribeToResult(this, closingNotifier)); + } + BufferSubscriber.prototype._next = function (value) { + this.buffer.push(value); + }; + BufferSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var buffer = this.buffer; + this.buffer = []; + this.destination.next(buffer); + }; + return BufferSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],566:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Buffers the source Observable values until the size hits the maximum + * `bufferSize` given. + * + * Collects values from the past as an array, and emits + * that array only when its size reaches `bufferSize`. + * + * + * + * Buffers a number of values from the source Observable by `bufferSize` then + * emits the buffer and clears it, and starts a new buffer each + * `startBufferEvery` values. If `startBufferEvery` is not provided or is + * `null`, then new buffers are started immediately at the start of the source + * and when each buffer closes and is emitted. + * + * @example Emit the last two click events as an array + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var buffered = clicks.bufferCount(2); + * buffered.subscribe(x => console.log(x)); + * + * @example On every click, emit the last two click events as an array + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var buffered = clicks.bufferCount(2, 1); + * buffered.subscribe(x => console.log(x)); + * + * @see {@link buffer} + * @see {@link bufferTime} + * @see {@link bufferToggle} + * @see {@link bufferWhen} + * @see {@link pairwise} + * @see {@link windowCount} + * + * @param {number} bufferSize The maximum size of the buffer emitted. + * @param {number} [startBufferEvery] Interval at which to start a new buffer. + * For example if `startBufferEvery` is `2`, then a new buffer will be started + * on every other value from the source. A new buffer is started at the + * beginning of the source by default. + * @return {Observable} An Observable of arrays of buffered values. + * @method bufferCount + * @owner Observable + */ +function bufferCount(bufferSize, startBufferEvery) { + if (startBufferEvery === void 0) { startBufferEvery = null; } + return this.lift(new BufferCountOperator(bufferSize, startBufferEvery)); +} +exports.bufferCount = bufferCount; +var BufferCountOperator = (function () { + function BufferCountOperator(bufferSize, startBufferEvery) { + this.bufferSize = bufferSize; + this.startBufferEvery = startBufferEvery; + } + BufferCountOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new BufferCountSubscriber(subscriber, this.bufferSize, this.startBufferEvery)); + }; + return BufferCountOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var BufferCountSubscriber = (function (_super) { + __extends(BufferCountSubscriber, _super); + function BufferCountSubscriber(destination, bufferSize, startBufferEvery) { + _super.call(this, destination); + this.bufferSize = bufferSize; + this.startBufferEvery = startBufferEvery; + this.buffers = [[]]; + this.count = 0; + } + BufferCountSubscriber.prototype._next = function (value) { + var count = (this.count += 1); + var destination = this.destination; + var bufferSize = this.bufferSize; + var startBufferEvery = (this.startBufferEvery == null) ? bufferSize : this.startBufferEvery; + var buffers = this.buffers; + var len = buffers.length; + var remove = -1; + if (count % startBufferEvery === 0) { + buffers.push([]); + } + for (var i = 0; i < len; i++) { + var buffer = buffers[i]; + buffer.push(value); + if (buffer.length === bufferSize) { + remove = i; + destination.next(buffer); + } + } + if (remove !== -1) { + buffers.splice(remove, 1); + } + }; + BufferCountSubscriber.prototype._complete = function () { + var destination = this.destination; + var buffers = this.buffers; + while (buffers.length > 0) { + var buffer = buffers.shift(); + if (buffer.length > 0) { + destination.next(buffer); + } + } + _super.prototype._complete.call(this); + }; + return BufferCountSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],567:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var async_1 = require('../scheduler/async'); +var isScheduler_1 = require('../util/isScheduler'); +/** + * Buffers the source Observable values for a specific time period. + * + * Collects values from the past as an array, and emits + * those arrays periodically in time. + * + * + * + * Buffers values from the source for a specific time duration `bufferTimeSpan`. + * Unless the optional argument `bufferCreationInterval` is given, it emits and + * resets the buffer every `bufferTimeSpan` milliseconds. If + * `bufferCreationInterval` is given, this operator opens the buffer every + * `bufferCreationInterval` milliseconds and closes (emits and resets) the + * buffer every `bufferTimeSpan` milliseconds. When the optional argument + * `maxBufferSize` is specified, the buffer will be closed either after + * `bufferTimeSpan` milliseconds or when it contains `maxBufferSize` elements. + * + * @example Every second, emit an array of the recent click events + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var buffered = clicks.bufferTime(1000); + * buffered.subscribe(x => console.log(x)); + * + * @example Every 5 seconds, emit the click events from the next 2 seconds + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var buffered = clicks.bufferTime(2000, 5000); + * buffered.subscribe(x => console.log(x)); + * + * @see {@link buffer} + * @see {@link bufferCount} + * @see {@link bufferToggle} + * @see {@link bufferWhen} + * @see {@link windowTime} + * + * @param {number} bufferTimeSpan The amount of time to fill each buffer array. + * @param {number} [bufferCreationInterval] The interval at which to start new + * buffers. + * @param {number} [maxBufferSize] The maximum buffer size. + * @param {Scheduler} [scheduler=async] The scheduler on which to schedule the + * intervals that determine buffer boundaries. + * @return {Observable} An observable of arrays of buffered values. + * @method bufferTime + * @owner Observable + */ +function bufferTime(bufferTimeSpan) { + var length = arguments.length; + var scheduler = async_1.async; + if (isScheduler_1.isScheduler(arguments[arguments.length - 1])) { + scheduler = arguments[arguments.length - 1]; + length--; + } + var bufferCreationInterval = null; + if (length >= 2) { + bufferCreationInterval = arguments[1]; + } + var maxBufferSize = Number.POSITIVE_INFINITY; + if (length >= 3) { + maxBufferSize = arguments[2]; + } + return this.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler)); +} +exports.bufferTime = bufferTime; +var BufferTimeOperator = (function () { + function BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) { + this.bufferTimeSpan = bufferTimeSpan; + this.bufferCreationInterval = bufferCreationInterval; + this.maxBufferSize = maxBufferSize; + this.scheduler = scheduler; + } + BufferTimeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new BufferTimeSubscriber(subscriber, this.bufferTimeSpan, this.bufferCreationInterval, this.maxBufferSize, this.scheduler)); + }; + return BufferTimeOperator; +}()); +var Context = (function () { + function Context() { + this.buffer = []; + } + return Context; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var BufferTimeSubscriber = (function (_super) { + __extends(BufferTimeSubscriber, _super); + function BufferTimeSubscriber(destination, bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) { + _super.call(this, destination); + this.bufferTimeSpan = bufferTimeSpan; + this.bufferCreationInterval = bufferCreationInterval; + this.maxBufferSize = maxBufferSize; + this.scheduler = scheduler; + this.contexts = []; + var context = this.openContext(); + this.timespanOnly = bufferCreationInterval == null || bufferCreationInterval < 0; + if (this.timespanOnly) { + var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan }; + this.add(context.closeAction = scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState)); + } + else { + var closeState = { subscriber: this, context: context }; + var creationState = { bufferTimeSpan: bufferTimeSpan, bufferCreationInterval: bufferCreationInterval, subscriber: this, scheduler: scheduler }; + this.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, closeState)); + this.add(scheduler.schedule(dispatchBufferCreation, bufferCreationInterval, creationState)); + } + } + BufferTimeSubscriber.prototype._next = function (value) { + var contexts = this.contexts; + var len = contexts.length; + var filledBufferContext; + for (var i = 0; i < len; i++) { + var context = contexts[i]; + var buffer = context.buffer; + buffer.push(value); + if (buffer.length == this.maxBufferSize) { + filledBufferContext = context; + } + } + if (filledBufferContext) { + this.onBufferFull(filledBufferContext); + } + }; + BufferTimeSubscriber.prototype._error = function (err) { + this.contexts.length = 0; + _super.prototype._error.call(this, err); + }; + BufferTimeSubscriber.prototype._complete = function () { + var _a = this, contexts = _a.contexts, destination = _a.destination; + while (contexts.length > 0) { + var context = contexts.shift(); + destination.next(context.buffer); + } + _super.prototype._complete.call(this); + }; + BufferTimeSubscriber.prototype._unsubscribe = function () { + this.contexts = null; + }; + BufferTimeSubscriber.prototype.onBufferFull = function (context) { + this.closeContext(context); + var closeAction = context.closeAction; + closeAction.unsubscribe(); + this.remove(closeAction); + if (this.timespanOnly) { + context = this.openContext(); + var bufferTimeSpan = this.bufferTimeSpan; + var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan }; + this.add(context.closeAction = this.scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState)); + } + }; + BufferTimeSubscriber.prototype.openContext = function () { + var context = new Context(); + this.contexts.push(context); + return context; + }; + BufferTimeSubscriber.prototype.closeContext = function (context) { + this.destination.next(context.buffer); + var contexts = this.contexts; + contexts.splice(contexts.indexOf(context), 1); + }; + return BufferTimeSubscriber; +}(Subscriber_1.Subscriber)); +function dispatchBufferTimeSpanOnly(state) { + var subscriber = state.subscriber; + var prevContext = state.context; + if (prevContext) { + subscriber.closeContext(prevContext); + } + state.context = subscriber.openContext(); + if (!subscriber.isUnsubscribed) { + state.context.closeAction = this.schedule(state, state.bufferTimeSpan); + } +} +function dispatchBufferCreation(state) { + var bufferCreationInterval = state.bufferCreationInterval, bufferTimeSpan = state.bufferTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler; + var context = subscriber.openContext(); + var action = this; + if (!subscriber.isUnsubscribed) { + subscriber.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, { subscriber: subscriber, context: context })); + action.schedule(state, bufferCreationInterval); + } +} +function dispatchBufferClose(arg) { + var subscriber = arg.subscriber, context = arg.context; + subscriber.closeContext(context); +} + +},{"../Subscriber":386,"../scheduler/async":674,"../util/isScheduler":701}],568:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscription_1 = require('../Subscription'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * Buffers the source Observable values starting from an emission from + * `openings` and ending when the output of `closingSelector` emits. + * + * Collects values from the past as an array. Starts + * collecting only when `opening` emits, and calls the `closingSelector` + * function to get an Observable that tells when to close the buffer. + * + * + * + * Buffers values from the source by opening the buffer via signals from an + * Observable provided to `openings`, and closing and sending the buffers when + * a Subscribable or Promise returned by the `closingSelector` function emits. + * + * @example Every other second, emit the click events from the next 500ms + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var openings = Rx.Observable.interval(1000); + * var buffered = clicks.bufferToggle(openings, i => + * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty() + * ); + * buffered.subscribe(x => console.log(x)); + * + * @see {@link buffer} + * @see {@link bufferCount} + * @see {@link bufferTime} + * @see {@link bufferWhen} + * @see {@link windowToggle} + * + * @param {SubscribableOrPromise} openings A Subscribable or Promise of notifications to start new + * buffers. + * @param {function(value: O): SubscribableOrPromise} closingSelector A function that takes + * the value emitted by the `openings` observable and returns a Subscribable or Promise, + * which, when it emits, signals that the associated buffer should be emitted + * and cleared. + * @return {Observable} An observable of arrays of buffered values. + * @method bufferToggle + * @owner Observable + */ +function bufferToggle(openings, closingSelector) { + return this.lift(new BufferToggleOperator(openings, closingSelector)); +} +exports.bufferToggle = bufferToggle; +var BufferToggleOperator = (function () { + function BufferToggleOperator(openings, closingSelector) { + this.openings = openings; + this.closingSelector = closingSelector; + } + BufferToggleOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector)); + }; + return BufferToggleOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var BufferToggleSubscriber = (function (_super) { + __extends(BufferToggleSubscriber, _super); + function BufferToggleSubscriber(destination, openings, closingSelector) { + _super.call(this, destination); + this.openings = openings; + this.closingSelector = closingSelector; + this.contexts = []; + this.add(subscribeToResult_1.subscribeToResult(this, openings)); + } + BufferToggleSubscriber.prototype._next = function (value) { + var contexts = this.contexts; + var len = contexts.length; + for (var i = 0; i < len; i++) { + contexts[i].buffer.push(value); + } + }; + BufferToggleSubscriber.prototype._error = function (err) { + var contexts = this.contexts; + while (contexts.length > 0) { + var context = contexts.shift(); + context.subscription.unsubscribe(); + context.buffer = null; + context.subscription = null; + } + this.contexts = null; + _super.prototype._error.call(this, err); + }; + BufferToggleSubscriber.prototype._complete = function () { + var contexts = this.contexts; + while (contexts.length > 0) { + var context = contexts.shift(); + this.destination.next(context.buffer); + context.subscription.unsubscribe(); + context.buffer = null; + context.subscription = null; + } + this.contexts = null; + _super.prototype._complete.call(this); + }; + BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue); + }; + BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) { + this.closeBuffer(innerSub.context); + }; + BufferToggleSubscriber.prototype.openBuffer = function (value) { + try { + var closingSelector = this.closingSelector; + var closingNotifier = closingSelector.call(this, value); + if (closingNotifier) { + this.trySubscribe(closingNotifier); + } + } + catch (err) { + this._error(err); + } + }; + BufferToggleSubscriber.prototype.closeBuffer = function (context) { + var contexts = this.contexts; + if (contexts && context) { + var buffer = context.buffer, subscription = context.subscription; + this.destination.next(buffer); + contexts.splice(contexts.indexOf(context), 1); + this.remove(subscription); + subscription.unsubscribe(); + } + }; + BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) { + var contexts = this.contexts; + var buffer = []; + var subscription = new Subscription_1.Subscription(); + var context = { buffer: buffer, subscription: subscription }; + contexts.push(context); + var innerSubscription = subscribeToResult_1.subscribeToResult(this, closingNotifier, context); + if (!innerSubscription || innerSubscription.isUnsubscribed) { + this.closeBuffer(context); + } + else { + innerSubscription.context = context; + this.add(innerSubscription); + subscription.add(innerSubscription); + } + }; + return BufferToggleSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subscription":387,"../util/subscribeToResult":705}],569:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscription_1 = require('../Subscription'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Buffers the source Observable values, using a factory function of closing + * Observables to determine when to close, emit, and reset the buffer. + * + * Collects values from the past as an array. When it + * starts collecting values, it calls a function that returns an Observable that + * tells when to close the buffer and restart collecting. + * + * + * + * Opens a buffer immediately, then closes the buffer when the observable + * returned by calling `closingSelector` function emits a value. When it closes + * the buffer, it immediately opens a new buffer and repeats the process. + * + * @example Emit an array of the last clicks every [1-5] random seconds + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var buffered = clicks.bufferWhen(() => + * Rx.Observable.interval(1000 + Math.random() * 4000) + * ); + * buffered.subscribe(x => console.log(x)); + * + * @see {@link buffer} + * @see {@link bufferCount} + * @see {@link bufferTime} + * @see {@link bufferToggle} + * @see {@link windowWhen} + * + * @param {function(): Observable} closingSelector A function that takes no + * arguments and returns an Observable that signals buffer closure. + * @return {Observable} An observable of arrays of buffered values. + * @method bufferWhen + * @owner Observable + */ +function bufferWhen(closingSelector) { + return this.lift(new BufferWhenOperator(closingSelector)); +} +exports.bufferWhen = bufferWhen; +var BufferWhenOperator = (function () { + function BufferWhenOperator(closingSelector) { + this.closingSelector = closingSelector; + } + BufferWhenOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector)); + }; + return BufferWhenOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var BufferWhenSubscriber = (function (_super) { + __extends(BufferWhenSubscriber, _super); + function BufferWhenSubscriber(destination, closingSelector) { + _super.call(this, destination); + this.closingSelector = closingSelector; + this.subscribing = false; + this.openBuffer(); + } + BufferWhenSubscriber.prototype._next = function (value) { + this.buffer.push(value); + }; + BufferWhenSubscriber.prototype._complete = function () { + var buffer = this.buffer; + if (buffer) { + this.destination.next(buffer); + } + _super.prototype._complete.call(this); + }; + BufferWhenSubscriber.prototype._unsubscribe = function () { + this.buffer = null; + this.subscribing = false; + }; + BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.openBuffer(); + }; + BufferWhenSubscriber.prototype.notifyComplete = function () { + if (this.subscribing) { + this.complete(); + } + else { + this.openBuffer(); + } + }; + BufferWhenSubscriber.prototype.openBuffer = function () { + var closingSubscription = this.closingSubscription; + if (closingSubscription) { + this.remove(closingSubscription); + closingSubscription.unsubscribe(); + } + var buffer = this.buffer; + if (this.buffer) { + this.destination.next(buffer); + } + this.buffer = []; + var closingNotifier = tryCatch_1.tryCatch(this.closingSelector)(); + if (closingNotifier === errorObject_1.errorObject) { + this.error(errorObject_1.errorObject.e); + } + else { + closingSubscription = new Subscription_1.Subscription(); + this.closingSubscription = closingSubscription; + this.add(closingSubscription); + this.subscribing = true; + closingSubscription.add(subscribeToResult_1.subscribeToResult(this, closingNotifier)); + this.subscribing = false; + } + }; + return BufferWhenSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subscription":387,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],570:[function(require,module,exports){ +"use strict"; +var publishReplay_1 = require('./publishReplay'); +/** + * @param bufferSize + * @param windowTime + * @param scheduler + * @return {Observable} + * @method cache + * @owner Observable + */ +function cache(bufferSize, windowTime, scheduler) { + if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; } + if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; } + return publishReplay_1.publishReplay.call(this, bufferSize, windowTime, scheduler).refCount(); +} +exports.cache = cache; + +},{"./publishReplay":624}],571:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Catches errors on the observable to be handled by returning a new observable or throwing an error. + * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which + * is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable + * is returned by the `selector` will be used to continue the observable chain. + * @return {Observable} an observable that originates from either the source or the observable returned by the + * catch `selector` function. + * @method catch + * @owner Observable + */ +function _catch(selector) { + var operator = new CatchOperator(selector); + var caught = this.lift(operator); + return (operator.caught = caught); +} +exports._catch = _catch; +var CatchOperator = (function () { + function CatchOperator(selector) { + this.selector = selector; + } + CatchOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new CatchSubscriber(subscriber, this.selector, this.caught)); + }; + return CatchOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var CatchSubscriber = (function (_super) { + __extends(CatchSubscriber, _super); + function CatchSubscriber(destination, selector, caught) { + _super.call(this, destination); + this.selector = selector; + this.caught = caught; + } + // NOTE: overriding `error` instead of `_error` because we don't want + // to have this flag this subscriber as `isStopped`. + CatchSubscriber.prototype.error = function (err) { + if (!this.isStopped) { + var result = void 0; + try { + result = this.selector(err, this.caught); + } + catch (err) { + this.destination.error(err); + return; + } + this._innerSub(result); + } + }; + CatchSubscriber.prototype._innerSub = function (result) { + this.unsubscribe(); + this.destination.remove(this); + result.subscribe(this.destination); + }; + return CatchSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],572:[function(require,module,exports){ +"use strict"; +var combineLatest_1 = require('./combineLatest'); +/** + * Converts a higher-order Observable into a first-order Observable by waiting + * for the outer Observable to complete, then applying {@link combineLatest}. + * + * Flattens an Observable-of-Observables by applying + * {@link combineLatest} when the Observable-of-Observables completes. + * + * + * + * Takes an Observable of Observables, and collects all Observables from it. + * Once the outer Observable completes, it subscribes to all collected + * Observables and combines their values using the {@link combineLatest} + * strategy, such that: + * - Every time an inner Observable emits, the output Observable emits. + * - When the returned observable emits, it emits all of the latest values by: + * - If a `project` function is provided, it is called with each recent value + * from each inner Observable in whatever order they arrived, and the result + * of the `project` function is what is emitted by the output Observable. + * - If there is no `project` function, an array of all of the most recent + * values is emitted by the output Observable. + * + * @example Map two click events to a finite interval Observable, then apply combineAll + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var higherOrder = clicks.map(ev => + * Rx.Observable.interval(Math.random()*2000).take(3) + * ).take(2); + * var result = higherOrder.combineAll(); + * result.subscribe(x => console.log(x)); + * + * @see {@link combineLatest} + * @see {@link mergeAll} + * + * @param {function} [project] An optional function to map the most recent + * values from each inner Observable into a new result. Takes each of the most + * recent values from each collected inner Observable as arguments, in order. + * @return {Observable} An Observable of projected results or arrays of recent + * values. + * @method combineAll + * @owner Observable + */ +function combineAll(project) { + return this.lift(new combineLatest_1.CombineLatestOperator(project)); +} +exports.combineAll = combineAll; + +},{"./combineLatest":573}],573:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var ArrayObservable_1 = require('../observable/ArrayObservable'); +var isArray_1 = require('../util/isArray'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var none = {}; +/** + * Combines multiple Observables to create an Observable whose values are + * calculated from the latest values of each of its input Observables. + * + * Whenever any input Observable emits a value, it + * computes a formula using the latest values from all the inputs, then emits + * the output of that formula. + * + * + * + * `combineLatest` combines the values from this Observable with values from + * Observables passed as arguments. This is done by subscribing to each + * Observable, in order, and collecting an array of each of the most recent + * values any time any of the input Observables emits, then either taking that + * array and passing it as arguments to an optional `project` function and + * emitting the return value of that, or just emitting the array of recent + * values directly if there is no `project` function. + * + * @example Dynamically calculate the Body-Mass Index from an Observable of weight and one for height + * var weight = Rx.Observable.of(70, 72, 76, 79, 75); + * var height = Rx.Observable.of(1.76, 1.77, 1.78); + * var bmi = weight.combineLatest(height, (w, h) => w / (h * h)); + * bmi.subscribe(x => console.log('BMI is ' + x)); + * + * @see {@link combineAll} + * @see {@link merge} + * @see {@link withLatestFrom} + * + * @param {Observable} other An input Observable to combine with the source + * Observable. More than one input Observables may be given as argument. + * @param {function} [project] An optional function to project the values from + * the combined latest values into a new value on the output Observable. + * @return {Observable} An Observable of projected values from the most recent + * values from each input Observable, or an array of the most recent values from + * each input Observable. + * @method combineLatest + * @owner Observable + */ +function combineLatest() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + var project = null; + if (typeof observables[observables.length - 1] === 'function') { + project = observables.pop(); + } + // if the first and only other argument besides the resultSelector is an array + // assume it's been called with `combineLatest([obs1, obs2, obs3], project)` + if (observables.length === 1 && isArray_1.isArray(observables[0])) { + observables = observables[0]; + } + observables.unshift(this); + return new ArrayObservable_1.ArrayObservable(observables).lift(new CombineLatestOperator(project)); +} +exports.combineLatest = combineLatest; +/* tslint:enable:max-line-length */ +var CombineLatestOperator = (function () { + function CombineLatestOperator(project) { + this.project = project; + } + CombineLatestOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new CombineLatestSubscriber(subscriber, this.project)); + }; + return CombineLatestOperator; +}()); +exports.CombineLatestOperator = CombineLatestOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var CombineLatestSubscriber = (function (_super) { + __extends(CombineLatestSubscriber, _super); + function CombineLatestSubscriber(destination, project) { + _super.call(this, destination); + this.project = project; + this.active = 0; + this.values = []; + this.observables = []; + } + CombineLatestSubscriber.prototype._next = function (observable) { + this.values.push(none); + this.observables.push(observable); + }; + CombineLatestSubscriber.prototype._complete = function () { + var observables = this.observables; + var len = observables.length; + if (len === 0) { + this.destination.complete(); + } + else { + this.active = len; + this.toRespond = len; + for (var i = 0; i < len; i++) { + var observable = observables[i]; + this.add(subscribeToResult_1.subscribeToResult(this, observable, observable, i)); + } + } + }; + CombineLatestSubscriber.prototype.notifyComplete = function (unused) { + if ((this.active -= 1) === 0) { + this.destination.complete(); + } + }; + CombineLatestSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var values = this.values; + var oldVal = values[outerIndex]; + var toRespond = !this.toRespond + ? 0 + : oldVal === none ? --this.toRespond : this.toRespond; + values[outerIndex] = innerValue; + if (toRespond === 0) { + if (this.project) { + this._tryProject(values); + } + else { + this.destination.next(values); + } + } + }; + CombineLatestSubscriber.prototype._tryProject = function (values) { + var result; + try { + result = this.project.apply(this, values); + } + catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + }; + return CombineLatestSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.CombineLatestSubscriber = CombineLatestSubscriber; + +},{"../OuterSubscriber":381,"../observable/ArrayObservable":515,"../util/isArray":695,"../util/subscribeToResult":705}],574:[function(require,module,exports){ +"use strict"; +var isScheduler_1 = require('../util/isScheduler'); +var ArrayObservable_1 = require('../observable/ArrayObservable'); +var mergeAll_1 = require('./mergeAll'); +/** + * Creates an output Observable which sequentially emits all values from every + * given input Observable after the current Observable. + * + * Concatenates multiple Observables together by + * sequentially emitting their values, one Observable after the other. + * + * + * + * Joins this Observable with multiple other Observables by subscribing to them + * one at a time, starting with the source, and merging their results into the + * output Observable. Will wait for each Observable to complete before moving + * on to the next. + * + * @example Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 + * var timer = Rx.Observable.interval(1000).take(4); + * var sequence = Rx.Observable.range(1, 10); + * var result = timer.concat(sequence); + * result.subscribe(x => console.log(x)); + * + * @example Concatenate 3 Observables + * var timer1 = Rx.Observable.interval(1000).take(10); + * var timer2 = Rx.Observable.interval(2000).take(6); + * var timer3 = Rx.Observable.interval(500).take(10); + * var result = timer1.concat(timer2, timer3); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatAll} + * @see {@link concatMap} + * @see {@link concatMapTo} + * + * @param {Observable} other An input Observable to concatenate after the source + * Observable. More than one input Observables may be given as argument. + * @param {Scheduler} [scheduler=null] An optional Scheduler to schedule each + * Observable subscription on. + * @return {Observable} All values of each passed Observable merged into a + * single Observable, in order, in serial fashion. + * @method concat + * @owner Observable + */ +function concat() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + return concatStatic.apply(void 0, [this].concat(observables)); +} +exports.concat = concat; +/* tslint:enable:max-line-length */ +/** + * Creates an output Observable which sequentially emits all values from every + * given input Observable after the current Observable. + * + * Concatenates multiple Observables together by + * sequentially emitting their values, one Observable after the other. + * + * + * + * Joins multiple Observables together by subscribing to them one at a time and + * merging their results into the output Observable. Will wait for each + * Observable to complete before moving on to the next. + * + * @example Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 + * var timer = Rx.Observable.interval(1000).take(4); + * var sequence = Rx.Observable.range(1, 10); + * var result = Rx.Observable.concat(timer, sequence); + * result.subscribe(x => console.log(x)); + * + * @example Concatenate 3 Observables + * var timer1 = Rx.Observable.interval(1000).take(10); + * var timer2 = Rx.Observable.interval(2000).take(6); + * var timer3 = Rx.Observable.interval(500).take(10); + * var result = Rx.Observable.concat(timer1, timer2, timer3); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatAll} + * @see {@link concatMap} + * @see {@link concatMapTo} + * + * @param {Observable} input1 An input Observable to concatenate with others. + * @param {Observable} input2 An input Observable to concatenate with others. + * More than one input Observables may be given as argument. + * @param {Scheduler} [scheduler=null] An optional Scheduler to schedule each + * Observable subscription on. + * @return {Observable} All values of each passed Observable merged into a + * single Observable, in order, in serial fashion. + * @static true + * @name concat + * @owner Observable + */ +function concatStatic() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + var scheduler = null; + var args = observables; + if (isScheduler_1.isScheduler(args[observables.length - 1])) { + scheduler = args.pop(); + } + return new ArrayObservable_1.ArrayObservable(observables, scheduler).lift(new mergeAll_1.MergeAllOperator(1)); +} +exports.concatStatic = concatStatic; + +},{"../observable/ArrayObservable":515,"../util/isScheduler":701,"./mergeAll":610}],575:[function(require,module,exports){ +"use strict"; +var mergeAll_1 = require('./mergeAll'); +/** + * Converts a higher-order Observable into a first-order Observable by + * concatenating the inner Observables in order. + * + * Flattens an Observable-of-Observables by putting one + * inner Observable after the other. + * + * + * + * Joins every Observable emitted by the source (a higher-order Observable), in + * a serial fashion. It subscribes to each inner Observable only after the + * previous inner Observable has completed, and merges all of their values into + * the returned observable. + * + * __Warning:__ If the source Observable emits Observables quickly and + * endlessly, and the inner Observables it emits generally complete slower than + * the source emits, you can run into memory issues as the incoming Observables + * collect in an unbounded buffer. + * + * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set + * to `1`. + * + * @example For each click event, tick every second from 0 to 3, with no concurrency + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var higherOrder = clicks.map(ev => Rx.Observable.interval(1000).take(4)); + * var firstOrder = higherOrder.concatAll(); + * firstOrder.subscribe(x => console.log(x)); + * + * @see {@link combineAll} + * @see {@link concat} + * @see {@link concatMap} + * @see {@link concatMapTo} + * @see {@link exhaust} + * @see {@link mergeAll} + * @see {@link switch} + * @see {@link zipAll} + * + * @return {Observable} An Observable emitting values from all the inner + * Observables concatenated. + * @method concatAll + * @owner Observable + */ +function concatAll() { + return this.lift(new mergeAll_1.MergeAllOperator(1)); +} +exports.concatAll = concatAll; + +},{"./mergeAll":610}],576:[function(require,module,exports){ +"use strict"; +var mergeMap_1 = require('./mergeMap'); +/** + * Projects each source value to an Observable which is merged in the output + * Observable, in a serialized fashion waiting for each one to complete before + * merging the next. + * + * Maps each value to an Observable, then flattens all of + * these inner Observables using {@link concatAll}. + * + * + * + * Returns an Observable that emits items based on applying a function that you + * supply to each item emitted by the source Observable, where that function + * returns an (so-called "inner") Observable. Each new inner Observable is + * concatenated with the previous inner Observable. + * + * __Warning:__ if source values arrive endlessly and faster than their + * corresponding inner Observables can complete, it will result in memory issues + * as inner Observables amass in an unbounded buffer waiting for their turn to + * be subscribed to. + * + * Note: `concatMap` is equivalent to `mergeMap` with concurrency parameter set + * to `1`. + * + * @example For each click event, tick every second from 0 to 3, with no concurrency + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.concatMap(ev => Rx.Observable.interval(1000).take(4)); + * result.subscribe(x => console.log(x)); + * + * @see {@link concat} + * @see {@link concatAll} + * @see {@link concatMapTo} + * @see {@link exhaustMap} + * @see {@link mergeMap} + * @see {@link switchMap} + * + * @param {function(value: T, ?index: number): Observable} project A function + * that, when applied to an item emitted by the source Observable, returns an + * Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @return {Observable} an observable of values merged from the projected + * Observables as they were subscribed to, one at a time. Optionally, these + * values may have been projected from a passed `projectResult` argument. + * @return {Observable} An Observable that emits the result of applying the + * projection function (and the optional `resultSelector`) to each item emitted + * by the source Observable and taking values from each projected inner + * Observable sequentially. + * @method concatMap + * @owner Observable + */ +function concatMap(project, resultSelector) { + return this.lift(new mergeMap_1.MergeMapOperator(project, resultSelector, 1)); +} +exports.concatMap = concatMap; + +},{"./mergeMap":611}],577:[function(require,module,exports){ +"use strict"; +var mergeMapTo_1 = require('./mergeMapTo'); +/** + * Projects each source value to the same Observable which is merged multiple + * times in a serialized fashion on the output Observable. + * + * It's like {@link concatMap}, but maps each value + * always to the same inner Observable. + * + * + * + * Maps each source value to the given Observable `innerObservable` regardless + * of the source value, and then flattens those resulting Observables into one + * single Observable, which is the output Observable. Each new `innerObservable` + * instance emitted on the output Observable is concatenated with the previous + * `innerObservable` instance. + * + * __Warning:__ if source values arrive endlessly and faster than their + * corresponding inner Observables can complete, it will result in memory issues + * as inner Observables amass in an unbounded buffer waiting for their turn to + * be subscribed to. + * + * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter + * set to `1`. + * + * @example For each click event, tick every second from 0 to 3, with no concurrency + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.concatMapTo(Rx.Observable.interval(1000).take(4)); + * result.subscribe(x => console.log(x)); + * + * @see {@link concat} + * @see {@link concatAll} + * @see {@link concatMap} + * @see {@link mergeMapTo} + * @see {@link switchMapTo} + * + * @param {Observable} innerObservable An Observable to replace each value from + * the source Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @return {Observable} An observable of values merged together by joining the + * passed observable with itself, one after the other, for each value emitted + * from the source. + * @method concatMapTo + * @owner Observable + */ +function concatMapTo(innerObservable, resultSelector) { + return this.lift(new mergeMapTo_1.MergeMapToOperator(innerObservable, resultSelector, 1)); +} +exports.concatMapTo = concatMapTo; + +},{"./mergeMapTo":612}],578:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Counts the number of emissions on the source and emits that number when the + * source completes. + * + * Tells how many values were emitted, when the source + * completes. + * + * + * + * `count` transforms an Observable that emits values into an Observable that + * emits a single value that represents the number of values emitted by the + * source Observable. If the source Observable terminates with an error, `count` + * will pass this error notification along without emitting an value first. If + * the source Observable does not terminate at all, `count` will neither emit + * a value nor terminate. This operator takes an optional `predicate` function + * as argument, in which case the output emission will represent the number of + * source values that matched `true` with the `predicate`. + * + * @example Counts how many seconds have passed before the first click happened + * var seconds = Rx.Observable.interval(1000); + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var secondsBeforeClick = seconds.takeUntil(clicks); + * var result = secondsBeforeClick.count(); + * result.subscribe(x => console.log(x)); + * + * @example Counts how many odd numbers are there between 1 and 7 + * var numbers = Rx.Observable.range(1, 7); + * var result = numbers.count(i => i % 2 === 1); + * result.subscribe(x => console.log(x)); + * + * @see {@link max} + * @see {@link min} + * @see {@link reduce} + * + * @param {function(value: T, i: number, source: Observable): boolean} [predicate] A + * boolean function to select what values are to be counted. It is provided with + * arguments of: + * - `value`: the value from the source Observable. + * - `index`: the (zero-based) "index" of the value from the source Observable. + * - `source`: the source Observable instance itself. + * @return {Observable} An Observable of one number that represents the count as + * described above. + * @method count + * @owner Observable + */ +function count(predicate) { + return this.lift(new CountOperator(predicate, this)); +} +exports.count = count; +var CountOperator = (function () { + function CountOperator(predicate, source) { + this.predicate = predicate; + this.source = source; + } + CountOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new CountSubscriber(subscriber, this.predicate, this.source)); + }; + return CountOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var CountSubscriber = (function (_super) { + __extends(CountSubscriber, _super); + function CountSubscriber(destination, predicate, source) { + _super.call(this, destination); + this.predicate = predicate; + this.source = source; + this.count = 0; + this.index = 0; + } + CountSubscriber.prototype._next = function (value) { + if (this.predicate) { + this._tryPredicate(value); + } + else { + this.count++; + } + }; + CountSubscriber.prototype._tryPredicate = function (value) { + var result; + try { + result = this.predicate(value, this.index++, this.source); + } + catch (err) { + this.destination.error(err); + return; + } + if (result) { + this.count++; + } + }; + CountSubscriber.prototype._complete = function () { + this.destination.next(this.count); + this.destination.complete(); + }; + return CountSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],579:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Emits a value from the source Observable only after a particular time span + * determined by another Observable has passed without another source emission. + * + * It's like {@link debounceTime}, but the time span of + * emission silence is determined by a second Observable. + * + * + * + * `debounce` delays values emitted by the source Observable, but drops previous + * pending delayed emissions if a new value arrives on the source Observable. + * This operator keeps track of the most recent value from the source + * Observable, and spawns a duration Observable by calling the + * `durationSelector` function. The value is emitted only when the duration + * Observable emits a value or completes, and if no other value was emitted on + * the source Observable since the duration Observable was spawned. If a new + * value appears before the duration Observable emits, the previous value will + * be dropped and will not be emitted on the output Observable. + * + * Like {@link debounceTime}, this is a rate-limiting operator, and also a + * delay-like operator since output emissions do not necessarily occur at the + * same time as they did on the source Observable. + * + * @example Emit the most recent click after a burst of clicks + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.debounce(() => Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link audit} + * @see {@link debounceTime} + * @see {@link delayWhen} + * @see {@link throttle} + * + * @param {function(value: T): Observable|Promise} durationSelector A function + * that receives a value from the source Observable, for computing the timeout + * duration for each source value, returned as an Observable or a Promise. + * @return {Observable} An Observable that delays the emissions of the source + * Observable by the specified duration Observable returned by + * `durationSelector`, and may drop some values if they occur too frequently. + * @method debounce + * @owner Observable + */ +function debounce(durationSelector) { + return this.lift(new DebounceOperator(durationSelector)); +} +exports.debounce = debounce; +var DebounceOperator = (function () { + function DebounceOperator(durationSelector) { + this.durationSelector = durationSelector; + } + DebounceOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DebounceSubscriber(subscriber, this.durationSelector)); + }; + return DebounceOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DebounceSubscriber = (function (_super) { + __extends(DebounceSubscriber, _super); + function DebounceSubscriber(destination, durationSelector) { + _super.call(this, destination); + this.durationSelector = durationSelector; + this.hasValue = false; + this.durationSubscription = null; + } + DebounceSubscriber.prototype._next = function (value) { + try { + var result = this.durationSelector.call(this, value); + if (result) { + this._tryNext(value, result); + } + } + catch (err) { + this.destination.error(err); + } + }; + DebounceSubscriber.prototype._complete = function () { + this.emitValue(); + this.destination.complete(); + }; + DebounceSubscriber.prototype._tryNext = function (value, duration) { + var subscription = this.durationSubscription; + this.value = value; + this.hasValue = true; + if (subscription) { + subscription.unsubscribe(); + this.remove(subscription); + } + subscription = subscribeToResult_1.subscribeToResult(this, duration); + if (!subscription.isUnsubscribed) { + this.add(this.durationSubscription = subscription); + } + }; + DebounceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.emitValue(); + }; + DebounceSubscriber.prototype.notifyComplete = function () { + this.emitValue(); + }; + DebounceSubscriber.prototype.emitValue = function () { + if (this.hasValue) { + var value = this.value; + var subscription = this.durationSubscription; + if (subscription) { + this.durationSubscription = null; + subscription.unsubscribe(); + this.remove(subscription); + } + this.value = null; + this.hasValue = false; + _super.prototype._next.call(this, value); + } + }; + return DebounceSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],580:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var async_1 = require('../scheduler/async'); +/** + * Emits a value from the source Observable only after a particular time span + * has passed without another source emission. + * + * It's like {@link delay}, but passes only the most + * recent value from each burst of emissions. + * + * + * + * `debounceTime` delays values emitted by the source Observable, but drops + * previous pending delayed emissions if a new value arrives on the source + * Observable. This operator keeps track of the most recent value from the + * source Observable, and emits that only when `dueTime` enough time has passed + * without any other value appearing on the source Observable. If a new value + * appears before `dueTime` silence occurs, the previous value will be dropped + * and will not be emitted on the output Observable. + * + * This is a rate-limiting operator, because it is impossible for more than one + * value to be emitted in any time window of duration `dueTime`, but it is also + * a delay-like operator since output emissions do not occur at the same time as + * they did on the source Observable. Optionally takes a {@link Scheduler} for + * managing timers. + * + * @example Emit the most recent click after a burst of clicks + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.debounceTime(1000); + * result.subscribe(x => console.log(x)); + * + * @see {@link auditTime} + * @see {@link debounce} + * @see {@link delay} + * @see {@link sampleTime} + * @see {@link throttleTime} + * + * @param {number} dueTime The timeout duration in milliseconds (or the time + * unit determined internally by the optional `scheduler`) for the window of + * time required to wait for emission silence before emitting the most recent + * source value. + * @param {Scheduler} [scheduler=async] The {@link Scheduler} to use for + * managing the timers that handle the timeout for each value. + * @return {Observable} An Observable that delays the emissions of the source + * Observable by the specified `dueTime`, and may drop some values if they occur + * too frequently. + * @method debounceTime + * @owner Observable + */ +function debounceTime(dueTime, scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new DebounceTimeOperator(dueTime, scheduler)); +} +exports.debounceTime = debounceTime; +var DebounceTimeOperator = (function () { + function DebounceTimeOperator(dueTime, scheduler) { + this.dueTime = dueTime; + this.scheduler = scheduler; + } + DebounceTimeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler)); + }; + return DebounceTimeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DebounceTimeSubscriber = (function (_super) { + __extends(DebounceTimeSubscriber, _super); + function DebounceTimeSubscriber(destination, dueTime, scheduler) { + _super.call(this, destination); + this.dueTime = dueTime; + this.scheduler = scheduler; + this.debouncedSubscription = null; + this.lastValue = null; + this.hasValue = false; + } + DebounceTimeSubscriber.prototype._next = function (value) { + this.clearDebounce(); + this.lastValue = value; + this.hasValue = true; + this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this)); + }; + DebounceTimeSubscriber.prototype._complete = function () { + this.debouncedNext(); + this.destination.complete(); + }; + DebounceTimeSubscriber.prototype.debouncedNext = function () { + this.clearDebounce(); + if (this.hasValue) { + this.destination.next(this.lastValue); + this.lastValue = null; + this.hasValue = false; + } + }; + DebounceTimeSubscriber.prototype.clearDebounce = function () { + var debouncedSubscription = this.debouncedSubscription; + if (debouncedSubscription !== null) { + this.remove(debouncedSubscription); + debouncedSubscription.unsubscribe(); + this.debouncedSubscription = null; + } + }; + return DebounceTimeSubscriber; +}(Subscriber_1.Subscriber)); +function dispatchNext(subscriber) { + subscriber.debouncedNext(); +} + +},{"../Subscriber":386,"../scheduler/async":674}],581:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Emits a given value if the source Observable completes without emitting any + * `next` value, otherwise mirrors the source Observable. + * + * If the source Observable turns out to be empty, then + * this operator will emit a default value. + * + * + * + * `defaultIfEmpty` emits the values emitted by the source Observable or a + * specified default value if the source Observable is empty (completes without + * having emitted any `next` value). + * + * @example If no clicks happen in 5 seconds, then emit "no clicks" + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var clicksBeforeFive = clicks.takeUntil(Rx.Observable.interval(5000)); + * var result = clicksBeforeFive.defaultIfEmpty('no clicks'); + * result.subscribe(x => console.log(x)); + * + * @see {@link empty} + * @see {@link last} + * + * @param {any} [defaultValue=null] The default value used if the source + * Observable is empty. + * @return {Observable} An Observable that emits either the specified + * `defaultValue` if the source Observable emits no items, or the values emitted + * by the source Observable. + * @method defaultIfEmpty + * @owner Observable + */ +function defaultIfEmpty(defaultValue) { + if (defaultValue === void 0) { defaultValue = null; } + return this.lift(new DefaultIfEmptyOperator(defaultValue)); +} +exports.defaultIfEmpty = defaultIfEmpty; +var DefaultIfEmptyOperator = (function () { + function DefaultIfEmptyOperator(defaultValue) { + this.defaultValue = defaultValue; + } + DefaultIfEmptyOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue)); + }; + return DefaultIfEmptyOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DefaultIfEmptySubscriber = (function (_super) { + __extends(DefaultIfEmptySubscriber, _super); + function DefaultIfEmptySubscriber(destination, defaultValue) { + _super.call(this, destination); + this.defaultValue = defaultValue; + this.isEmpty = true; + } + DefaultIfEmptySubscriber.prototype._next = function (value) { + this.isEmpty = false; + this.destination.next(value); + }; + DefaultIfEmptySubscriber.prototype._complete = function () { + if (this.isEmpty) { + this.destination.next(this.defaultValue); + } + this.destination.complete(); + }; + return DefaultIfEmptySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],582:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var async_1 = require('../scheduler/async'); +var isDate_1 = require('../util/isDate'); +var Subscriber_1 = require('../Subscriber'); +var Notification_1 = require('../Notification'); +/** + * Delays the emission of items from the source Observable by a given timeout or + * until a given Date. + * + * Time shifts each item by some specified amount of + * milliseconds. + * + * + * + * If the delay argument is a Number, this operator time shifts the source + * Observable by that amount of time expressed in milliseconds. The relative + * time intervals between the values are preserved. + * + * If the delay argument is a Date, this operator time shifts the start of the + * Observable execution until the given date occurs. + * + * @example Delay each click by one second + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var delayedClicks = clicks.delay(1000); // each click emitted after 1 second + * delayedClicks.subscribe(x => console.log(x)); + * + * @example Delay all clicks until a future date happens + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var date = new Date('March 15, 2050 12:00:00'); // in the future + * var delayedClicks = clicks.delay(date); // click emitted only after that date + * delayedClicks.subscribe(x => console.log(x)); + * + * @see {@link debounceTime} + * @see {@link delayWhen} + * + * @param {number|Date} delay The delay duration in milliseconds (a `number`) or + * a `Date` until which the emission of the source items is delayed. + * @param {Scheduler} [scheduler=async] The Scheduler to use for + * managing the timers that handle the time-shift for each item. + * @return {Observable} An Observable that delays the emissions of the source + * Observable by the specified timeout or Date. + * @method delay + * @owner Observable + */ +function delay(delay, scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + var absoluteDelay = isDate_1.isDate(delay); + var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay); + return this.lift(new DelayOperator(delayFor, scheduler)); +} +exports.delay = delay; +var DelayOperator = (function () { + function DelayOperator(delay, scheduler) { + this.delay = delay; + this.scheduler = scheduler; + } + DelayOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler)); + }; + return DelayOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DelaySubscriber = (function (_super) { + __extends(DelaySubscriber, _super); + function DelaySubscriber(destination, delay, scheduler) { + _super.call(this, destination); + this.delay = delay; + this.scheduler = scheduler; + this.queue = []; + this.active = false; + this.errored = false; + } + DelaySubscriber.dispatch = function (state) { + var source = state.source; + var queue = source.queue; + var scheduler = state.scheduler; + var destination = state.destination; + while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) { + queue.shift().notification.observe(destination); + } + if (queue.length > 0) { + var delay_1 = Math.max(0, queue[0].time - scheduler.now()); + this.schedule(state, delay_1); + } + else { + source.active = false; + } + }; + DelaySubscriber.prototype._schedule = function (scheduler) { + this.active = true; + this.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, { + source: this, destination: this.destination, scheduler: scheduler + })); + }; + DelaySubscriber.prototype.scheduleNotification = function (notification) { + if (this.errored === true) { + return; + } + var scheduler = this.scheduler; + var message = new DelayMessage(scheduler.now() + this.delay, notification); + this.queue.push(message); + if (this.active === false) { + this._schedule(scheduler); + } + }; + DelaySubscriber.prototype._next = function (value) { + this.scheduleNotification(Notification_1.Notification.createNext(value)); + }; + DelaySubscriber.prototype._error = function (err) { + this.errored = true; + this.queue = []; + this.destination.error(err); + }; + DelaySubscriber.prototype._complete = function () { + this.scheduleNotification(Notification_1.Notification.createComplete()); + }; + return DelaySubscriber; +}(Subscriber_1.Subscriber)); +var DelayMessage = (function () { + function DelayMessage(time, notification) { + this.time = time; + this.notification = notification; + } + return DelayMessage; +}()); + +},{"../Notification":377,"../Subscriber":386,"../scheduler/async":674,"../util/isDate":696}],583:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Observable_1 = require('../Observable'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Delays the emission of items from the source Observable by a given time span + * determined by the emissions of another Observable. + * + * It's like {@link delay}, but the time span of the + * delay duration is determined by a second Observable. + * + * + * + * `delayWhen` time shifts each emitted value from the source Observable by a + * time span determined by another Observable. When the source emits a value, + * the `delayDurationSelector` function is called with the source value as + * argument, and should return an Observable, called the "duration" Observable. + * The source value is emitted on the output Observable only when the duration + * Observable emits a value or completes. + * + * Optionally, `delayWhen` takes a second argument, `subscriptionDelay`, which + * is an Observable. When `subscriptionDelay` emits its first value or + * completes, the source Observable is subscribed to and starts behaving like + * described in the previous paragraph. If `subscriptionDelay` is not provided, + * `delayWhen` will subscribe to the source Observable as soon as the output + * Observable is subscribed. + * + * @example Delay each click by a random amount of time, between 0 and 5 seconds + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var delayedClicks = clicks.delayWhen(event => + * Rx.Observable.interval(Math.random() * 5000) + * ); + * delayedClicks.subscribe(x => console.log(x)); + * + * @see {@link debounce} + * @see {@link delay} + * + * @param {function(value: T): Observable} delayDurationSelector A function that + * returns an Observable for each value emitted by the source Observable, which + * is then used to delay the emission of that item on the output Observable + * until the Observable returned from this function emits a value. + * @param {Observable} subscriptionDelay An Observable that triggers the + * subscription to the source Observable once it emits any value. + * @return {Observable} An Observable that delays the emissions of the source + * Observable by an amount of time specified by the Observable returned by + * `delayDurationSelector`. + * @method delayWhen + * @owner Observable + */ +function delayWhen(delayDurationSelector, subscriptionDelay) { + if (subscriptionDelay) { + return new SubscriptionDelayObservable(this, subscriptionDelay) + .lift(new DelayWhenOperator(delayDurationSelector)); + } + return this.lift(new DelayWhenOperator(delayDurationSelector)); +} +exports.delayWhen = delayWhen; +var DelayWhenOperator = (function () { + function DelayWhenOperator(delayDurationSelector) { + this.delayDurationSelector = delayDurationSelector; + } + DelayWhenOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector)); + }; + return DelayWhenOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DelayWhenSubscriber = (function (_super) { + __extends(DelayWhenSubscriber, _super); + function DelayWhenSubscriber(destination, delayDurationSelector) { + _super.call(this, destination); + this.delayDurationSelector = delayDurationSelector; + this.completed = false; + this.delayNotifierSubscriptions = []; + this.values = []; + } + DelayWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.destination.next(outerValue); + this.removeSubscription(innerSub); + this.tryComplete(); + }; + DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) { + this._error(error); + }; + DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) { + var value = this.removeSubscription(innerSub); + if (value) { + this.destination.next(value); + } + this.tryComplete(); + }; + DelayWhenSubscriber.prototype._next = function (value) { + try { + var delayNotifier = this.delayDurationSelector(value); + if (delayNotifier) { + this.tryDelay(delayNotifier, value); + } + } + catch (err) { + this.destination.error(err); + } + }; + DelayWhenSubscriber.prototype._complete = function () { + this.completed = true; + this.tryComplete(); + }; + DelayWhenSubscriber.prototype.removeSubscription = function (subscription) { + subscription.unsubscribe(); + var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription); + var value = null; + if (subscriptionIdx !== -1) { + value = this.values[subscriptionIdx]; + this.delayNotifierSubscriptions.splice(subscriptionIdx, 1); + this.values.splice(subscriptionIdx, 1); + } + return value; + }; + DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) { + var notifierSubscription = subscribeToResult_1.subscribeToResult(this, delayNotifier, value); + this.add(notifierSubscription); + this.delayNotifierSubscriptions.push(notifierSubscription); + this.values.push(value); + }; + DelayWhenSubscriber.prototype.tryComplete = function () { + if (this.completed && this.delayNotifierSubscriptions.length === 0) { + this.destination.complete(); + } + }; + return DelayWhenSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SubscriptionDelayObservable = (function (_super) { + __extends(SubscriptionDelayObservable, _super); + function SubscriptionDelayObservable(source, subscriptionDelay) { + _super.call(this); + this.source = source; + this.subscriptionDelay = subscriptionDelay; + } + SubscriptionDelayObservable.prototype._subscribe = function (subscriber) { + this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source)); + }; + return SubscriptionDelayObservable; +}(Observable_1.Observable)); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SubscriptionDelaySubscriber = (function (_super) { + __extends(SubscriptionDelaySubscriber, _super); + function SubscriptionDelaySubscriber(parent, source) { + _super.call(this); + this.parent = parent; + this.source = source; + this.sourceSubscribed = false; + } + SubscriptionDelaySubscriber.prototype._next = function (unused) { + this.subscribeToSource(); + }; + SubscriptionDelaySubscriber.prototype._error = function (err) { + this.unsubscribe(); + this.parent.error(err); + }; + SubscriptionDelaySubscriber.prototype._complete = function () { + this.subscribeToSource(); + }; + SubscriptionDelaySubscriber.prototype.subscribeToSource = function () { + if (!this.sourceSubscribed) { + this.sourceSubscribed = true; + this.unsubscribe(); + this.source.subscribe(this.parent); + } + }; + return SubscriptionDelaySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Observable":378,"../OuterSubscriber":381,"../Subscriber":386,"../util/subscribeToResult":705}],584:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Converts an Observable of {@link Notification} objects into the emissions + * that they represent. + * + * Unwraps {@link Notification} objects as actual `next`, + * `error` and `complete` emissions. The opposite of {@link materialize}. + * + * + * + * `dematerialize` is assumed to operate an Observable that only emits + * {@link Notification} objects as `next` emissions, and does not emit any + * `error`. Such Observable is the output of a `materialize` operation. Those + * notifications are then unwrapped using the metadata they contain, and emitted + * as `next`, `error`, and `complete` on the output Observable. + * + * Use this operator in conjunction with {@link materialize}. + * + * @example Convert an Observable of Notifications to an actual Observable + * var notifA = new Rx.Notification('N', 'A'); + * var notifB = new Rx.Notification('N', 'B'); + * var notifE = new Rx.Notification('E', void 0, + * new TypeError('x.toUpperCase is not a function') + * ); + * var materialized = Rx.Observable.of(notifA, notifB, notifE); + * var upperCase = materialized.dematerialize(); + * upperCase.subscribe(x => console.log(x), e => console.error(e)); + * + * @see {@link Notification} + * @see {@link materialize} + * + * @return {Observable} An Observable that emits items and notifications + * embedded in Notification objects emitted by the source Observable. + * @method dematerialize + * @owner Observable + */ +function dematerialize() { + return this.lift(new DeMaterializeOperator()); +} +exports.dematerialize = dematerialize; +var DeMaterializeOperator = (function () { + function DeMaterializeOperator() { + } + DeMaterializeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DeMaterializeSubscriber(subscriber)); + }; + return DeMaterializeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DeMaterializeSubscriber = (function (_super) { + __extends(DeMaterializeSubscriber, _super); + function DeMaterializeSubscriber(destination) { + _super.call(this, destination); + } + DeMaterializeSubscriber.prototype._next = function (value) { + value.observe(this.destination); + }; + return DeMaterializeSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],585:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items. + * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted. + * If a comparator function is not provided, an equality check is used by default. + * As the internal HashSet of this operator grows larger and larger, care should be taken in the domain of inputs this operator may see. + * An optional parameter is also provided such that an Observable can be provided to queue the internal HashSet to flush the values it holds. + * @param {function} [compare] optional comparison function called to test if an item is distinct from previous items in the source. + * @param {Observable} [flushes] optional Observable for flushing the internal HashSet of the operator. + * @return {Observable} an Observable that emits items from the source Observable with distinct values. + * @method distinct + * @owner Observable + */ +function distinct(compare, flushes) { + return this.lift(new DistinctOperator(compare, flushes)); +} +exports.distinct = distinct; +var DistinctOperator = (function () { + function DistinctOperator(compare, flushes) { + this.compare = compare; + this.flushes = flushes; + } + DistinctOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DistinctSubscriber(subscriber, this.compare, this.flushes)); + }; + return DistinctOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DistinctSubscriber = (function (_super) { + __extends(DistinctSubscriber, _super); + function DistinctSubscriber(destination, compare, flushes) { + _super.call(this, destination); + this.values = []; + if (typeof compare === 'function') { + this.compare = compare; + } + if (flushes) { + this.add(subscribeToResult_1.subscribeToResult(this, flushes)); + } + } + DistinctSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.values.length = 0; + }; + DistinctSubscriber.prototype.notifyError = function (error, innerSub) { + this._error(error); + }; + DistinctSubscriber.prototype._next = function (value) { + var found = false; + var values = this.values; + var len = values.length; + try { + for (var i = 0; i < len; i++) { + if (this.compare(values[i], value)) { + found = true; + return; + } + } + } + catch (err) { + this.destination.error(err); + return; + } + this.values.push(value); + this.destination.next(value); + }; + DistinctSubscriber.prototype.compare = function (x, y) { + return x === y; + }; + return DistinctSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.DistinctSubscriber = DistinctSubscriber; + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],586:[function(require,module,exports){ +"use strict"; +var distinct_1 = require('./distinct'); +/** + * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items, + * using a property accessed by using the key provided to check if the two items are distinct. + * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted. + * If a comparator function is not provided, an equality check is used by default. + * As the internal HashSet of this operator grows larger and larger, care should be taken in the domain of inputs this operator may see. + * An optional parameter is also provided such that an Observable can be provided to queue the internal HashSet to flush the values it holds. + * @param {string} key string key for object property lookup on each item. + * @param {function} [compare] optional comparison function called to test if an item is distinct from previous items in the source. + * @param {Observable} [flushes] optional Observable for flushing the internal HashSet of the operator. + * @return {Observable} an Observable that emits items from the source Observable with distinct values. + * @method distinctKey + * @owner Observable + */ +function distinctKey(key, compare, flushes) { + return distinct_1.distinct.call(this, function (x, y) { + if (compare) { + return compare(x[key], y[key]); + } + return x[key] === y[key]; + }, flushes); +} +exports.distinctKey = distinctKey; + +},{"./distinct":585}],587:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +/** + * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item. + * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted. + * If a comparator function is not provided, an equality check is used by default. + * @param {function} [compare] optional comparison function called to test if an item is distinct from the previous item in the source. + * @return {Observable} an Observable that emits items from the source Observable with distinct values. + * @method distinctUntilChanged + * @owner Observable + */ +function distinctUntilChanged(compare, keySelector) { + return this.lift(new DistinctUntilChangedOperator(compare, keySelector)); +} +exports.distinctUntilChanged = distinctUntilChanged; +var DistinctUntilChangedOperator = (function () { + function DistinctUntilChangedOperator(compare, keySelector) { + this.compare = compare; + this.keySelector = keySelector; + } + DistinctUntilChangedOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector)); + }; + return DistinctUntilChangedOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DistinctUntilChangedSubscriber = (function (_super) { + __extends(DistinctUntilChangedSubscriber, _super); + function DistinctUntilChangedSubscriber(destination, compare, keySelector) { + _super.call(this, destination); + this.keySelector = keySelector; + this.hasKey = false; + if (typeof compare === 'function') { + this.compare = compare; + } + } + DistinctUntilChangedSubscriber.prototype.compare = function (x, y) { + return x === y; + }; + DistinctUntilChangedSubscriber.prototype._next = function (value) { + var keySelector = this.keySelector; + var key = value; + if (keySelector) { + key = tryCatch_1.tryCatch(this.keySelector)(value); + if (key === errorObject_1.errorObject) { + return this.destination.error(errorObject_1.errorObject.e); + } + } + var result = false; + if (this.hasKey) { + result = tryCatch_1.tryCatch(this.compare)(this.key, key); + if (result === errorObject_1.errorObject) { + return this.destination.error(errorObject_1.errorObject.e); + } + } + else { + this.hasKey = true; + } + if (Boolean(result) === false) { + this.key = key; + this.destination.next(value); + } + }; + return DistinctUntilChangedSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../util/errorObject":694,"../util/tryCatch":708}],588:[function(require,module,exports){ +"use strict"; +var distinctUntilChanged_1 = require('./distinctUntilChanged'); +/** + * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item, + * using a property accessed by using the key provided to check if the two items are distinct. + * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted. + * If a comparator function is not provided, an equality check is used by default. + * @param {string} key string key for object property lookup on each item. + * @param {function} [compare] optional comparison function called to test if an item is distinct from the previous item in the source. + * @return {Observable} an Observable that emits items from the source Observable with distinct values based on the key specified. + * @method distinctUntilKeyChanged + * @owner Observable + */ +function distinctUntilKeyChanged(key, compare) { + return distinctUntilChanged_1.distinctUntilChanged.call(this, function (x, y) { + if (compare) { + return compare(x[key], y[key]); + } + return x[key] === y[key]; + }); +} +exports.distinctUntilKeyChanged = distinctUntilKeyChanged; + +},{"./distinctUntilChanged":587}],589:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Perform a side effect for every emission on the source Observable, but return + * an Observable that is identical to the source. + * + * Intercepts each emission on the source and runs a + * function, but returns an output which is identical to the source. + * + * + * + * Returns a mirrored Observable of the source Observable, but modified so that + * the provided Observer is called to perform a side effect for every value, + * error, and completion emitted by the source. Any errors that are thrown in + * the aforementioned Observer or handlers are safely sent down the error path + * of the output Observable. + * + * This operator is useful for debugging your Observables for the correct values + * or performing other side effects. + * + * Note: this is different to a `subscribe` on the Observable. If the Observable + * returned by `do` is not subscribed, the side effects specified by the + * Observer will never happen. `do` therefore simply spies on existing + * execution, it does not trigger an execution to happen like `subscribe` does. + * + * @example Map every every click to the clientX position of that click, while also logging the click event + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var positions = clicks + * .do(ev => console.log(ev)) + * .map(ev => ev.clientX); + * positions.subscribe(x => console.log(x)); + * + * @see {@link map} + * @see {@link subscribe} + * + * @param {Observer|function} [nextOrObserver] A normal Observer object or a + * callback for `next`. + * @param {function} [error] Callback for errors in the source. + * @param {function} [complete] Callback for the completion of the source. + * @return {Observable} An Observable identical to the source, but runs the + * specified Observer or callback(s) for each item. + * @method do + * @name do + * @owner Observable + */ +function _do(nextOrObserver, error, complete) { + return this.lift(new DoOperator(nextOrObserver, error, complete)); +} +exports._do = _do; +var DoOperator = (function () { + function DoOperator(nextOrObserver, error, complete) { + this.nextOrObserver = nextOrObserver; + this.error = error; + this.complete = complete; + } + DoOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new DoSubscriber(subscriber, this.nextOrObserver, this.error, this.complete)); + }; + return DoOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var DoSubscriber = (function (_super) { + __extends(DoSubscriber, _super); + function DoSubscriber(destination, nextOrObserver, error, complete) { + _super.call(this, destination); + var safeSubscriber = new Subscriber_1.Subscriber(nextOrObserver, error, complete); + safeSubscriber.syncErrorThrowable = true; + this.add(safeSubscriber); + this.safeSubscriber = safeSubscriber; + } + DoSubscriber.prototype._next = function (value) { + var safeSubscriber = this.safeSubscriber; + safeSubscriber.next(value); + if (safeSubscriber.syncErrorThrown) { + this.destination.error(safeSubscriber.syncErrorValue); + } + else { + this.destination.next(value); + } + }; + DoSubscriber.prototype._error = function (err) { + var safeSubscriber = this.safeSubscriber; + safeSubscriber.error(err); + if (safeSubscriber.syncErrorThrown) { + this.destination.error(safeSubscriber.syncErrorValue); + } + else { + this.destination.error(err); + } + }; + DoSubscriber.prototype._complete = function () { + var safeSubscriber = this.safeSubscriber; + safeSubscriber.complete(); + if (safeSubscriber.syncErrorThrown) { + this.destination.error(safeSubscriber.syncErrorValue); + } + else { + this.destination.complete(); + } + }; + return DoSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],590:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var ArgumentOutOfRangeError_1 = require('../util/ArgumentOutOfRangeError'); +/** + * Emits the single value at the specified `index` in a sequence of emissions + * from the source Observable. + * + * Emits only the i-th value, then completes. + * + * + * + * `elementAt` returns an Observable that emits the item at the specified + * `index` in the source Observable, or a default value if that `index` is out + * of range and the `default` argument is provided. If the `default` argument is + * not given and the `index` is out of range, the output Observable will emit an + * `ArgumentOutOfRangeError` error. + * + * @example Emit only the third click event + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.elementAt(2); + * result.subscribe(x => console.log(x)); + * + * @see {@link first} + * @see {@link last} + * @see {@link skip} + * @see {@link single} + * @see {@link take} + * + * @throws {ArgumentOutOfRangeError} When using `elementAt(i)`, it delivers an + * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0` or the + * Observable has completed before emitting the i-th `next` notification. + * + * @param {number} index Is the number `i` for the i-th source emission that has + * happened since the subscription, starting from the number `0`. + * @param {T} [defaultValue] The default value returned for missing indices. + * @return {Observable} An Observable that emits a single item, if it is found. + * Otherwise, will emit the default value if given. If not, then emits an error. + * @method elementAt + * @owner Observable + */ +function elementAt(index, defaultValue) { + return this.lift(new ElementAtOperator(index, defaultValue)); +} +exports.elementAt = elementAt; +var ElementAtOperator = (function () { + function ElementAtOperator(index, defaultValue) { + this.index = index; + this.defaultValue = defaultValue; + if (index < 0) { + throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; + } + } + ElementAtOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ElementAtSubscriber(subscriber, this.index, this.defaultValue)); + }; + return ElementAtOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ElementAtSubscriber = (function (_super) { + __extends(ElementAtSubscriber, _super); + function ElementAtSubscriber(destination, index, defaultValue) { + _super.call(this, destination); + this.index = index; + this.defaultValue = defaultValue; + } + ElementAtSubscriber.prototype._next = function (x) { + if (this.index-- === 0) { + this.destination.next(x); + this.destination.complete(); + } + }; + ElementAtSubscriber.prototype._complete = function () { + var destination = this.destination; + if (this.index >= 0) { + if (typeof this.defaultValue !== 'undefined') { + destination.next(this.defaultValue); + } + else { + destination.error(new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError); + } + } + destination.complete(); + }; + return ElementAtSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../util/ArgumentOutOfRangeError":684}],591:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Returns an Observable that emits whether or not every item of the source satisfies the condition specified. + * @param {function} predicate a function for determining if an item meets a specified condition. + * @param {any} [thisArg] optional object to use for `this` in the callback + * @return {Observable} an Observable of booleans that determines if all items of the source Observable meet the condition specified. + * @method every + * @owner Observable + */ +function every(predicate, thisArg) { + return this.lift(new EveryOperator(predicate, thisArg, this)); +} +exports.every = every; +var EveryOperator = (function () { + function EveryOperator(predicate, thisArg, source) { + this.predicate = predicate; + this.thisArg = thisArg; + this.source = source; + } + EveryOperator.prototype.call = function (observer, source) { + return source._subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source)); + }; + return EveryOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var EverySubscriber = (function (_super) { + __extends(EverySubscriber, _super); + function EverySubscriber(destination, predicate, thisArg, source) { + _super.call(this, destination); + this.predicate = predicate; + this.thisArg = thisArg; + this.source = source; + this.index = 0; + this.thisArg = thisArg || this; + } + EverySubscriber.prototype.notifyComplete = function (everyValueMatch) { + this.destination.next(everyValueMatch); + this.destination.complete(); + }; + EverySubscriber.prototype._next = function (value) { + var result = false; + try { + result = this.predicate.call(this.thisArg, value, this.index++, this.source); + } + catch (err) { + this.destination.error(err); + return; + } + if (!result) { + this.notifyComplete(false); + } + }; + EverySubscriber.prototype._complete = function () { + this.notifyComplete(true); + }; + return EverySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],592:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Converts a higher-order Observable into a first-order Observable by dropping + * inner Observables while the previous inner Observable has not yet completed. + * + * Flattens an Observable-of-Observables by dropping the + * next inner Observables while the current inner is still executing. + * + * + * + * `exhaust` subscribes to an Observable that emits Observables, also known as a + * higher-order Observable. Each time it observes one of these emitted inner + * Observables, the output Observable begins emitting the items emitted by that + * inner Observable. So far, it behaves like {@link mergeAll}. However, + * `exhaust` ignores every new inner Observable if the previous Observable has + * not yet completed. Once that one completes, it will accept and flatten the + * next inner Observable and repeat this process. + * + * @example Run a finite timer for each click, only if there is no currently active timer + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000)); + * var result = higherOrder.exhaust(); + * result.subscribe(x => console.log(x)); + * + * @see {@link combineAll} + * @see {@link concatAll} + * @see {@link switch} + * @see {@link mergeAll} + * @see {@link exhaustMap} + * @see {@link zipAll} + * + * @return {Observable} Returns an Observable that takes a source of Observables + * and propagates the first observable exclusively until it completes before + * subscribing to the next. + * @method exhaust + * @owner Observable + */ +function exhaust() { + return this.lift(new SwitchFirstOperator()); +} +exports.exhaust = exhaust; +var SwitchFirstOperator = (function () { + function SwitchFirstOperator() { + } + SwitchFirstOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SwitchFirstSubscriber(subscriber)); + }; + return SwitchFirstOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SwitchFirstSubscriber = (function (_super) { + __extends(SwitchFirstSubscriber, _super); + function SwitchFirstSubscriber(destination) { + _super.call(this, destination); + this.hasCompleted = false; + this.hasSubscription = false; + } + SwitchFirstSubscriber.prototype._next = function (value) { + if (!this.hasSubscription) { + this.hasSubscription = true; + this.add(subscribeToResult_1.subscribeToResult(this, value)); + } + }; + SwitchFirstSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (!this.hasSubscription) { + this.destination.complete(); + } + }; + SwitchFirstSubscriber.prototype.notifyComplete = function (innerSub) { + this.remove(innerSub); + this.hasSubscription = false; + if (this.hasCompleted) { + this.destination.complete(); + } + }; + return SwitchFirstSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],593:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Projects each source value to an Observable which is merged in the output + * Observable only if the previous projected Observable has completed. + * + * Maps each value to an Observable, then flattens all of + * these inner Observables using {@link exhaust}. + * + * + * + * Returns an Observable that emits items based on applying a function that you + * supply to each item emitted by the source Observable, where that function + * returns an (so-called "inner") Observable. When it projects a source value to + * an Observable, the output Observable begins emitting the items emitted by + * that projected Observable. However, `exhaustMap` ignores every new projected + * Observable if the previous projected Observable has not yet completed. Once + * that one completes, it will accept and flatten the next projected Observable + * and repeat this process. + * + * @example Run a finite timer for each click, only if there is no currently active timer + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.exhaustMap((ev) => Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatMap} + * @see {@link exhaust} + * @see {@link mergeMap} + * @see {@link switchMap} + * + * @param {function(value: T, ?index: number): Observable} project A function + * that, when applied to an item emitted by the source Observable, returns an + * Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @return {Observable} An Observable containing projected Observables + * of each item of the source, ignoring projected Observables that start before + * their preceding Observable has completed. + * @method exhaustMap + * @owner Observable + */ +function exhaustMap(project, resultSelector) { + return this.lift(new SwitchFirstMapOperator(project, resultSelector)); +} +exports.exhaustMap = exhaustMap; +var SwitchFirstMapOperator = (function () { + function SwitchFirstMapOperator(project, resultSelector) { + this.project = project; + this.resultSelector = resultSelector; + } + SwitchFirstMapOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SwitchFirstMapSubscriber(subscriber, this.project, this.resultSelector)); + }; + return SwitchFirstMapOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SwitchFirstMapSubscriber = (function (_super) { + __extends(SwitchFirstMapSubscriber, _super); + function SwitchFirstMapSubscriber(destination, project, resultSelector) { + _super.call(this, destination); + this.project = project; + this.resultSelector = resultSelector; + this.hasSubscription = false; + this.hasCompleted = false; + this.index = 0; + } + SwitchFirstMapSubscriber.prototype._next = function (value) { + if (!this.hasSubscription) { + this.tryNext(value); + } + }; + SwitchFirstMapSubscriber.prototype.tryNext = function (value) { + var index = this.index++; + var destination = this.destination; + try { + var result = this.project(value, index); + this.hasSubscription = true; + this.add(subscribeToResult_1.subscribeToResult(this, result, value, index)); + } + catch (err) { + destination.error(err); + } + }; + SwitchFirstMapSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (!this.hasSubscription) { + this.destination.complete(); + } + }; + SwitchFirstMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var _a = this, resultSelector = _a.resultSelector, destination = _a.destination; + if (resultSelector) { + this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex); + } + else { + destination.next(innerValue); + } + }; + SwitchFirstMapSubscriber.prototype.trySelectResult = function (outerValue, innerValue, outerIndex, innerIndex) { + var _a = this, resultSelector = _a.resultSelector, destination = _a.destination; + try { + var result = resultSelector(outerValue, innerValue, outerIndex, innerIndex); + destination.next(result); + } + catch (err) { + destination.error(err); + } + }; + SwitchFirstMapSubscriber.prototype.notifyError = function (err) { + this.destination.error(err); + }; + SwitchFirstMapSubscriber.prototype.notifyComplete = function (innerSub) { + this.remove(innerSub); + this.hasSubscription = false; + if (this.hasCompleted) { + this.destination.complete(); + } + }; + return SwitchFirstMapSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],594:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Returns an Observable where for each item in the source Observable, the supplied function is applied to each item, + * resulting in a new value to then be applied again with the function. + * @param {function} project the function for projecting the next emitted item of the Observable. + * @param {number} [concurrent] the max number of observables that can be created concurrently. defaults to infinity. + * @param {Scheduler} [scheduler] The Scheduler to use for managing the expansions. + * @return {Observable} an Observable containing the expansions of the source Observable. + * @method expand + * @owner Observable + */ +function expand(project, concurrent, scheduler) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + if (scheduler === void 0) { scheduler = undefined; } + concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent; + return this.lift(new ExpandOperator(project, concurrent, scheduler)); +} +exports.expand = expand; +var ExpandOperator = (function () { + function ExpandOperator(project, concurrent, scheduler) { + this.project = project; + this.concurrent = concurrent; + this.scheduler = scheduler; + } + ExpandOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler)); + }; + return ExpandOperator; +}()); +exports.ExpandOperator = ExpandOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ExpandSubscriber = (function (_super) { + __extends(ExpandSubscriber, _super); + function ExpandSubscriber(destination, project, concurrent, scheduler) { + _super.call(this, destination); + this.project = project; + this.concurrent = concurrent; + this.scheduler = scheduler; + this.index = 0; + this.active = 0; + this.hasCompleted = false; + if (concurrent < Number.POSITIVE_INFINITY) { + this.buffer = []; + } + } + ExpandSubscriber.dispatch = function (arg) { + var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index; + subscriber.subscribeToProjection(result, value, index); + }; + ExpandSubscriber.prototype._next = function (value) { + var destination = this.destination; + if (destination.isUnsubscribed) { + this._complete(); + return; + } + var index = this.index++; + if (this.active < this.concurrent) { + destination.next(value); + var result = tryCatch_1.tryCatch(this.project)(value, index); + if (result === errorObject_1.errorObject) { + destination.error(errorObject_1.errorObject.e); + } + else if (!this.scheduler) { + this.subscribeToProjection(result, value, index); + } + else { + var state = { subscriber: this, result: result, value: value, index: index }; + this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state)); + } + } + else { + this.buffer.push(value); + } + }; + ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) { + this.active++; + this.add(subscribeToResult_1.subscribeToResult(this, result, value, index)); + }; + ExpandSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (this.hasCompleted && this.active === 0) { + this.destination.complete(); + } + }; + ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this._next(innerValue); + }; + ExpandSubscriber.prototype.notifyComplete = function (innerSub) { + var buffer = this.buffer; + this.remove(innerSub); + this.active--; + if (buffer && buffer.length > 0) { + this._next(buffer.shift()); + } + if (this.hasCompleted && this.active === 0) { + this.destination.complete(); + } + }; + return ExpandSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.ExpandSubscriber = ExpandSubscriber; + +},{"../OuterSubscriber":381,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],595:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Filter items emitted by the source Observable by only emitting those that + * satisfy a specified predicate. + * + * Like + * [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter), + * it only emits a value from the source if it passes a criterion function. + * + * + * + * Similar to the well-known `Array.prototype.filter` method, this operator + * takes values from the source Observable, passes them through a `predicate` + * function and only emits those values that yielded `true`. + * + * @example Emit only click events whose target was a DIV element + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var clicksOnDivs = clicks.filter(ev => ev.target.tagName === 'DIV'); + * clicksOnDivs.subscribe(x => console.log(x)); + * + * @see {@link distinct} + * @see {@link distinctKey} + * @see {@link distinctUntilChanged} + * @see {@link distinctUntilKeyChanged} + * @see {@link ignoreElements} + * @see {@link partition} + * @see {@link skip} + * + * @param {function(value: T, index: number): boolean} predicate A function that + * evaluates each value emitted by the source Observable. If it returns `true`, + * the value is emitted, if `false` the value is not passed to the output + * Observable. The `index` parameter is the number `i` for the i-th source + * emission that has happened since the subscription, starting from the number + * `0`. + * @param {any} [thisArg] An optional argument to determine the value of `this` + * in the `predicate` function. + * @return {Observable} An Observable of values from the source that were + * allowed by the `predicate` function. + * @method filter + * @owner Observable + */ +function filter(predicate, thisArg) { + return this.lift(new FilterOperator(predicate, thisArg)); +} +exports.filter = filter; +var FilterOperator = (function () { + function FilterOperator(predicate, thisArg) { + this.predicate = predicate; + this.thisArg = thisArg; + } + FilterOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg)); + }; + return FilterOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var FilterSubscriber = (function (_super) { + __extends(FilterSubscriber, _super); + function FilterSubscriber(destination, predicate, thisArg) { + _super.call(this, destination); + this.predicate = predicate; + this.thisArg = thisArg; + this.count = 0; + this.predicate = predicate; + } + // the try catch block below is left specifically for + // optimization and perf reasons. a tryCatcher is not necessary here. + FilterSubscriber.prototype._next = function (value) { + var result; + try { + result = this.predicate.call(this.thisArg, value, this.count++); + } + catch (err) { + this.destination.error(err); + return; + } + if (result) { + this.destination.next(value); + } + }; + return FilterSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],596:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Subscription_1 = require('../Subscription'); +/** + * Returns an Observable that mirrors the source Observable, but will call a specified function when + * the source terminates on complete or error. + * @param {function} callback function to be called when source terminates. + * @return {Observable} an Observable that mirrors the source, but will call the specified function on termination. + * @method finally + * @owner Observable + */ +function _finally(callback) { + return this.lift(new FinallyOperator(callback)); +} +exports._finally = _finally; +var FinallyOperator = (function () { + function FinallyOperator(callback) { + this.callback = callback; + } + FinallyOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new FinallySubscriber(subscriber, this.callback)); + }; + return FinallyOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var FinallySubscriber = (function (_super) { + __extends(FinallySubscriber, _super); + function FinallySubscriber(destination, callback) { + _super.call(this, destination); + this.add(new Subscription_1.Subscription(callback)); + } + return FinallySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../Subscription":387}],597:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Emits only the first value emitted by the source Observable that meets some + * condition. + * + * Finds the first value that passes some test and emits + * that. + * + * + * + * `find` searches for the first item in the source Observable that matches the + * specified condition embodied by the `predicate`, and returns the first + * occurrence in the source. Unlike {@link first}, the `predicate` is required + * in `find`, and does not emit an error if a valid value is not found. + * + * @example Find and emit the first click that happens on a DIV element + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.find(ev => ev.target.tagName === 'DIV'); + * result.subscribe(x => console.log(x)); + * + * @see {@link filter} + * @see {@link first} + * @see {@link findIndex} + * @see {@link take} + * + * @param {function(value: T, index: number, source: Observable): boolean} predicate + * A function called with each item to test for condition matching. + * @param {any} [thisArg] An optional argument to determine the value of `this` + * in the `predicate` function. + * @return {Observable} An Observable of the first item that matches the + * condition. + * @method find + * @owner Observable + */ +function find(predicate, thisArg) { + if (typeof predicate !== 'function') { + throw new TypeError('predicate is not a function'); + } + return this.lift(new FindValueOperator(predicate, this, false, thisArg)); +} +exports.find = find; +var FindValueOperator = (function () { + function FindValueOperator(predicate, source, yieldIndex, thisArg) { + this.predicate = predicate; + this.source = source; + this.yieldIndex = yieldIndex; + this.thisArg = thisArg; + } + FindValueOperator.prototype.call = function (observer, source) { + return source._subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg)); + }; + return FindValueOperator; +}()); +exports.FindValueOperator = FindValueOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var FindValueSubscriber = (function (_super) { + __extends(FindValueSubscriber, _super); + function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) { + _super.call(this, destination); + this.predicate = predicate; + this.source = source; + this.yieldIndex = yieldIndex; + this.thisArg = thisArg; + this.index = 0; + } + FindValueSubscriber.prototype.notifyComplete = function (value) { + var destination = this.destination; + destination.next(value); + destination.complete(); + }; + FindValueSubscriber.prototype._next = function (value) { + var _a = this, predicate = _a.predicate, thisArg = _a.thisArg; + var index = this.index++; + try { + var result = predicate.call(thisArg || this, value, index, this.source); + if (result) { + this.notifyComplete(this.yieldIndex ? index : value); + } + } + catch (err) { + this.destination.error(err); + } + }; + FindValueSubscriber.prototype._complete = function () { + this.notifyComplete(this.yieldIndex ? -1 : undefined); + }; + return FindValueSubscriber; +}(Subscriber_1.Subscriber)); +exports.FindValueSubscriber = FindValueSubscriber; + +},{"../Subscriber":386}],598:[function(require,module,exports){ +"use strict"; +var find_1 = require('./find'); +/** + * Emits only the index of the first value emitted by the source Observable that + * meets some condition. + * + * It's like {@link find}, but emits the index of the + * found value, not the value itself. + * + * + * + * `findIndex` searches for the first item in the source Observable that matches + * the specified condition embodied by the `predicate`, and returns the + * (zero-based) index of the first occurrence in the source. Unlike + * {@link first}, the `predicate` is required in `findIndex`, and does not emit + * an error if a valid value is not found. + * + * @example Emit the index of first click that happens on a DIV element + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.findIndex(ev => ev.target.tagName === 'DIV'); + * result.subscribe(x => console.log(x)); + * + * @see {@link filter} + * @see {@link find} + * @see {@link first} + * @see {@link take} + * + * @param {function(value: T, index: number, source: Observable): boolean} predicate + * A function called with each item to test for condition matching. + * @param {any} [thisArg] An optional argument to determine the value of `this` + * in the `predicate` function. + * @return {Observable} An Observable of the index of the first item that + * matches the condition. + * @method find + * @owner Observable + */ +function findIndex(predicate, thisArg) { + return this.lift(new find_1.FindValueOperator(predicate, this, true, thisArg)); +} +exports.findIndex = findIndex; + +},{"./find":597}],599:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var EmptyError_1 = require('../util/EmptyError'); +/** + * Emits only the first value (or the first value that meets some condition) + * emitted by the source Observable. + * + * Emits only the first value. Or emits only the first + * value that passes some test. + * + * + * + * If called with no arguments, `first` emits the first value of the source + * Observable, then completes. If called with a `predicate` function, `first` + * emits the first value of the source that matches the specified condition. It + * may also take a `resultSelector` function to produce the output value from + * the input value, and a `defaultValue` to emit in case the source completes + * before it is able to emit a valid value. Throws an error if `defaultValue` + * was not provided and a matching element is not found. + * + * @example Emit only the first click that happens on the DOM + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.first(); + * result.subscribe(x => console.log(x)); + * + * @example Emits the first click that happens on a DIV + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.first(ev => ev.target.tagName === 'DIV'); + * result.subscribe(x => console.log(x)); + * + * @see {@link filter} + * @see {@link find} + * @see {@link take} + * + * @throws {EmptyError} Delivers an EmptyError to the Observer's `error` + * callback if the Observable completes before any `next` notification was sent. + * + * @param {function(value: T, index: number, source: Observable): boolean} [predicate] + * An optional function called with each item to test for condition matching. + * @param {function(value: T, index: number): R} [resultSelector] A function to + * produce the value on the output Observable based on the values + * and the indices of the source Observable. The arguments passed to this + * function are: + * - `value`: the value that was emitted on the source. + * - `index`: the "index" of the value from the source. + * @param {R} [defaultValue] The default value emitted in case no valid value + * was found on the source. + * @return {Observable} an Observable of the first item that matches the + * condition. + * @method first + * @owner Observable + */ +function first(predicate, resultSelector, defaultValue) { + return this.lift(new FirstOperator(predicate, resultSelector, defaultValue, this)); +} +exports.first = first; +var FirstOperator = (function () { + function FirstOperator(predicate, resultSelector, defaultValue, source) { + this.predicate = predicate; + this.resultSelector = resultSelector; + this.defaultValue = defaultValue; + this.source = source; + } + FirstOperator.prototype.call = function (observer, source) { + return source._subscribe(new FirstSubscriber(observer, this.predicate, this.resultSelector, this.defaultValue, this.source)); + }; + return FirstOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var FirstSubscriber = (function (_super) { + __extends(FirstSubscriber, _super); + function FirstSubscriber(destination, predicate, resultSelector, defaultValue, source) { + _super.call(this, destination); + this.predicate = predicate; + this.resultSelector = resultSelector; + this.defaultValue = defaultValue; + this.source = source; + this.index = 0; + this.hasCompleted = false; + } + FirstSubscriber.prototype._next = function (value) { + var index = this.index++; + if (this.predicate) { + this._tryPredicate(value, index); + } + else { + this._emit(value, index); + } + }; + FirstSubscriber.prototype._tryPredicate = function (value, index) { + var result; + try { + result = this.predicate(value, index, this.source); + } + catch (err) { + this.destination.error(err); + return; + } + if (result) { + this._emit(value, index); + } + }; + FirstSubscriber.prototype._emit = function (value, index) { + if (this.resultSelector) { + this._tryResultSelector(value, index); + return; + } + this._emitFinal(value); + }; + FirstSubscriber.prototype._tryResultSelector = function (value, index) { + var result; + try { + result = this.resultSelector(value, index); + } + catch (err) { + this.destination.error(err); + return; + } + this._emitFinal(result); + }; + FirstSubscriber.prototype._emitFinal = function (value) { + var destination = this.destination; + destination.next(value); + destination.complete(); + this.hasCompleted = true; + }; + FirstSubscriber.prototype._complete = function () { + var destination = this.destination; + if (!this.hasCompleted && typeof this.defaultValue !== 'undefined') { + destination.next(this.defaultValue); + destination.complete(); + } + else if (!this.hasCompleted) { + destination.error(new EmptyError_1.EmptyError); + } + }; + return FirstSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../util/EmptyError":685}],600:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Subscription_1 = require('../Subscription'); +var Observable_1 = require('../Observable'); +var Subject_1 = require('../Subject'); +var Map_1 = require('../util/Map'); +var FastMap_1 = require('../util/FastMap'); +/** + * Groups the items emitted by an Observable according to a specified criterion, + * and emits these grouped items as `GroupedObservables`, one + * {@link GroupedObservable} per group. + * + * + * + * @param {function(value: T): K} keySelector a function that extracts the key + * for each item. + * @param {function(value: T): R} [elementSelector] a function that extracts the + * return element for each item. + * @param {function(grouped: GroupedObservable): Observable} [durationSelector] + * a function that returns an Observable to determine how long each group should + * exist. + * @return {Observable>} an Observable that emits + * GroupedObservables, each of which corresponds to a unique key value and each + * of which emits those items from the source Observable that share that key + * value. + * @method groupBy + * @owner Observable + */ +function groupBy(keySelector, elementSelector, durationSelector) { + return this.lift(new GroupByOperator(this, keySelector, elementSelector, durationSelector)); +} +exports.groupBy = groupBy; +var GroupByOperator = (function () { + function GroupByOperator(source, keySelector, elementSelector, durationSelector) { + this.source = source; + this.keySelector = keySelector; + this.elementSelector = elementSelector; + this.durationSelector = durationSelector; + } + GroupByOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new GroupBySubscriber(subscriber, this.keySelector, this.elementSelector, this.durationSelector)); + }; + return GroupByOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var GroupBySubscriber = (function (_super) { + __extends(GroupBySubscriber, _super); + function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector) { + _super.call(this, destination); + this.keySelector = keySelector; + this.elementSelector = elementSelector; + this.durationSelector = durationSelector; + this.groups = null; + this.attemptedToUnsubscribe = false; + this.count = 0; + } + GroupBySubscriber.prototype._next = function (value) { + var key; + try { + key = this.keySelector(value); + } + catch (err) { + this.error(err); + return; + } + this._group(value, key); + }; + GroupBySubscriber.prototype._group = function (value, key) { + var groups = this.groups; + if (!groups) { + groups = this.groups = typeof key === 'string' ? new FastMap_1.FastMap() : new Map_1.Map(); + } + var group = groups.get(key); + var element; + if (this.elementSelector) { + try { + element = this.elementSelector(value); + } + catch (err) { + this.error(err); + } + } + else { + element = value; + } + if (!group) { + groups.set(key, group = new Subject_1.Subject()); + var groupedObservable = new GroupedObservable(key, group, this); + this.destination.next(groupedObservable); + if (this.durationSelector) { + var duration = void 0; + try { + duration = this.durationSelector(new GroupedObservable(key, group)); + } + catch (err) { + this.error(err); + return; + } + this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this))); + } + } + if (!group.isUnsubscribed) { + group.next(element); + } + }; + GroupBySubscriber.prototype._error = function (err) { + var groups = this.groups; + if (groups) { + groups.forEach(function (group, key) { + group.error(err); + }); + groups.clear(); + } + this.destination.error(err); + }; + GroupBySubscriber.prototype._complete = function () { + var groups = this.groups; + if (groups) { + groups.forEach(function (group, key) { + group.complete(); + }); + groups.clear(); + } + this.destination.complete(); + }; + GroupBySubscriber.prototype.removeGroup = function (key) { + this.groups.delete(key); + }; + GroupBySubscriber.prototype.unsubscribe = function () { + if (!this.isUnsubscribed && !this.attemptedToUnsubscribe) { + this.attemptedToUnsubscribe = true; + if (this.count === 0) { + _super.prototype.unsubscribe.call(this); + } + } + }; + return GroupBySubscriber; +}(Subscriber_1.Subscriber)); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var GroupDurationSubscriber = (function (_super) { + __extends(GroupDurationSubscriber, _super); + function GroupDurationSubscriber(key, group, parent) { + _super.call(this); + this.key = key; + this.group = group; + this.parent = parent; + } + GroupDurationSubscriber.prototype._next = function (value) { + this._complete(); + }; + GroupDurationSubscriber.prototype._error = function (err) { + var group = this.group; + if (!group.isUnsubscribed) { + group.error(err); + } + this.parent.removeGroup(this.key); + }; + GroupDurationSubscriber.prototype._complete = function () { + var group = this.group; + if (!group.isUnsubscribed) { + group.complete(); + } + this.parent.removeGroup(this.key); + }; + return GroupDurationSubscriber; +}(Subscriber_1.Subscriber)); +/** + * An Observable representing values belonging to the same group represented by + * a common key. The values emitted by a GroupedObservable come from the source + * Observable. The common key is available as the field `key` on a + * GroupedObservable instance. + * + * @class GroupedObservable + */ +var GroupedObservable = (function (_super) { + __extends(GroupedObservable, _super); + function GroupedObservable(key, groupSubject, refCountSubscription) { + _super.call(this); + this.key = key; + this.groupSubject = groupSubject; + this.refCountSubscription = refCountSubscription; + } + GroupedObservable.prototype._subscribe = function (subscriber) { + var subscription = new Subscription_1.Subscription(); + var _a = this, refCountSubscription = _a.refCountSubscription, groupSubject = _a.groupSubject; + if (refCountSubscription && !refCountSubscription.isUnsubscribed) { + subscription.add(new InnerRefCountSubscription(refCountSubscription)); + } + subscription.add(groupSubject.subscribe(subscriber)); + return subscription; + }; + return GroupedObservable; +}(Observable_1.Observable)); +exports.GroupedObservable = GroupedObservable; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var InnerRefCountSubscription = (function (_super) { + __extends(InnerRefCountSubscription, _super); + function InnerRefCountSubscription(parent) { + _super.call(this); + this.parent = parent; + parent.count++; + } + InnerRefCountSubscription.prototype.unsubscribe = function () { + var parent = this.parent; + if (!parent.isUnsubscribed && !this.isUnsubscribed) { + _super.prototype.unsubscribe.call(this); + parent.count -= 1; + if (parent.count === 0 && parent.attemptedToUnsubscribe) { + parent.unsubscribe(); + } + } + }; + return InnerRefCountSubscription; +}(Subscription_1.Subscription)); + +},{"../Observable":378,"../Subject":384,"../Subscriber":386,"../Subscription":387,"../util/FastMap":686,"../util/Map":688}],601:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var noop_1 = require('../util/noop'); +/** + * Ignores all items emitted by the source Observable and only passes calls of `complete` or `error`. + * + * + * + * @return {Observable} an empty Observable that only calls `complete` + * or `error`, based on which one is called by the source Observable. + * @method ignoreElements + * @owner Observable + */ +function ignoreElements() { + return this.lift(new IgnoreElementsOperator()); +} +exports.ignoreElements = ignoreElements; +; +var IgnoreElementsOperator = (function () { + function IgnoreElementsOperator() { + } + IgnoreElementsOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new IgnoreElementsSubscriber(subscriber)); + }; + return IgnoreElementsOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var IgnoreElementsSubscriber = (function (_super) { + __extends(IgnoreElementsSubscriber, _super); + function IgnoreElementsSubscriber() { + _super.apply(this, arguments); + } + IgnoreElementsSubscriber.prototype._next = function (unused) { + noop_1.noop(); + }; + return IgnoreElementsSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../util/noop":702}],602:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * If the source Observable is empty it returns an Observable that emits true, otherwise it emits false. + * + * + * + * @return {Observable} an Observable that emits a Boolean. + * @method isEmpty + * @owner Observable + */ +function isEmpty() { + return this.lift(new IsEmptyOperator()); +} +exports.isEmpty = isEmpty; +var IsEmptyOperator = (function () { + function IsEmptyOperator() { + } + IsEmptyOperator.prototype.call = function (observer, source) { + return source._subscribe(new IsEmptySubscriber(observer)); + }; + return IsEmptyOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var IsEmptySubscriber = (function (_super) { + __extends(IsEmptySubscriber, _super); + function IsEmptySubscriber(destination) { + _super.call(this, destination); + } + IsEmptySubscriber.prototype.notifyComplete = function (isEmpty) { + var destination = this.destination; + destination.next(isEmpty); + destination.complete(); + }; + IsEmptySubscriber.prototype._next = function (value) { + this.notifyComplete(false); + }; + IsEmptySubscriber.prototype._complete = function () { + this.notifyComplete(true); + }; + return IsEmptySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],603:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var EmptyError_1 = require('../util/EmptyError'); +/** + * Returns an Observable that emits only the last item emitted by the source Observable. + * It optionally takes a predicate function as a parameter, in which case, rather than emitting + * the last item from the source Observable, the resulting Observable will emit the last item + * from the source Observable that satisfies the predicate. + * + * + * + * @throws {EmptyError} Delivers an EmptyError to the Observer's `error` + * callback if the Observable completes before any `next` notification was sent. + * @param {function} predicate - the condition any source emitted item has to satisfy. + * @return {Observable} an Observable that emits only the last item satisfying the given condition + * from the source, or an NoSuchElementException if no such items are emitted. + * @throws - Throws if no items that match the predicate are emitted by the source Observable. + * @method last + * @owner Observable + */ +function last(predicate, resultSelector, defaultValue) { + return this.lift(new LastOperator(predicate, resultSelector, defaultValue, this)); +} +exports.last = last; +var LastOperator = (function () { + function LastOperator(predicate, resultSelector, defaultValue, source) { + this.predicate = predicate; + this.resultSelector = resultSelector; + this.defaultValue = defaultValue; + this.source = source; + } + LastOperator.prototype.call = function (observer, source) { + return source._subscribe(new LastSubscriber(observer, this.predicate, this.resultSelector, this.defaultValue, this.source)); + }; + return LastOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var LastSubscriber = (function (_super) { + __extends(LastSubscriber, _super); + function LastSubscriber(destination, predicate, resultSelector, defaultValue, source) { + _super.call(this, destination); + this.predicate = predicate; + this.resultSelector = resultSelector; + this.defaultValue = defaultValue; + this.source = source; + this.hasValue = false; + this.index = 0; + if (typeof defaultValue !== 'undefined') { + this.lastValue = defaultValue; + this.hasValue = true; + } + } + LastSubscriber.prototype._next = function (value) { + var index = this.index++; + if (this.predicate) { + this._tryPredicate(value, index); + } + else { + if (this.resultSelector) { + this._tryResultSelector(value, index); + return; + } + this.lastValue = value; + this.hasValue = true; + } + }; + LastSubscriber.prototype._tryPredicate = function (value, index) { + var result; + try { + result = this.predicate(value, index, this.source); + } + catch (err) { + this.destination.error(err); + return; + } + if (result) { + if (this.resultSelector) { + this._tryResultSelector(value, index); + return; + } + this.lastValue = value; + this.hasValue = true; + } + }; + LastSubscriber.prototype._tryResultSelector = function (value, index) { + var result; + try { + result = this.resultSelector(value, index); + } + catch (err) { + this.destination.error(err); + return; + } + this.lastValue = result; + this.hasValue = true; + }; + LastSubscriber.prototype._complete = function () { + var destination = this.destination; + if (this.hasValue) { + destination.next(this.lastValue); + destination.complete(); + } + else { + destination.error(new EmptyError_1.EmptyError); + } + }; + return LastSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../util/EmptyError":685}],604:[function(require,module,exports){ +"use strict"; +/** + * @param func + * @return {Observable} + * @method let + * @owner Observable + */ +function letProto(func) { + return func(this); +} +exports.letProto = letProto; + +},{}],605:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Applies a given `project` function to each value emitted by the source + * Observable, and emits the resulting values as an Observable. + * + * Like [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map), + * it passes each source value through a transformation function to get + * corresponding output values. + * + * + * + * Similar to the well known `Array.prototype.map` function, this operator + * applies a projection to each value and emits that projection in the output + * Observable. + * + * @example Map every every click to the clientX position of that click + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var positions = clicks.map(ev => ev.clientX); + * positions.subscribe(x => console.log(x)); + * + * @see {@link mapTo} + * @see {@link pluck} + * + * @param {function(value: T, index: number): R} project The function to apply + * to each `value` emitted by the source Observable. The `index` parameter is + * the number `i` for the i-th emission that has happened since the + * subscription, starting from the number `0`. + * @param {any} [thisArg] An optional argument to define what `this` is in the + * `project` function. + * @return {Observable} An Observable that emits the values from the source + * Observable transformed by the given `project` function. + * @method map + * @owner Observable + */ +function map(project, thisArg) { + if (typeof project !== 'function') { + throw new TypeError('argument is not a function. Are you looking for `mapTo()`?'); + } + return this.lift(new MapOperator(project, thisArg)); +} +exports.map = map; +var MapOperator = (function () { + function MapOperator(project, thisArg) { + this.project = project; + this.thisArg = thisArg; + } + MapOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new MapSubscriber(subscriber, this.project, this.thisArg)); + }; + return MapOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MapSubscriber = (function (_super) { + __extends(MapSubscriber, _super); + function MapSubscriber(destination, project, thisArg) { + _super.call(this, destination); + this.project = project; + this.count = 0; + this.thisArg = thisArg || this; + } + // NOTE: This looks unoptimized, but it's actually purposefully NOT + // using try/catch optimizations. + MapSubscriber.prototype._next = function (value) { + var result; + try { + result = this.project.call(this.thisArg, value, this.count++); + } + catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + }; + return MapSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],606:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Emits the given constant value on the output Observable every time the source + * Observable emits a value. + * + * Like {@link map}, but it maps every source value to + * the same output value every time. + * + * + * + * Takes a constant `value` as argument, and emits that whenever the source + * Observable emits a value. In other words, ignores the actual source value, + * and simply uses the emission moment to know when to emit the given `value`. + * + * @example Map every every click to the string 'Hi' + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var greetings = clicks.mapTo('Hi'); + * greetings.subscribe(x => console.log(x)); + * + * @see {@link map} + * + * @param {any} value The value to map each source value to. + * @return {Observable} An Observable that emits the given `value` every time + * the source Observable emits something. + * @method mapTo + * @owner Observable + */ +function mapTo(value) { + return this.lift(new MapToOperator(value)); +} +exports.mapTo = mapTo; +var MapToOperator = (function () { + function MapToOperator(value) { + this.value = value; + } + MapToOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new MapToSubscriber(subscriber, this.value)); + }; + return MapToOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MapToSubscriber = (function (_super) { + __extends(MapToSubscriber, _super); + function MapToSubscriber(destination, value) { + _super.call(this, destination); + this.value = value; + } + MapToSubscriber.prototype._next = function (x) { + this.destination.next(this.value); + }; + return MapToSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],607:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Notification_1 = require('../Notification'); +/** + * Represents all of the notifications from the source Observable as `next` + * emissions marked with their original types within {@link Notification} + * objects. + * + * Wraps `next`, `error` and `complete` emissions in + * {@link Notification} objects, emitted as `next` on the output Observable. + * + * + * + * + * `materialize` returns an Observable that emits a `next` notification for each + * `next`, `error`, or `complete` emission of the source Observable. When the + * source Observable emits `complete`, the output Observable will emit `next` as + * a Notification of type "complete", and then it will emit `complete` as well. + * When the source Observable emits `error`, the output will emit `next` as a + * Notification of type "error", and then `complete`. + * + * This operator is useful for producing metadata of the source Observable, to + * be consumed as `next` emissions. Use it in conjunction with + * {@link dematerialize}. + * + * @example Convert a faulty Observable to an Observable of Notifications + * var letters = Rx.Observable.of('a', 'b', 13, 'd'); + * var upperCase = letters.map(x => x.toUpperCase()); + * var materialized = upperCase.materialize(); + * materialized.subscribe(x => console.log(x)); + * + * @see {@link Notification} + * @see {@link dematerialize} + * + * @return {Observable>} An Observable that emits + * {@link Notification} objects that wrap the original emissions from the source + * Observable with metadata. + * @method materialize + * @owner Observable + */ +function materialize() { + return this.lift(new MaterializeOperator()); +} +exports.materialize = materialize; +var MaterializeOperator = (function () { + function MaterializeOperator() { + } + MaterializeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new MaterializeSubscriber(subscriber)); + }; + return MaterializeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MaterializeSubscriber = (function (_super) { + __extends(MaterializeSubscriber, _super); + function MaterializeSubscriber(destination) { + _super.call(this, destination); + } + MaterializeSubscriber.prototype._next = function (value) { + this.destination.next(Notification_1.Notification.createNext(value)); + }; + MaterializeSubscriber.prototype._error = function (err) { + var destination = this.destination; + destination.next(Notification_1.Notification.createError(err)); + destination.complete(); + }; + MaterializeSubscriber.prototype._complete = function () { + var destination = this.destination; + destination.next(Notification_1.Notification.createComplete()); + destination.complete(); + }; + return MaterializeSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Notification":377,"../Subscriber":386}],608:[function(require,module,exports){ +"use strict"; +var reduce_1 = require('./reduce'); +/** + * The Max operator operates on an Observable that emits numbers (or items that can be evaluated as numbers), + * and when source Observable completes it emits a single item: the item with the largest number. + * + * + * + * @param {Function} optional comparer function that it will use instead of its default to compare the value of two + * items. + * @return {Observable} an Observable that emits item with the largest number. + * @method max + * @owner Observable + */ +function max(comparer) { + var max = (typeof comparer === 'function') + ? comparer + : function (x, y) { return x > y ? x : y; }; + return this.lift(new reduce_1.ReduceOperator(max)); +} +exports.max = max; + +},{"./reduce":626}],609:[function(require,module,exports){ +"use strict"; +var ArrayObservable_1 = require('../observable/ArrayObservable'); +var mergeAll_1 = require('./mergeAll'); +var isScheduler_1 = require('../util/isScheduler'); +/** + * Creates an output Observable which concurrently emits all values from every + * given input Observable. + * + * Flattens multiple Observables together by blending + * their values into one Observable. + * + * + * + * `merge` subscribes to each given input Observable (either the source or an + * Observable given as argument), and simply forwards (without doing any + * transformation) all the values from all the input Observables to the output + * Observable. The output Observable only completes once all input Observables + * have completed. Any error delivered by an input Observable will be immediately + * emitted on the output Observable. + * + * @example Merge together two Observables: 1s interval and clicks + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var timer = Rx.Observable.interval(1000); + * var clicksOrTimer = clicks.merge(timer); + * clicksOrTimer.subscribe(x => console.log(x)); + * + * @example Merge together 3 Observables, but only 2 run concurrently + * var timer1 = Rx.Observable.interval(1000).take(10); + * var timer2 = Rx.Observable.interval(2000).take(6); + * var timer3 = Rx.Observable.interval(500).take(10); + * var concurrent = 2; // the argument + * var merged = timer1.merge(timer2, timer3, concurrent); + * merged.subscribe(x => console.log(x)); + * + * @see {@link mergeAll} + * @see {@link mergeMap} + * @see {@link mergeMapTo} + * @see {@link mergeScan} + * + * @param {Observable} other An input Observable to merge with the source + * Observable. More than one input Observables may be given as argument. + * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input + * Observables being subscribed to concurrently. + * @param {Scheduler} [scheduler=null] The Scheduler to use for managing + * concurrency of input Observables. + * @return {Observable} an Observable that emits items that are the result of + * every input Observable. + * @method merge + * @owner Observable + */ +function merge() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + observables.unshift(this); + return mergeStatic.apply(this, observables); +} +exports.merge = merge; +/* tslint:enable:max-line-length */ +/** + * Creates an output Observable which concurrently emits all values from every + * given input Observable. + * + * Flattens multiple Observables together by blending + * their values into one Observable. + * + * + * + * `merge` subscribes to each given input Observable (as arguments), and simply + * forwards (without doing any transformation) all the values from all the input + * Observables to the output Observable. The output Observable only completes + * once all input Observables have completed. Any error delivered by an input + * Observable will be immediately emitted on the output Observable. + * + * @example Merge together two Observables: 1s interval and clicks + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var timer = Rx.Observable.interval(1000); + * var clicksOrTimer = Rx.Observable.merge(clicks, timer); + * clicksOrTimer.subscribe(x => console.log(x)); + * + * @example Merge together 3 Observables, but only 2 run concurrently + * var timer1 = Rx.Observable.interval(1000).take(10); + * var timer2 = Rx.Observable.interval(2000).take(6); + * var timer3 = Rx.Observable.interval(500).take(10); + * var concurrent = 2; // the argument + * var merged = Rx.Observable.merge(timer1, timer2, timer3, concurrent); + * merged.subscribe(x => console.log(x)); + * + * @see {@link mergeAll} + * @see {@link mergeMap} + * @see {@link mergeMapTo} + * @see {@link mergeScan} + * + * @param {Observable} input1 An input Observable to merge with others. + * @param {Observable} input2 An input Observable to merge with others. + * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input + * Observables being subscribed to concurrently. + * @param {Scheduler} [scheduler=null] The Scheduler to use for managing + * concurrency of input Observables. + * @return {Observable} an Observable that emits items that are the result of + * every input Observable. + * @static true + * @name merge + * @owner Observable + */ +function mergeStatic() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + var concurrent = Number.POSITIVE_INFINITY; + var scheduler = null; + var last = observables[observables.length - 1]; + if (isScheduler_1.isScheduler(last)) { + scheduler = observables.pop(); + if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') { + concurrent = observables.pop(); + } + } + else if (typeof last === 'number') { + concurrent = observables.pop(); + } + if (observables.length === 1) { + return observables[0]; + } + return new ArrayObservable_1.ArrayObservable(observables, scheduler).lift(new mergeAll_1.MergeAllOperator(concurrent)); +} +exports.mergeStatic = mergeStatic; + +},{"../observable/ArrayObservable":515,"../util/isScheduler":701,"./mergeAll":610}],610:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Converts a higher-order Observable into a first-order Observable which + * concurrently delivers all values that are emitted on the inner Observables. + * + * Flattens an Observable-of-Observables. + * + * + * + * `mergeAll` subscribes to an Observable that emits Observables, also known as + * a higher-order Observable. Each time it observes one of these emitted inner + * Observables, it subscribes to that and delivers all the values from the + * inner Observable on the output Observable. The output Observable only + * completes once all inner Observables have completed. Any error delivered by + * a inner Observable will be immediately emitted on the output Observable. + * + * @example Spawn a new interval Observable for each click event, and blend their outputs as one Observable + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000)); + * var firstOrder = higherOrder.mergeAll(); + * firstOrder.subscribe(x => console.log(x)); + * + * @example Count from 0 to 9 every second for each click, but only allow 2 concurrent timers + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(10)); + * var firstOrder = higherOrder.mergeAll(2); + * firstOrder.subscribe(x => console.log(x)); + * + * @see {@link combineAll} + * @see {@link concatAll} + * @see {@link exhaust} + * @see {@link merge} + * @see {@link mergeMap} + * @see {@link mergeMapTo} + * @see {@link mergeScan} + * @see {@link switch} + * @see {@link zipAll} + * + * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of inner + * Observables being subscribed to concurrently. + * @return {Observable} An Observable that emits values coming from all the + * inner Observables emitted by the source Observable. + * @method mergeAll + * @owner Observable + */ +function mergeAll(concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + return this.lift(new MergeAllOperator(concurrent)); +} +exports.mergeAll = mergeAll; +var MergeAllOperator = (function () { + function MergeAllOperator(concurrent) { + this.concurrent = concurrent; + } + MergeAllOperator.prototype.call = function (observer, source) { + return source._subscribe(new MergeAllSubscriber(observer, this.concurrent)); + }; + return MergeAllOperator; +}()); +exports.MergeAllOperator = MergeAllOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MergeAllSubscriber = (function (_super) { + __extends(MergeAllSubscriber, _super); + function MergeAllSubscriber(destination, concurrent) { + _super.call(this, destination); + this.concurrent = concurrent; + this.hasCompleted = false; + this.buffer = []; + this.active = 0; + } + MergeAllSubscriber.prototype._next = function (observable) { + if (this.active < this.concurrent) { + this.active++; + this.add(subscribeToResult_1.subscribeToResult(this, observable)); + } + else { + this.buffer.push(observable); + } + }; + MergeAllSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (this.active === 0 && this.buffer.length === 0) { + this.destination.complete(); + } + }; + MergeAllSubscriber.prototype.notifyComplete = function (innerSub) { + var buffer = this.buffer; + this.remove(innerSub); + this.active--; + if (buffer.length > 0) { + this._next(buffer.shift()); + } + else if (this.active === 0 && this.hasCompleted) { + this.destination.complete(); + } + }; + return MergeAllSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.MergeAllSubscriber = MergeAllSubscriber; + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],611:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * Projects each source value to an Observable which is merged in the output + * Observable. + * + * Maps each value to an Observable, then flattens all of + * these inner Observables using {@link mergeAll}. + * + * + * + * Returns an Observable that emits items based on applying a function that you + * supply to each item emitted by the source Observable, where that function + * returns an Observable, and then merging those resulting Observables and + * emitting the results of this merger. + * + * @example Map and flatten each letter to an Observable ticking every 1 second + * var letters = Rx.Observable.of('a', 'b', 'c'); + * var result = letters.mergeMap(x => + * Rx.Observable.interval(1000).map(i => x+i) + * ); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatMap} + * @see {@link exhaustMap} + * @see {@link merge} + * @see {@link mergeAll} + * @see {@link mergeMapTo} + * @see {@link mergeScan} + * @see {@link switchMap} + * + * @param {function(value: T, ?index: number): Observable} project A function + * that, when applied to an item emitted by the source Observable, returns an + * Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input + * Observables being subscribed to concurrently. + * @return {Observable} An Observable that emits the result of applying the + * projection function (and the optional `resultSelector`) to each item emitted + * by the source Observable and merging the results of the Observables obtained + * from this transformation. + * @method mergeMap + * @owner Observable + */ +function mergeMap(project, resultSelector, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + if (typeof resultSelector === 'number') { + concurrent = resultSelector; + resultSelector = null; + } + return this.lift(new MergeMapOperator(project, resultSelector, concurrent)); +} +exports.mergeMap = mergeMap; +var MergeMapOperator = (function () { + function MergeMapOperator(project, resultSelector, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + this.project = project; + this.resultSelector = resultSelector; + this.concurrent = concurrent; + } + MergeMapOperator.prototype.call = function (observer, source) { + return source._subscribe(new MergeMapSubscriber(observer, this.project, this.resultSelector, this.concurrent)); + }; + return MergeMapOperator; +}()); +exports.MergeMapOperator = MergeMapOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MergeMapSubscriber = (function (_super) { + __extends(MergeMapSubscriber, _super); + function MergeMapSubscriber(destination, project, resultSelector, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + _super.call(this, destination); + this.project = project; + this.resultSelector = resultSelector; + this.concurrent = concurrent; + this.hasCompleted = false; + this.buffer = []; + this.active = 0; + this.index = 0; + } + MergeMapSubscriber.prototype._next = function (value) { + if (this.active < this.concurrent) { + this._tryNext(value); + } + else { + this.buffer.push(value); + } + }; + MergeMapSubscriber.prototype._tryNext = function (value) { + var result; + var index = this.index++; + try { + result = this.project(value, index); + } + catch (err) { + this.destination.error(err); + return; + } + this.active++; + this._innerSub(result, value, index); + }; + MergeMapSubscriber.prototype._innerSub = function (ish, value, index) { + this.add(subscribeToResult_1.subscribeToResult(this, ish, value, index)); + }; + MergeMapSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (this.active === 0 && this.buffer.length === 0) { + this.destination.complete(); + } + }; + MergeMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + if (this.resultSelector) { + this._notifyResultSelector(outerValue, innerValue, outerIndex, innerIndex); + } + else { + this.destination.next(innerValue); + } + }; + MergeMapSubscriber.prototype._notifyResultSelector = function (outerValue, innerValue, outerIndex, innerIndex) { + var result; + try { + result = this.resultSelector(outerValue, innerValue, outerIndex, innerIndex); + } + catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + }; + MergeMapSubscriber.prototype.notifyComplete = function (innerSub) { + var buffer = this.buffer; + this.remove(innerSub); + this.active--; + if (buffer.length > 0) { + this._next(buffer.shift()); + } + else if (this.active === 0 && this.hasCompleted) { + this.destination.complete(); + } + }; + return MergeMapSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.MergeMapSubscriber = MergeMapSubscriber; + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],612:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Projects each source value to the same Observable which is merged multiple + * times in the output Observable. + * + * It's like {@link mergeMap}, but maps each value always + * to the same inner Observable. + * + * + * + * Maps each source value to the given Observable `innerObservable` regardless + * of the source value, and then merges those resulting Observables into one + * single Observable, which is the output Observable. + * + * @example For each click event, start an interval Observable ticking every 1 second + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.mergeMapTo(Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatMapTo} + * @see {@link merge} + * @see {@link mergeAll} + * @see {@link mergeMap} + * @see {@link mergeScan} + * @see {@link switchMapTo} + * + * @param {Observable} innerObservable An Observable to replace each value from + * the source Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input + * Observables being subscribed to concurrently. + * @return {Observable} An Observable that emits items from the given + * `innerObservable` (and optionally transformed through `resultSelector`) every + * time a value is emitted on the source Observable. + * @method mergeMapTo + * @owner Observable + */ +function mergeMapTo(innerObservable, resultSelector, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + if (typeof resultSelector === 'number') { + concurrent = resultSelector; + resultSelector = null; + } + return this.lift(new MergeMapToOperator(innerObservable, resultSelector, concurrent)); +} +exports.mergeMapTo = mergeMapTo; +// TODO: Figure out correct signature here: an Operator, R> +// needs to implement call(observer: Subscriber): Subscriber> +var MergeMapToOperator = (function () { + function MergeMapToOperator(ish, resultSelector, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + this.ish = ish; + this.resultSelector = resultSelector; + this.concurrent = concurrent; + } + MergeMapToOperator.prototype.call = function (observer, source) { + return source._subscribe(new MergeMapToSubscriber(observer, this.ish, this.resultSelector, this.concurrent)); + }; + return MergeMapToOperator; +}()); +exports.MergeMapToOperator = MergeMapToOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MergeMapToSubscriber = (function (_super) { + __extends(MergeMapToSubscriber, _super); + function MergeMapToSubscriber(destination, ish, resultSelector, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + _super.call(this, destination); + this.ish = ish; + this.resultSelector = resultSelector; + this.concurrent = concurrent; + this.hasCompleted = false; + this.buffer = []; + this.active = 0; + this.index = 0; + } + MergeMapToSubscriber.prototype._next = function (value) { + if (this.active < this.concurrent) { + var resultSelector = this.resultSelector; + var index = this.index++; + var ish = this.ish; + var destination = this.destination; + this.active++; + this._innerSub(ish, destination, resultSelector, value, index); + } + else { + this.buffer.push(value); + } + }; + MergeMapToSubscriber.prototype._innerSub = function (ish, destination, resultSelector, value, index) { + this.add(subscribeToResult_1.subscribeToResult(this, ish, value, index)); + }; + MergeMapToSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (this.active === 0 && this.buffer.length === 0) { + this.destination.complete(); + } + }; + MergeMapToSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var _a = this, resultSelector = _a.resultSelector, destination = _a.destination; + if (resultSelector) { + this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex); + } + else { + destination.next(innerValue); + } + }; + MergeMapToSubscriber.prototype.trySelectResult = function (outerValue, innerValue, outerIndex, innerIndex) { + var _a = this, resultSelector = _a.resultSelector, destination = _a.destination; + var result; + try { + result = resultSelector(outerValue, innerValue, outerIndex, innerIndex); + } + catch (err) { + destination.error(err); + return; + } + destination.next(result); + }; + MergeMapToSubscriber.prototype.notifyError = function (err) { + this.destination.error(err); + }; + MergeMapToSubscriber.prototype.notifyComplete = function (innerSub) { + var buffer = this.buffer; + this.remove(innerSub); + this.active--; + if (buffer.length > 0) { + this._next(buffer.shift()); + } + else if (this.active === 0 && this.hasCompleted) { + this.destination.complete(); + } + }; + return MergeMapToSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.MergeMapToSubscriber = MergeMapToSubscriber; + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],613:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +/** + * @param project + * @param seed + * @param concurrent + * @return {Observable|WebSocketSubject|Observable} + * @method mergeScan + * @owner Observable + */ +function mergeScan(project, seed, concurrent) { + if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; } + return this.lift(new MergeScanOperator(project, seed, concurrent)); +} +exports.mergeScan = mergeScan; +var MergeScanOperator = (function () { + function MergeScanOperator(project, seed, concurrent) { + this.project = project; + this.seed = seed; + this.concurrent = concurrent; + } + MergeScanOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new MergeScanSubscriber(subscriber, this.project, this.seed, this.concurrent)); + }; + return MergeScanOperator; +}()); +exports.MergeScanOperator = MergeScanOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var MergeScanSubscriber = (function (_super) { + __extends(MergeScanSubscriber, _super); + function MergeScanSubscriber(destination, project, acc, concurrent) { + _super.call(this, destination); + this.project = project; + this.acc = acc; + this.concurrent = concurrent; + this.hasValue = false; + this.hasCompleted = false; + this.buffer = []; + this.active = 0; + this.index = 0; + } + MergeScanSubscriber.prototype._next = function (value) { + if (this.active < this.concurrent) { + var index = this.index++; + var ish = tryCatch_1.tryCatch(this.project)(this.acc, value); + var destination = this.destination; + if (ish === errorObject_1.errorObject) { + destination.error(errorObject_1.errorObject.e); + } + else { + this.active++; + this._innerSub(ish, value, index); + } + } + else { + this.buffer.push(value); + } + }; + MergeScanSubscriber.prototype._innerSub = function (ish, value, index) { + this.add(subscribeToResult_1.subscribeToResult(this, ish, value, index)); + }; + MergeScanSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (this.active === 0 && this.buffer.length === 0) { + if (this.hasValue === false) { + this.destination.next(this.acc); + } + this.destination.complete(); + } + }; + MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var destination = this.destination; + this.acc = innerValue; + this.hasValue = true; + destination.next(innerValue); + }; + MergeScanSubscriber.prototype.notifyComplete = function (innerSub) { + var buffer = this.buffer; + this.remove(innerSub); + this.active--; + if (buffer.length > 0) { + this._next(buffer.shift()); + } + else if (this.active === 0 && this.hasCompleted) { + if (this.hasValue === false) { + this.destination.next(this.acc); + } + this.destination.complete(); + } + }; + return MergeScanSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.MergeScanSubscriber = MergeScanSubscriber; + +},{"../OuterSubscriber":381,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],614:[function(require,module,exports){ +"use strict"; +var reduce_1 = require('./reduce'); +/** + * The Min operator operates on an Observable that emits numbers (or items that can be evaluated as numbers), + * and when source Observable completes it emits a single item: the item with the smallest number. + * + * + * + * @param {Function} optional comparer function that it will use instead of its default to compare the value of two items. + * @return {Observable} an Observable that emits item with the smallest number. + * @method min + * @owner Observable + */ +function min(comparer) { + var min = (typeof comparer === 'function') + ? comparer + : function (x, y) { return x < y ? x : y; }; + return this.lift(new reduce_1.ReduceOperator(min)); +} +exports.min = min; + +},{"./reduce":626}],615:[function(require,module,exports){ +"use strict"; +var MulticastObservable_1 = require('../observable/MulticastObservable'); +var ConnectableObservable_1 = require('../observable/ConnectableObservable'); +/** + * Returns an Observable that emits the results of invoking a specified selector on items + * emitted by a ConnectableObservable that shares a single subscription to the underlying stream. + * + * + * + * @param {Function|Subject} Factory function to create an intermediate subject through + * which the source sequence's elements will be multicast to the selector function + * or Subject to push source elements into. + * @param {Function} Optional selector function that can use the multicasted source stream + * as many times as needed, without causing multiple subscriptions to the source stream. + * Subscribers to the given source will receive all notifications of the source from the + * time of the subscription forward. + * @return {Observable} an Observable that emits the results of invoking the selector + * on the items emitted by a `ConnectableObservable` that shares a single subscription to + * the underlying stream. + * @method multicast + * @owner Observable + */ +function multicast(subjectOrSubjectFactory, selector) { + var subjectFactory; + if (typeof subjectOrSubjectFactory === 'function') { + subjectFactory = subjectOrSubjectFactory; + } + else { + subjectFactory = function subjectFactory() { + return subjectOrSubjectFactory; + }; + } + var connectable = new ConnectableObservable_1.ConnectableObservable(this, subjectFactory); + return selector ? new MulticastObservable_1.MulticastObservable(this, connectable, selector) : connectable; +} +exports.multicast = multicast; + +},{"../observable/ConnectableObservable":518,"../observable/MulticastObservable":530}],616:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Notification_1 = require('../Notification'); +/** + * @see {@link Notification} + * + * @param scheduler + * @param delay + * @return {Observable|WebSocketSubject|Observable} + * @method observeOn + * @owner Observable + */ +function observeOn(scheduler, delay) { + if (delay === void 0) { delay = 0; } + return this.lift(new ObserveOnOperator(scheduler, delay)); +} +exports.observeOn = observeOn; +var ObserveOnOperator = (function () { + function ObserveOnOperator(scheduler, delay) { + if (delay === void 0) { delay = 0; } + this.scheduler = scheduler; + this.delay = delay; + } + ObserveOnOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay)); + }; + return ObserveOnOperator; +}()); +exports.ObserveOnOperator = ObserveOnOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ObserveOnSubscriber = (function (_super) { + __extends(ObserveOnSubscriber, _super); + function ObserveOnSubscriber(destination, scheduler, delay) { + if (delay === void 0) { delay = 0; } + _super.call(this, destination); + this.scheduler = scheduler; + this.delay = delay; + } + ObserveOnSubscriber.dispatch = function (arg) { + var notification = arg.notification, destination = arg.destination; + notification.observe(destination); + }; + ObserveOnSubscriber.prototype.scheduleMessage = function (notification) { + this.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination))); + }; + ObserveOnSubscriber.prototype._next = function (value) { + this.scheduleMessage(Notification_1.Notification.createNext(value)); + }; + ObserveOnSubscriber.prototype._error = function (err) { + this.scheduleMessage(Notification_1.Notification.createError(err)); + }; + ObserveOnSubscriber.prototype._complete = function () { + this.scheduleMessage(Notification_1.Notification.createComplete()); + }; + return ObserveOnSubscriber; +}(Subscriber_1.Subscriber)); +exports.ObserveOnSubscriber = ObserveOnSubscriber; +var ObserveOnMessage = (function () { + function ObserveOnMessage(notification, destination) { + this.notification = notification; + this.destination = destination; + } + return ObserveOnMessage; +}()); +exports.ObserveOnMessage = ObserveOnMessage; + +},{"../Notification":377,"../Subscriber":386}],617:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var FromObservable_1 = require('../observable/FromObservable'); +var isArray_1 = require('../util/isArray'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +function onErrorResumeNext() { + var nextSources = []; + for (var _i = 0; _i < arguments.length; _i++) { + nextSources[_i - 0] = arguments[_i]; + } + if (nextSources.length === 1 && isArray_1.isArray(nextSources[0])) { + nextSources = nextSources[0]; + } + return this.lift(new OnErrorResumeNextOperator(nextSources)); +} +exports.onErrorResumeNext = onErrorResumeNext; +/* tslint:enable:max-line-length */ +function onErrorResumeNextStatic() { + var nextSources = []; + for (var _i = 0; _i < arguments.length; _i++) { + nextSources[_i - 0] = arguments[_i]; + } + var source = null; + if (nextSources.length === 1 && isArray_1.isArray(nextSources[0])) { + nextSources = nextSources[0]; + } + source = nextSources.shift(); + return new FromObservable_1.FromObservable(source, null).lift(new OnErrorResumeNextOperator(nextSources)); +} +exports.onErrorResumeNextStatic = onErrorResumeNextStatic; +var OnErrorResumeNextOperator = (function () { + function OnErrorResumeNextOperator(nextSources) { + this.nextSources = nextSources; + } + OnErrorResumeNextOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources)); + }; + return OnErrorResumeNextOperator; +}()); +var OnErrorResumeNextSubscriber = (function (_super) { + __extends(OnErrorResumeNextSubscriber, _super); + function OnErrorResumeNextSubscriber(destination, nextSources) { + _super.call(this, destination); + this.destination = destination; + this.nextSources = nextSources; + } + OnErrorResumeNextSubscriber.prototype.notifyError = function (error, innerSub) { + this.subscribeToNextSource(); + }; + OnErrorResumeNextSubscriber.prototype.notifyComplete = function (innerSub) { + this.subscribeToNextSource(); + }; + OnErrorResumeNextSubscriber.prototype._error = function (err) { + this.subscribeToNextSource(); + }; + OnErrorResumeNextSubscriber.prototype._complete = function () { + this.subscribeToNextSource(); + }; + OnErrorResumeNextSubscriber.prototype.subscribeToNextSource = function () { + var next = this.nextSources.shift(); + if (next) { + this.add(subscribeToResult_1.subscribeToResult(this, next)); + } + else { + this.destination.complete(); + } + }; + return OnErrorResumeNextSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../observable/FromObservable":525,"../util/isArray":695,"../util/subscribeToResult":705}],618:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Groups pairs of consecutive emissions together and emits them as an array of + * two values. + * + * Puts the current value and previous value together as + * an array, and emits that. + * + * + * + * The Nth emission from the source Observable will cause the output Observable + * to emit an array [(N-1)th, Nth] of the previous and the current value, as a + * pair. For this reason, `pairwise` emits on the second and subsequent + * emissions from the source Observable, but not on the first emission, because + * there is no previous value in that case. + * + * @example On every click (starting from the second), emit the relative distance to the previous click + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var pairs = clicks.pairwise(); + * var distance = pairs.map(pair => { + * var x0 = pair[0].clientX; + * var y0 = pair[0].clientY; + * var x1 = pair[1].clientX; + * var y1 = pair[1].clientY; + * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); + * }); + * distance.subscribe(x => console.log(x)); + * + * @see {@link buffer} + * @see {@link bufferCount} + * + * @return {Observable<[T, T]>} An Observable of pairs of consecutive values + * from the source Observable. + * @method pairwise + * @owner Observable + */ +function pairwise() { + return this.lift(new PairwiseOperator()); +} +exports.pairwise = pairwise; +var PairwiseOperator = (function () { + function PairwiseOperator() { + } + PairwiseOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new PairwiseSubscriber(subscriber)); + }; + return PairwiseOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var PairwiseSubscriber = (function (_super) { + __extends(PairwiseSubscriber, _super); + function PairwiseSubscriber(destination) { + _super.call(this, destination); + this.hasPrev = false; + } + PairwiseSubscriber.prototype._next = function (value) { + if (this.hasPrev) { + this.destination.next([this.prev, value]); + } + else { + this.hasPrev = true; + } + this.prev = value; + }; + return PairwiseSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],619:[function(require,module,exports){ +"use strict"; +var not_1 = require('../util/not'); +var filter_1 = require('./filter'); +/** + * Splits the source Observable into two, one with values that satisfy a + * predicate, and another with values that don't satisfy the predicate. + * + * It's like {@link filter}, but returns two Observables: + * one like the output of {@link filter}, and the other with values that did not + * pass the condition. + * + * + * + * `partition` outputs an array with two Observables that partition the values + * from the source Observable through the given `predicate` function. The first + * Observable in that array emits source values for which the predicate argument + * returns true. The second Observable emits source values for which the + * predicate returns false. The first behaves like {@link filter} and the second + * behaves like {@link filter} with the predicate negated. + * + * @example Partition click events into those on DIV elements and those elsewhere + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var parts = clicks.partition(ev => ev.target.tagName === 'DIV'); + * var clicksOnDivs = parts[0]; + * var clicksElsewhere = parts[1]; + * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x)); + * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x)); + * + * @see {@link filter} + * + * @param {function(value: T, index: number): boolean} predicate A function that + * evaluates each value emitted by the source Observable. If it returns `true`, + * the value is emitted on the first Observable in the returned array, if + * `false` the value is emitted on the second Observable in the array. The + * `index` parameter is the number `i` for the i-th source emission that has + * happened since the subscription, starting from the number `0`. + * @param {any} [thisArg] An optional argument to determine the value of `this` + * in the `predicate` function. + * @return {[Observable, Observable]} An array with two Observables: one + * with values that passed the predicate, and another with values that did not + * pass the predicate. + * @method partition + * @owner Observable + */ +function partition(predicate, thisArg) { + return [ + filter_1.filter.call(this, predicate), + filter_1.filter.call(this, not_1.not(predicate, thisArg)) + ]; +} +exports.partition = partition; + +},{"../util/not":703,"./filter":595}],620:[function(require,module,exports){ +"use strict"; +var map_1 = require('./map'); +/** + * Maps each source value (an object) to its specified nested property. + * + * Like {@link map}, but meant only for picking one of + * the nested properties of every emitted object. + * + * + * + * Given a list of strings describing a path to an object property, retrieves + * the value of a specified nested property from all values in the source + * Observable. If a property can't be resolved, it will return `undefined` for + * that value. + * + * @example Map every every click to the tagName of the clicked target element + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var tagNames = clicks.pluck('target', 'tagName'); + * tagNames.subscribe(x => console.log(x)); + * + * @see {@link map} + * + * @param {...string} properties The nested properties to pluck from each source + * value (an object). + * @return {Observable} Returns a new Observable of property values from the + * source values. + * @method pluck + * @owner Observable + */ +function pluck() { + var properties = []; + for (var _i = 0; _i < arguments.length; _i++) { + properties[_i - 0] = arguments[_i]; + } + var length = properties.length; + if (length === 0) { + throw new Error('List of properties cannot be empty.'); + } + return map_1.map.call(this, plucker(properties, length)); +} +exports.pluck = pluck; +function plucker(props, length) { + var mapper = function (x) { + var currentProp = x; + for (var i = 0; i < length; i++) { + var p = currentProp[props[i]]; + if (typeof p !== 'undefined') { + currentProp = p; + } + else { + return undefined; + } + } + return currentProp; + }; + return mapper; +} + +},{"./map":605}],621:[function(require,module,exports){ +"use strict"; +var Subject_1 = require('../Subject'); +var multicast_1 = require('./multicast'); +/** + * Returns a ConnectableObservable, which is a variety of Observable that waits until its connect method is called + * before it begins emitting items to those Observers that have subscribed to it. + * + * + * + * @param {Function} Optional selector function which can use the multicasted source sequence as many times as needed, + * without causing multiple subscriptions to the source sequence. + * Subscribers to the given source will receive all notifications of the source from the time of the subscription on. + * @return a ConnectableObservable that upon connection causes the source Observable to emit items to its Observers. + * @method publish + * @owner Observable + */ +function publish(selector) { + return selector ? multicast_1.multicast.call(this, function () { return new Subject_1.Subject(); }, selector) : + multicast_1.multicast.call(this, new Subject_1.Subject()); +} +exports.publish = publish; + +},{"../Subject":384,"./multicast":615}],622:[function(require,module,exports){ +"use strict"; +var BehaviorSubject_1 = require('../BehaviorSubject'); +var multicast_1 = require('./multicast'); +/** + * @param value + * @return {ConnectableObservable} + * @method publishBehavior + * @owner Observable + */ +function publishBehavior(value) { + return multicast_1.multicast.call(this, new BehaviorSubject_1.BehaviorSubject(value)); +} +exports.publishBehavior = publishBehavior; + +},{"../BehaviorSubject":375,"./multicast":615}],623:[function(require,module,exports){ +"use strict"; +var AsyncSubject_1 = require('../AsyncSubject'); +var multicast_1 = require('./multicast'); +/** + * @return {ConnectableObservable} + * @method publishLast + * @owner Observable + */ +function publishLast() { + return multicast_1.multicast.call(this, new AsyncSubject_1.AsyncSubject()); +} +exports.publishLast = publishLast; + +},{"../AsyncSubject":374,"./multicast":615}],624:[function(require,module,exports){ +"use strict"; +var ReplaySubject_1 = require('../ReplaySubject'); +var multicast_1 = require('./multicast'); +/** + * @param bufferSize + * @param windowTime + * @param scheduler + * @return {ConnectableObservable} + * @method publishReplay + * @owner Observable + */ +function publishReplay(bufferSize, windowTime, scheduler) { + if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; } + if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; } + return multicast_1.multicast.call(this, new ReplaySubject_1.ReplaySubject(bufferSize, windowTime, scheduler)); +} +exports.publishReplay = publishReplay; + +},{"../ReplaySubject":382,"./multicast":615}],625:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var isArray_1 = require('../util/isArray'); +var ArrayObservable_1 = require('../observable/ArrayObservable'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Returns an Observable that mirrors the first source Observable to emit an item + * from the combination of this Observable and supplied Observables + * @param {...Observables} ...observables sources used to race for which Observable emits first. + * @return {Observable} an Observable that mirrors the output of the first Observable to emit an item. + * @method race + * @owner Observable + */ +function race() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + // if the only argument is an array, it was most likely called with + // `pair([obs1, obs2, ...])` + if (observables.length === 1 && isArray_1.isArray(observables[0])) { + observables = observables[0]; + } + observables.unshift(this); + return raceStatic.apply(this, observables); +} +exports.race = race; +function raceStatic() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + // if the only argument is an array, it was most likely called with + // `pair([obs1, obs2, ...])` + if (observables.length === 1) { + if (isArray_1.isArray(observables[0])) { + observables = observables[0]; + } + else { + return observables[0]; + } + } + return new ArrayObservable_1.ArrayObservable(observables).lift(new RaceOperator()); +} +exports.raceStatic = raceStatic; +var RaceOperator = (function () { + function RaceOperator() { + } + RaceOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new RaceSubscriber(subscriber)); + }; + return RaceOperator; +}()); +exports.RaceOperator = RaceOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var RaceSubscriber = (function (_super) { + __extends(RaceSubscriber, _super); + function RaceSubscriber(destination) { + _super.call(this, destination); + this.hasFirst = false; + this.observables = []; + this.subscriptions = []; + } + RaceSubscriber.prototype._next = function (observable) { + this.observables.push(observable); + }; + RaceSubscriber.prototype._complete = function () { + var observables = this.observables; + var len = observables.length; + if (len === 0) { + this.destination.complete(); + } + else { + for (var i = 0; i < len; i++) { + var observable = observables[i]; + var subscription = subscribeToResult_1.subscribeToResult(this, observable, observable, i); + if (this.subscriptions) { + this.subscriptions.push(subscription); + this.add(subscription); + } + } + this.observables = null; + } + }; + RaceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + if (!this.hasFirst) { + this.hasFirst = true; + for (var i = 0; i < this.subscriptions.length; i++) { + if (i !== outerIndex) { + var subscription = this.subscriptions[i]; + subscription.unsubscribe(); + this.remove(subscription); + } + } + this.subscriptions = null; + } + this.destination.next(innerValue); + }; + return RaceSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); +exports.RaceSubscriber = RaceSubscriber; + +},{"../OuterSubscriber":381,"../observable/ArrayObservable":515,"../util/isArray":695,"../util/subscribeToResult":705}],626:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Applies an accumulator function over the source Observable, and returns the + * accumulated result when the source completes, given an optional seed value. + * + * Combines together all values emitted on the source, + * using an accumulator function that knows how to join a new source value into + * the accumulation from the past. + * + * + * + * Like + * [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce), + * `reduce` applies an `accumulator` function against an accumulation and each + * value of the source Observable (from the past) to reduce it to a single + * value, emitted on the output Observable. Note that `reduce` will only emit + * one value, only when the source Observable completes. It is equivalent to + * applying operator {@link scan} followed by operator {@link last}. + * + * Returns an Observable that applies a specified `accumulator` function to each + * item emitted by the source Observable. If a `seed` value is specified, then + * that value will be used as the initial value for the accumulator. If no seed + * value is specified, the first item of the source is used as the seed. + * + * @example Count the number of click events that happened in 5 seconds + * var clicksInFiveSeconds = Rx.Observable.fromEvent(document, 'click') + * .takeUntil(Rx.Observable.interval(5000)); + * var ones = clicksInFiveSeconds.mapTo(1); + * var seed = 0; + * var count = ones.reduce((acc, one) => acc + one, seed); + * count.subscribe(x => console.log(x)); + * + * @see {@link count} + * @see {@link expand} + * @see {@link mergeScan} + * @see {@link scan} + * + * @param {function(acc: R, value: T): R} accumulator The accumulator function + * called on each source value. + * @param {R} [seed] The initial accumulation value. + * @return {Observable} An observable of the accumulated values. + * @return {Observable} An Observable that emits a single value that is the + * result of accumulating the values emitted by the source Observable. + * @method reduce + * @owner Observable + */ +function reduce(accumulator, seed) { + return this.lift(new ReduceOperator(accumulator, seed)); +} +exports.reduce = reduce; +var ReduceOperator = (function () { + function ReduceOperator(accumulator, seed) { + this.accumulator = accumulator; + this.seed = seed; + } + ReduceOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ReduceSubscriber(subscriber, this.accumulator, this.seed)); + }; + return ReduceOperator; +}()); +exports.ReduceOperator = ReduceOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ReduceSubscriber = (function (_super) { + __extends(ReduceSubscriber, _super); + function ReduceSubscriber(destination, accumulator, seed) { + _super.call(this, destination); + this.accumulator = accumulator; + this.hasValue = false; + this.acc = seed; + this.accumulator = accumulator; + this.hasSeed = typeof seed !== 'undefined'; + } + ReduceSubscriber.prototype._next = function (value) { + if (this.hasValue || (this.hasValue = this.hasSeed)) { + this._tryReduce(value); + } + else { + this.acc = value; + this.hasValue = true; + } + }; + ReduceSubscriber.prototype._tryReduce = function (value) { + var result; + try { + result = this.accumulator(this.acc, value); + } + catch (err) { + this.destination.error(err); + return; + } + this.acc = result; + }; + ReduceSubscriber.prototype._complete = function () { + if (this.hasValue || this.hasSeed) { + this.destination.next(this.acc); + } + this.destination.complete(); + }; + return ReduceSubscriber; +}(Subscriber_1.Subscriber)); +exports.ReduceSubscriber = ReduceSubscriber; + +},{"../Subscriber":386}],627:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var EmptyObservable_1 = require('../observable/EmptyObservable'); +/** + * Returns an Observable that repeats the stream of items emitted by the source Observable at most count times, + * on a particular Scheduler. + * + * + * + * @param {Scheduler} [scheduler] the Scheduler to emit the items on. + * @param {number} [count] the number of times the source Observable items are repeated, a count of 0 will yield + * an empty Observable. + * @return {Observable} an Observable that repeats the stream of items emitted by the source Observable at most + * count times. + * @method repeat + * @owner Observable + */ +function repeat(count) { + if (count === void 0) { count = -1; } + if (count === 0) { + return new EmptyObservable_1.EmptyObservable(); + } + else if (count < 0) { + return this.lift(new RepeatOperator(-1, this)); + } + else { + return this.lift(new RepeatOperator(count - 1, this)); + } +} +exports.repeat = repeat; +var RepeatOperator = (function () { + function RepeatOperator(count, source) { + this.count = count; + this.source = source; + } + RepeatOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new RepeatSubscriber(subscriber, this.count, this.source)); + }; + return RepeatOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var RepeatSubscriber = (function (_super) { + __extends(RepeatSubscriber, _super); + function RepeatSubscriber(destination, count, source) { + _super.call(this, destination); + this.count = count; + this.source = source; + } + RepeatSubscriber.prototype.complete = function () { + if (!this.isStopped) { + var _a = this, source = _a.source, count = _a.count; + if (count === 0) { + return _super.prototype.complete.call(this); + } + else if (count > -1) { + this.count = count - 1; + } + this.unsubscribe(); + this.isStopped = false; + this.isUnsubscribed = false; + source.subscribe(this); + } + }; + return RepeatSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../observable/EmptyObservable":520}],628:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Returns an Observable that mirrors the source Observable, resubscribing to it if it calls `error` and the + * predicate returns true for that specific exception and retry count. + * If the source Observable calls `error`, this method will resubscribe to the source Observable for a maximum of + * count resubscriptions (given as a number parameter) rather than propagating the `error` call. + * + * + * + * Any and all items emitted by the source Observable will be emitted by the resulting Observable, even those emitted + * during failed subscriptions. For example, if an Observable fails at first but emits [1, 2] then succeeds the second + * time and emits: [1, 2, 3, 4, 5] then the complete stream of emissions and notifications + * would be: [1, 2, 1, 2, 3, 4, 5, `complete`]. + * @param {number} number of retry attempts before failing. + * @return {Observable} the source Observable modified with the retry logic. + * @method retry + * @owner Observable + */ +function retry(count) { + if (count === void 0) { count = -1; } + return this.lift(new RetryOperator(count, this)); +} +exports.retry = retry; +var RetryOperator = (function () { + function RetryOperator(count, source) { + this.count = count; + this.source = source; + } + RetryOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new RetrySubscriber(subscriber, this.count, this.source)); + }; + return RetryOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var RetrySubscriber = (function (_super) { + __extends(RetrySubscriber, _super); + function RetrySubscriber(destination, count, source) { + _super.call(this, destination); + this.count = count; + this.source = source; + } + RetrySubscriber.prototype.error = function (err) { + if (!this.isStopped) { + var _a = this, source = _a.source, count = _a.count; + if (count === 0) { + return _super.prototype.error.call(this, err); + } + else if (count > -1) { + this.count = count - 1; + } + this.unsubscribe(); + this.isStopped = false; + this.isUnsubscribed = false; + source.subscribe(this); + } + }; + return RetrySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],629:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../Subject'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Returns an Observable that emits the same values as the source observable with the exception of an `error`. + * An `error` will cause the emission of the Throwable that cause the error to the Observable returned from + * notificationHandler. If that Observable calls onComplete or `error` then retry will call `complete` or `error` + * on the child subscription. Otherwise, this Observable will resubscribe to the source observable, on a particular + * Scheduler. + * + * + * + * @param {notificationHandler} receives an Observable of notifications with which a user can `complete` or `error`, + * aborting the retry. + * @param {scheduler} the Scheduler on which to subscribe to the source Observable. + * @return {Observable} the source Observable modified with retry logic. + * @method retryWhen + * @owner Observable + */ +function retryWhen(notifier) { + return this.lift(new RetryWhenOperator(notifier, this)); +} +exports.retryWhen = retryWhen; +var RetryWhenOperator = (function () { + function RetryWhenOperator(notifier, source) { + this.notifier = notifier; + this.source = source; + } + RetryWhenOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source)); + }; + return RetryWhenOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var RetryWhenSubscriber = (function (_super) { + __extends(RetryWhenSubscriber, _super); + function RetryWhenSubscriber(destination, notifier, source) { + _super.call(this, destination); + this.notifier = notifier; + this.source = source; + } + RetryWhenSubscriber.prototype.error = function (err) { + if (!this.isStopped) { + var errors = this.errors; + var retries = this.retries; + var retriesSubscription = this.retriesSubscription; + if (!retries) { + errors = new Subject_1.Subject(); + retries = tryCatch_1.tryCatch(this.notifier)(errors); + if (retries === errorObject_1.errorObject) { + return _super.prototype.error.call(this, errorObject_1.errorObject.e); + } + retriesSubscription = subscribeToResult_1.subscribeToResult(this, retries); + } + else { + this.errors = null; + this.retriesSubscription = null; + } + this.unsubscribe(); + this.isUnsubscribed = false; + this.errors = errors; + this.retries = retries; + this.retriesSubscription = retriesSubscription; + errors.next(err); + } + }; + RetryWhenSubscriber.prototype._unsubscribe = function () { + var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription; + if (errors) { + errors.unsubscribe(); + this.errors = null; + } + if (retriesSubscription) { + retriesSubscription.unsubscribe(); + this.retriesSubscription = null; + } + this.retries = null; + }; + RetryWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var _a = this, errors = _a.errors, retries = _a.retries, retriesSubscription = _a.retriesSubscription; + this.errors = null; + this.retries = null; + this.retriesSubscription = null; + this.unsubscribe(); + this.isStopped = false; + this.isUnsubscribed = false; + this.errors = errors; + this.retries = retries; + this.retriesSubscription = retriesSubscription; + this.source.subscribe(this); + }; + return RetryWhenSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subject":384,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],630:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Emits the most recently emitted value from the source Observable whenever + * another Observable, the `notifier`, emits. + * + * It's like {@link sampleTime}, but samples whenever + * the `notifier` Observable emits something. + * + * + * + * Whenever the `notifier` Observable emits a value or completes, `sample` + * looks at the source Observable and emits whichever value it has most recently + * emitted since the previous sampling, unless the source has not emitted + * anything since the previous sampling. The `notifier` is subscribed to as soon + * as the output Observable is subscribed. + * + * @example On every click, sample the most recent "seconds" timer + * var seconds = Rx.Observable.interval(1000); + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = seconds.sample(clicks); + * result.subscribe(x => console.log(x)); + * + * @see {@link audit} + * @see {@link debounce} + * @see {@link sampleTime} + * @see {@link throttle} + * + * @param {Observable} notifier The Observable to use for sampling the + * source Observable. + * @return {Observable} An Observable that emits the results of sampling the + * values emitted by the source Observable whenever the notifier Observable + * emits value or completes. + * @method sample + * @owner Observable + */ +function sample(notifier) { + return this.lift(new SampleOperator(notifier)); +} +exports.sample = sample; +var SampleOperator = (function () { + function SampleOperator(notifier) { + this.notifier = notifier; + } + SampleOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SampleSubscriber(subscriber, this.notifier)); + }; + return SampleOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SampleSubscriber = (function (_super) { + __extends(SampleSubscriber, _super); + function SampleSubscriber(destination, notifier) { + _super.call(this, destination); + this.hasValue = false; + this.add(subscribeToResult_1.subscribeToResult(this, notifier)); + } + SampleSubscriber.prototype._next = function (value) { + this.value = value; + this.hasValue = true; + }; + SampleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.emitValue(); + }; + SampleSubscriber.prototype.notifyComplete = function () { + this.emitValue(); + }; + SampleSubscriber.prototype.emitValue = function () { + if (this.hasValue) { + this.hasValue = false; + this.destination.next(this.value); + } + }; + return SampleSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],631:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var async_1 = require('../scheduler/async'); +/** + * Emits the most recently emitted value from the source Observable within + * periodic time intervals. + * + * Samples the source Observable at periodic time + * intervals, emitting what it samples. + * + * + * + * `sampleTime` periodically looks at the source Observable and emits whichever + * value it has most recently emitted since the previous sampling, unless the + * source has not emitted anything since the previous sampling. The sampling + * happens periodically in time every `period` milliseconds (or the time unit + * defined by the optional `scheduler` argument). The sampling starts as soon as + * the output Observable is subscribed. + * + * @example Every second, emit the most recent click at most once + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.sampleTime(1000); + * result.subscribe(x => console.log(x)); + * + * @see {@link auditTime} + * @see {@link debounceTime} + * @see {@link delay} + * @see {@link sample} + * @see {@link throttleTime} + * + * @param {number} period The sampling period expressed in milliseconds or the + * time unit determined internally by the optional `scheduler`. + * @param {Scheduler} [scheduler=async] The {@link Scheduler} to use for + * managing the timers that handle the sampling. + * @return {Observable} An Observable that emits the results of sampling the + * values emitted by the source Observable at the specified time interval. + * @method sampleTime + * @owner Observable + */ +function sampleTime(period, scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new SampleTimeOperator(period, scheduler)); +} +exports.sampleTime = sampleTime; +var SampleTimeOperator = (function () { + function SampleTimeOperator(period, scheduler) { + this.period = period; + this.scheduler = scheduler; + } + SampleTimeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler)); + }; + return SampleTimeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SampleTimeSubscriber = (function (_super) { + __extends(SampleTimeSubscriber, _super); + function SampleTimeSubscriber(destination, period, scheduler) { + _super.call(this, destination); + this.period = period; + this.scheduler = scheduler; + this.hasValue = false; + this.add(scheduler.schedule(dispatchNotification, period, { subscriber: this, period: period })); + } + SampleTimeSubscriber.prototype._next = function (value) { + this.lastValue = value; + this.hasValue = true; + }; + SampleTimeSubscriber.prototype.notifyNext = function () { + if (this.hasValue) { + this.hasValue = false; + this.destination.next(this.lastValue); + } + }; + return SampleTimeSubscriber; +}(Subscriber_1.Subscriber)); +function dispatchNotification(state) { + var subscriber = state.subscriber, period = state.period; + subscriber.notifyNext(); + this.schedule(state, period); +} + +},{"../Subscriber":386,"../scheduler/async":674}],632:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Applies an accumulator function over the source Observable, and returns each + * intermediate result, with an optional seed value. + * + * It's like {@link reduce}, but emits the current + * accumulation whenever the source emits a value. + * + * + * + * Combines together all values emitted on the source, using an accumulator + * function that knows how to join a new source value into the accumulation from + * the past. Is similar to {@link reduce}, but emits the intermediate + * accumulations. + * + * Returns an Observable that applies a specified `accumulator` function to each + * item emitted by the source Observable. If a `seed` value is specified, then + * that value will be used as the initial value for the accumulator. If no seed + * value is specified, the first item of the source is used as the seed. + * + * @example Count the number of click events + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var ones = clicks.mapTo(1); + * var seed = 0; + * var count = ones.scan((acc, one) => acc + one, seed); + * count.subscribe(x => console.log(x)); + * + * @see {@link expand} + * @see {@link mergeScan} + * @see {@link reduce} + * + * @param {function(acc: R, value: T, index: number): R} accumulator + * The accumulator function called on each source value. + * @param {T|R} [seed] The initial accumulation value. + * @return {Observable} An observable of the accumulated values. + * @method scan + * @owner Observable + */ +function scan(accumulator, seed) { + return this.lift(new ScanOperator(accumulator, seed)); +} +exports.scan = scan; +var ScanOperator = (function () { + function ScanOperator(accumulator, seed) { + this.accumulator = accumulator; + this.seed = seed; + } + ScanOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed)); + }; + return ScanOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ScanSubscriber = (function (_super) { + __extends(ScanSubscriber, _super); + function ScanSubscriber(destination, accumulator, seed) { + _super.call(this, destination); + this.accumulator = accumulator; + this.index = 0; + this.accumulatorSet = false; + this.seed = seed; + this.accumulatorSet = typeof seed !== 'undefined'; + } + Object.defineProperty(ScanSubscriber.prototype, "seed", { + get: function () { + return this._seed; + }, + set: function (value) { + this.accumulatorSet = true; + this._seed = value; + }, + enumerable: true, + configurable: true + }); + ScanSubscriber.prototype._next = function (value) { + if (!this.accumulatorSet) { + this.seed = value; + this.destination.next(value); + } + else { + return this._tryNext(value); + } + }; + ScanSubscriber.prototype._tryNext = function (value) { + var index = this.index++; + var result; + try { + result = this.accumulator(this.seed, value, index); + } + catch (err) { + this.destination.error(err); + } + this.seed = result; + this.destination.next(result); + }; + return ScanSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],633:[function(require,module,exports){ +"use strict"; +var multicast_1 = require('./multicast'); +var Subject_1 = require('../Subject'); +function shareSubjectFactory() { + return new Subject_1.Subject(); +} +/** + * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one + * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will + * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`. + * This is an alias for .publish().refCount(). + * + * + * + * @return {Observable} an Observable that upon connection causes the source Observable to emit items to its Observers + * @method share + * @owner Observable + */ +function share() { + return multicast_1.multicast.call(this, shareSubjectFactory).refCount(); +} +exports.share = share; +; + +},{"../Subject":384,"./multicast":615}],634:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var EmptyError_1 = require('../util/EmptyError'); +/** + * Returns an Observable that emits the single item emitted by the source Observable that matches a specified + * predicate, if that Observable emits one such item. If the source Observable emits more than one such item or no + * such items, notify of an IllegalArgumentException or NoSuchElementException respectively. + * + * + * + * @throws {EmptyError} Delivers an EmptyError to the Observer's `error` + * callback if the Observable completes before any `next` notification was sent. + * @param {Function} a predicate function to evaluate items emitted by the source Observable. + * @return {Observable} an Observable that emits the single item emitted by the source Observable that matches + * the predicate. + . + * @method single + * @owner Observable + */ +function single(predicate) { + return this.lift(new SingleOperator(predicate, this)); +} +exports.single = single; +var SingleOperator = (function () { + function SingleOperator(predicate, source) { + this.predicate = predicate; + this.source = source; + } + SingleOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SingleSubscriber(subscriber, this.predicate, this.source)); + }; + return SingleOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SingleSubscriber = (function (_super) { + __extends(SingleSubscriber, _super); + function SingleSubscriber(destination, predicate, source) { + _super.call(this, destination); + this.predicate = predicate; + this.source = source; + this.seenValue = false; + this.index = 0; + } + SingleSubscriber.prototype.applySingleValue = function (value) { + if (this.seenValue) { + this.destination.error('Sequence contains more than one element'); + } + else { + this.seenValue = true; + this.singleValue = value; + } + }; + SingleSubscriber.prototype._next = function (value) { + var predicate = this.predicate; + this.index++; + if (predicate) { + this.tryNext(value); + } + else { + this.applySingleValue(value); + } + }; + SingleSubscriber.prototype.tryNext = function (value) { + try { + var result = this.predicate(value, this.index, this.source); + if (result) { + this.applySingleValue(value); + } + } + catch (err) { + this.destination.error(err); + } + }; + SingleSubscriber.prototype._complete = function () { + var destination = this.destination; + if (this.index > 0) { + destination.next(this.seenValue ? this.singleValue : undefined); + destination.complete(); + } + else { + destination.error(new EmptyError_1.EmptyError); + } + }; + return SingleSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../util/EmptyError":685}],635:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Returns an Observable that skips `n` items emitted by an Observable. + * + * + * + * @param {Number} the `n` of times, items emitted by source Observable should be skipped. + * @return {Observable} an Observable that skips values emitted by the source Observable. + * + * @method skip + * @owner Observable + */ +function skip(total) { + return this.lift(new SkipOperator(total)); +} +exports.skip = skip; +var SkipOperator = (function () { + function SkipOperator(total) { + this.total = total; + } + SkipOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SkipSubscriber(subscriber, this.total)); + }; + return SkipOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SkipSubscriber = (function (_super) { + __extends(SkipSubscriber, _super); + function SkipSubscriber(destination, total) { + _super.call(this, destination); + this.total = total; + this.count = 0; + } + SkipSubscriber.prototype._next = function (x) { + if (++this.count > this.total) { + this.destination.next(x); + } + }; + return SkipSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],636:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item. + * + * + * + * @param {Observable} the second Observable that has to emit an item before the source Observable's elements begin to + * be mirrored by the resulting Observable. + * @return {Observable} an Observable that skips items from the source Observable until the second Observable emits + * an item, then emits the remaining items. + * @method skipUntil + * @owner Observable + */ +function skipUntil(notifier) { + return this.lift(new SkipUntilOperator(notifier)); +} +exports.skipUntil = skipUntil; +var SkipUntilOperator = (function () { + function SkipUntilOperator(notifier) { + this.notifier = notifier; + } + SkipUntilOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SkipUntilSubscriber(subscriber, this.notifier)); + }; + return SkipUntilOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SkipUntilSubscriber = (function (_super) { + __extends(SkipUntilSubscriber, _super); + function SkipUntilSubscriber(destination, notifier) { + _super.call(this, destination); + this.hasValue = false; + this.isInnerStopped = false; + this.add(subscribeToResult_1.subscribeToResult(this, notifier)); + } + SkipUntilSubscriber.prototype._next = function (value) { + if (this.hasValue) { + _super.prototype._next.call(this, value); + } + }; + SkipUntilSubscriber.prototype._complete = function () { + if (this.isInnerStopped) { + _super.prototype._complete.call(this); + } + else { + this.unsubscribe(); + } + }; + SkipUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.hasValue = true; + }; + SkipUntilSubscriber.prototype.notifyComplete = function () { + this.isInnerStopped = true; + if (this.isStopped) { + _super.prototype._complete.call(this); + } + }; + return SkipUntilSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],637:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds + * true, but emits all further source items as soon as the condition becomes false. + * + * + * + * @param {Function} predicate - a function to test each item emitted from the source Observable. + * @return {Observable} an Observable that begins emitting items emitted by the source Observable when the + * specified predicate becomes false. + * @method skipWhile + * @owner Observable + */ +function skipWhile(predicate) { + return this.lift(new SkipWhileOperator(predicate)); +} +exports.skipWhile = skipWhile; +var SkipWhileOperator = (function () { + function SkipWhileOperator(predicate) { + this.predicate = predicate; + } + SkipWhileOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SkipWhileSubscriber(subscriber, this.predicate)); + }; + return SkipWhileOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SkipWhileSubscriber = (function (_super) { + __extends(SkipWhileSubscriber, _super); + function SkipWhileSubscriber(destination, predicate) { + _super.call(this, destination); + this.predicate = predicate; + this.skipping = true; + this.index = 0; + } + SkipWhileSubscriber.prototype._next = function (value) { + var destination = this.destination; + if (this.skipping) { + this.tryCallPredicate(value); + } + if (!this.skipping) { + destination.next(value); + } + }; + SkipWhileSubscriber.prototype.tryCallPredicate = function (value) { + try { + var result = this.predicate(value, this.index++); + this.skipping = Boolean(result); + } + catch (err) { + this.destination.error(err); + } + }; + return SkipWhileSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],638:[function(require,module,exports){ +"use strict"; +var ArrayObservable_1 = require('../observable/ArrayObservable'); +var ScalarObservable_1 = require('../observable/ScalarObservable'); +var EmptyObservable_1 = require('../observable/EmptyObservable'); +var concat_1 = require('./concat'); +var isScheduler_1 = require('../util/isScheduler'); +/** + * Returns an Observable that emits the items in a specified Iterable before it begins to emit items emitted by the + * source Observable. + * + * + * + * @param {Values} an Iterable that contains the items you want the modified Observable to emit first. + * @return {Observable} an Observable that emits the items in the specified Iterable and then emits the items + * emitted by the source Observable. + * @method startWith + * @owner Observable + */ +function startWith() { + var array = []; + for (var _i = 0; _i < arguments.length; _i++) { + array[_i - 0] = arguments[_i]; + } + var scheduler = array[array.length - 1]; + if (isScheduler_1.isScheduler(scheduler)) { + array.pop(); + } + else { + scheduler = null; + } + var len = array.length; + if (len === 1) { + return concat_1.concatStatic(new ScalarObservable_1.ScalarObservable(array[0], scheduler), this); + } + else if (len > 1) { + return concat_1.concatStatic(new ArrayObservable_1.ArrayObservable(array, scheduler), this); + } + else { + return concat_1.concatStatic(new EmptyObservable_1.EmptyObservable(scheduler), this); + } +} +exports.startWith = startWith; + +},{"../observable/ArrayObservable":515,"../observable/EmptyObservable":520,"../observable/ScalarObservable":534,"../util/isScheduler":701,"./concat":574}],639:[function(require,module,exports){ +"use strict"; +var SubscribeOnObservable_1 = require('../observable/SubscribeOnObservable'); +/** + * Asynchronously subscribes Observers to this Observable on the specified Scheduler. + * + * + * + * @param {Scheduler} the Scheduler to perform subscription actions on. + * @return {Observable} the source Observable modified so that its subscriptions happen on the specified Scheduler + . + * @method subscribeOn + * @owner Observable + */ +function subscribeOn(scheduler, delay) { + if (delay === void 0) { delay = 0; } + return new SubscribeOnObservable_1.SubscribeOnObservable(this, delay, scheduler); +} +exports.subscribeOn = subscribeOn; + +},{"../observable/SubscribeOnObservable":535}],640:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Converts a higher-order Observable into a first-order Observable by + * subscribing to only the most recently emitted of those inner Observables. + * + * Flattens an Observable-of-Observables by dropping the + * previous inner Observable once a new one appears. + * + * + * + * `switch` subscribes to an Observable that emits Observables, also known as a + * higher-order Observable. Each time it observes one of these emitted inner + * Observables, the output Observable subscribes to the inner Observable and + * begins emitting the items emitted by that. So far, it behaves + * like {@link mergeAll}. However, when a new inner Observable is emitted, + * `switch` unsubscribes from the earlier-emitted inner Observable and + * subscribes to the new inner Observable and begins emitting items from it. It + * continues to behave like this for subsequent inner Observables. + * + * @example Rerun an interval Observable on every click event + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * // Each click event is mapped to an Observable that ticks every second + * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000)); + * var switched = higherOrder.switch(); + * // The outcome is that `switched` is essentially a timer that restarts + * // on every click. The interval Observables from older clicks do not merge + * // with the current interval Observable. + * switched.subscribe(x => console.log(x)); + * + * @see {@link combineAll} + * @see {@link concatAll} + * @see {@link exhaust} + * @see {@link mergeAll} + * @see {@link switchMap} + * @see {@link switchMapTo} + * @see {@link zipAll} + * + * @return {Observable} An Observable that emits the items emitted by the + * Observable most recently emitted by the source Observable. + * @method switch + * @name switch + * @owner Observable + */ +function _switch() { + return this.lift(new SwitchOperator()); +} +exports._switch = _switch; +var SwitchOperator = (function () { + function SwitchOperator() { + } + SwitchOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SwitchSubscriber(subscriber)); + }; + return SwitchOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SwitchSubscriber = (function (_super) { + __extends(SwitchSubscriber, _super); + function SwitchSubscriber(destination) { + _super.call(this, destination); + this.active = 0; + this.hasCompleted = false; + } + SwitchSubscriber.prototype._next = function (value) { + this.unsubscribeInner(); + this.active++; + this.add(this.innerSubscription = subscribeToResult_1.subscribeToResult(this, value)); + }; + SwitchSubscriber.prototype._complete = function () { + this.hasCompleted = true; + if (this.active === 0) { + this.destination.complete(); + } + }; + SwitchSubscriber.prototype.unsubscribeInner = function () { + this.active = this.active > 0 ? this.active - 1 : 0; + var innerSubscription = this.innerSubscription; + if (innerSubscription) { + innerSubscription.unsubscribe(); + this.remove(innerSubscription); + } + }; + SwitchSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.destination.next(innerValue); + }; + SwitchSubscriber.prototype.notifyError = function (err) { + this.destination.error(err); + }; + SwitchSubscriber.prototype.notifyComplete = function () { + this.unsubscribeInner(); + if (this.hasCompleted && this.active === 0) { + this.destination.complete(); + } + }; + return SwitchSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],641:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Projects each source value to an Observable which is merged in the output + * Observable, emitting values only from the most recently projected Observable. + * + * Maps each value to an Observable, then flattens all of + * these inner Observables using {@link switch}. + * + * + * + * Returns an Observable that emits items based on applying a function that you + * supply to each item emitted by the source Observable, where that function + * returns an (so-called "inner") Observable. Each time it observes one of these + * inner Observables, the output Observable begins emitting the items emitted by + * that inner Observable. When a new inner Observable is emitted, `switchMap` + * stops emitting items from the earlier-emitted inner Observable and begins + * emitting items from the new one. It continues to behave like this for + * subsequent inner Observables. + * + * @example Rerun an interval Observable on every click event + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.switchMap((ev) => Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatMap} + * @see {@link exhaustMap} + * @see {@link mergeMap} + * @see {@link switch} + * @see {@link switchMapTo} + * + * @param {function(value: T, ?index: number): Observable} project A function + * that, when applied to an item emitted by the source Observable, returns an + * Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @return {Observable} An Observable that emits the result of applying the + * projection function (and the optional `resultSelector`) to each item emitted + * by the source Observable and taking only the values from the most recently + * projected inner Observable. + * @method switchMap + * @owner Observable + */ +function switchMap(project, resultSelector) { + return this.lift(new SwitchMapOperator(project, resultSelector)); +} +exports.switchMap = switchMap; +var SwitchMapOperator = (function () { + function SwitchMapOperator(project, resultSelector) { + this.project = project; + this.resultSelector = resultSelector; + } + SwitchMapOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SwitchMapSubscriber(subscriber, this.project, this.resultSelector)); + }; + return SwitchMapOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SwitchMapSubscriber = (function (_super) { + __extends(SwitchMapSubscriber, _super); + function SwitchMapSubscriber(destination, project, resultSelector) { + _super.call(this, destination); + this.project = project; + this.resultSelector = resultSelector; + this.index = 0; + } + SwitchMapSubscriber.prototype._next = function (value) { + var result; + var index = this.index++; + try { + result = this.project(value, index); + } + catch (error) { + this.destination.error(error); + return; + } + this._innerSub(result, value, index); + }; + SwitchMapSubscriber.prototype._innerSub = function (result, value, index) { + var innerSubscription = this.innerSubscription; + if (innerSubscription) { + innerSubscription.unsubscribe(); + } + this.add(this.innerSubscription = subscribeToResult_1.subscribeToResult(this, result, value, index)); + }; + SwitchMapSubscriber.prototype._complete = function () { + var innerSubscription = this.innerSubscription; + if (!innerSubscription || innerSubscription.isUnsubscribed) { + _super.prototype._complete.call(this); + } + }; + SwitchMapSubscriber.prototype._unsubscribe = function () { + this.innerSubscription = null; + }; + SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) { + this.remove(innerSub); + this.innerSubscription = null; + if (this.isStopped) { + _super.prototype._complete.call(this); + } + }; + SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + if (this.resultSelector) { + this._tryNotifyNext(outerValue, innerValue, outerIndex, innerIndex); + } + else { + this.destination.next(innerValue); + } + }; + SwitchMapSubscriber.prototype._tryNotifyNext = function (outerValue, innerValue, outerIndex, innerIndex) { + var result; + try { + result = this.resultSelector(outerValue, innerValue, outerIndex, innerIndex); + } + catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + }; + return SwitchMapSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],642:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Projects each source value to the same Observable which is flattened multiple + * times with {@link switch} in the output Observable. + * + * It's like {@link switchMap}, but maps each value + * always to the same inner Observable. + * + * + * + * Maps each source value to the given Observable `innerObservable` regardless + * of the source value, and then flattens those resulting Observables into one + * single Observable, which is the output Observable. The output Observables + * emits values only from the most recently emitted instance of + * `innerObservable`. + * + * @example Rerun an interval Observable on every click event + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.switchMapTo(Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link concatMapTo} + * @see {@link switch} + * @see {@link switchMap} + * @see {@link mergeMapTo} + * + * @param {Observable} innerObservable An Observable to replace each value from + * the source Observable. + * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector] + * A function to produce the value on the output Observable based on the values + * and the indices of the source (outer) emission and the inner Observable + * emission. The arguments passed to this function are: + * - `outerValue`: the value that came from the source + * - `innerValue`: the value that came from the projected Observable + * - `outerIndex`: the "index" of the value that came from the source + * - `innerIndex`: the "index" of the value from the projected Observable + * @return {Observable} An Observable that emits items from the given + * `innerObservable` every time a value is emitted on the source Observable. + * @return {Observable} An Observable that emits items from the given + * `innerObservable` (and optionally transformed through `resultSelector`) every + * time a value is emitted on the source Observable, and taking only the values + * from the most recently projected inner Observable. + * @method switchMapTo + * @owner Observable + */ +function switchMapTo(innerObservable, resultSelector) { + return this.lift(new SwitchMapToOperator(innerObservable, resultSelector)); +} +exports.switchMapTo = switchMapTo; +var SwitchMapToOperator = (function () { + function SwitchMapToOperator(observable, resultSelector) { + this.observable = observable; + this.resultSelector = resultSelector; + } + SwitchMapToOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new SwitchMapToSubscriber(subscriber, this.observable, this.resultSelector)); + }; + return SwitchMapToOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var SwitchMapToSubscriber = (function (_super) { + __extends(SwitchMapToSubscriber, _super); + function SwitchMapToSubscriber(destination, inner, resultSelector) { + _super.call(this, destination); + this.inner = inner; + this.resultSelector = resultSelector; + this.index = 0; + } + SwitchMapToSubscriber.prototype._next = function (value) { + var innerSubscription = this.innerSubscription; + if (innerSubscription) { + innerSubscription.unsubscribe(); + } + this.add(this.innerSubscription = subscribeToResult_1.subscribeToResult(this, this.inner, value, this.index++)); + }; + SwitchMapToSubscriber.prototype._complete = function () { + var innerSubscription = this.innerSubscription; + if (!innerSubscription || innerSubscription.isUnsubscribed) { + _super.prototype._complete.call(this); + } + }; + SwitchMapToSubscriber.prototype._unsubscribe = function () { + this.innerSubscription = null; + }; + SwitchMapToSubscriber.prototype.notifyComplete = function (innerSub) { + this.remove(innerSub); + this.innerSubscription = null; + if (this.isStopped) { + _super.prototype._complete.call(this); + } + }; + SwitchMapToSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + var _a = this, resultSelector = _a.resultSelector, destination = _a.destination; + if (resultSelector) { + this.tryResultSelector(outerValue, innerValue, outerIndex, innerIndex); + } + else { + destination.next(innerValue); + } + }; + SwitchMapToSubscriber.prototype.tryResultSelector = function (outerValue, innerValue, outerIndex, innerIndex) { + var _a = this, resultSelector = _a.resultSelector, destination = _a.destination; + var result; + try { + result = resultSelector(outerValue, innerValue, outerIndex, innerIndex); + } + catch (err) { + destination.error(err); + return; + } + destination.next(result); + }; + return SwitchMapToSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],643:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var ArgumentOutOfRangeError_1 = require('../util/ArgumentOutOfRangeError'); +var EmptyObservable_1 = require('../observable/EmptyObservable'); +/** + * Emits only the first `count` values emitted by the source Observable. + * + * Takes the first `count` values from the source, then + * completes. + * + * + * + * `take` returns an Observable that emits only the first `count` values emitted + * by the source Observable. If the source emits fewer than `count` values then + * all of its values are emitted. After that, it completes, regardless if the + * source completes. + * + * @example Take the first 5 seconds of an infinite 1-second interval Observable + * var interval = Rx.Observable.interval(1000); + * var five = interval.take(5); + * five.subscribe(x => console.log(x)); + * + * @see {@link takeLast} + * @see {@link takeUntil} + * @see {@link takeWhile} + * @see {@link skip} + * + * @throws {ArgumentOutOfRangeError} When using `take(i)`, it delivers an + * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`. + * + * @param {number} count The maximum number of `next` values to emit. + * @return {Observable} An Observable that emits only the first `count` + * values emitted by the source Observable, or all of the values from the source + * if the source emits fewer than `count` values. + * @method take + * @owner Observable + */ +function take(count) { + if (count === 0) { + return new EmptyObservable_1.EmptyObservable(); + } + else { + return this.lift(new TakeOperator(count)); + } +} +exports.take = take; +var TakeOperator = (function () { + function TakeOperator(total) { + this.total = total; + if (this.total < 0) { + throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; + } + } + TakeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new TakeSubscriber(subscriber, this.total)); + }; + return TakeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TakeSubscriber = (function (_super) { + __extends(TakeSubscriber, _super); + function TakeSubscriber(destination, total) { + _super.call(this, destination); + this.total = total; + this.count = 0; + } + TakeSubscriber.prototype._next = function (value) { + var total = this.total; + if (++this.count <= total) { + this.destination.next(value); + if (this.count === total) { + this.destination.complete(); + this.unsubscribe(); + } + } + }; + return TakeSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../observable/EmptyObservable":520,"../util/ArgumentOutOfRangeError":684}],644:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var ArgumentOutOfRangeError_1 = require('../util/ArgumentOutOfRangeError'); +var EmptyObservable_1 = require('../observable/EmptyObservable'); +/** + * Emits only the last `count` values emitted by the source Observable. + * + * Remembers the latest `count` values, then emits those + * only when the source completes. + * + * + * + * `takeLast` returns an Observable that emits at most the last `count` values + * emitted by the source Observable. If the source emits fewer than `count` + * values then all of its values are emitted. This operator must wait until the + * `complete` notification emission from the source in order to emit the `next` + * values on the output Observable, because otherwise it is impossible to know + * whether or not more values will be emitted on the source. For this reason, + * all values are emitted synchronously, followed by the complete notification. + * + * @example Take the last 3 values of an Observable with many values + * var many = Rx.Observable.range(1, 100); + * var lastThree = many.takeLast(3); + * lastThree.subscribe(x => console.log(x)); + * + * @see {@link take} + * @see {@link takeUntil} + * @see {@link takeWhile} + * @see {@link skip} + * + * @throws {ArgumentOutOfRangeError} When using `takeLast(i)`, it delivers an + * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`. + * + * @param {number} count The maximum number of values to emit from the end of + * the sequence of values emitted by the source Observable. + * @return {Observable} An Observable that emits at most the last count + * values emitted by the source Observable. + * @method takeLast + * @owner Observable + */ +function takeLast(count) { + if (count === 0) { + return new EmptyObservable_1.EmptyObservable(); + } + else { + return this.lift(new TakeLastOperator(count)); + } +} +exports.takeLast = takeLast; +var TakeLastOperator = (function () { + function TakeLastOperator(total) { + this.total = total; + if (this.total < 0) { + throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; + } + } + TakeLastOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new TakeLastSubscriber(subscriber, this.total)); + }; + return TakeLastOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TakeLastSubscriber = (function (_super) { + __extends(TakeLastSubscriber, _super); + function TakeLastSubscriber(destination, total) { + _super.call(this, destination); + this.total = total; + this.ring = new Array(); + this.count = 0; + } + TakeLastSubscriber.prototype._next = function (value) { + var ring = this.ring; + var total = this.total; + var count = this.count++; + if (ring.length < total) { + ring.push(value); + } + else { + var index = count % total; + ring[index] = value; + } + }; + TakeLastSubscriber.prototype._complete = function () { + var destination = this.destination; + var count = this.count; + if (count > 0) { + var total = this.count >= this.total ? this.total : this.count; + var ring = this.ring; + for (var i = 0; i < total; i++) { + var idx = (count++) % total; + destination.next(ring[idx]); + } + } + destination.complete(); + }; + return TakeLastSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../observable/EmptyObservable":520,"../util/ArgumentOutOfRangeError":684}],645:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Emits the values emitted by the source Observable until a `notifier` + * Observable emits a value. + * + * Lets values pass until a second Observable, + * `notifier`, emits something. Then, it completes. + * + * + * + * `takeUntil` subscribes and begins mirroring the source Observable. It also + * monitors a second Observable, `notifier` that you provide. If the `notifier` + * emits a value or a complete notification, the output Observable stops + * mirroring the source Observable and completes. + * + * @example Tick every second until the first click happens + * var interval = Rx.Observable.interval(1000); + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = interval.takeUntil(clicks); + * result.subscribe(x => console.log(x)); + * + * @see {@link take} + * @see {@link takeLast} + * @see {@link takeWhile} + * @see {@link skip} + * + * @param {Observable} notifier The Observable whose first emitted value will + * cause the output Observable of `takeUntil` to stop emitting values from the + * source Observable. + * @return {Observable} An Observable that emits the values from the source + * Observable until such time as `notifier` emits its first value. + * @method takeUntil + * @owner Observable + */ +function takeUntil(notifier) { + return this.lift(new TakeUntilOperator(notifier)); +} +exports.takeUntil = takeUntil; +var TakeUntilOperator = (function () { + function TakeUntilOperator(notifier) { + this.notifier = notifier; + } + TakeUntilOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new TakeUntilSubscriber(subscriber, this.notifier)); + }; + return TakeUntilOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TakeUntilSubscriber = (function (_super) { + __extends(TakeUntilSubscriber, _super); + function TakeUntilSubscriber(destination, notifier) { + _super.call(this, destination); + this.notifier = notifier; + this.add(subscribeToResult_1.subscribeToResult(this, notifier)); + } + TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.complete(); + }; + TakeUntilSubscriber.prototype.notifyComplete = function () { + // noop + }; + return TakeUntilSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],646:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * Emits values emitted by the source Observable so long as each value satisfies + * the given `predicate`, and then completes as soon as this `predicate` is not + * satisfied. + * + * Takes values from the source only while they pass the + * condition given. When the first value does not satisfy, it completes. + * + * + * + * `takeWhile` subscribes and begins mirroring the source Observable. Each value + * emitted on the source is given to the `predicate` function which returns a + * boolean, representing a condition to be satisfied by the source values. The + * output Observable emits the source values until such time as the `predicate` + * returns false, at which point `takeWhile` stops mirroring the source + * Observable and completes the output Observable. + * + * @example Emit click events only while the clientX property is greater than 200 + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.takeWhile(ev => ev.clientX > 200); + * result.subscribe(x => console.log(x)); + * + * @see {@link take} + * @see {@link takeLast} + * @see {@link takeUntil} + * @see {@link skip} + * + * @param {function(value: T, index: number): boolean} predicate A function that + * evaluates a value emitted by the source Observable and returns a boolean. + * Also takes the (zero-based) index as the second argument. + * @return {Observable} An Observable that emits the values from the source + * Observable so long as each value satisfies the condition defined by the + * `predicate`, then completes. + * @method takeWhile + * @owner Observable + */ +function takeWhile(predicate) { + return this.lift(new TakeWhileOperator(predicate)); +} +exports.takeWhile = takeWhile; +var TakeWhileOperator = (function () { + function TakeWhileOperator(predicate) { + this.predicate = predicate; + } + TakeWhileOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new TakeWhileSubscriber(subscriber, this.predicate)); + }; + return TakeWhileOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TakeWhileSubscriber = (function (_super) { + __extends(TakeWhileSubscriber, _super); + function TakeWhileSubscriber(destination, predicate) { + _super.call(this, destination); + this.predicate = predicate; + this.index = 0; + } + TakeWhileSubscriber.prototype._next = function (value) { + var destination = this.destination; + var result; + try { + result = this.predicate(value, this.index++); + } + catch (err) { + destination.error(err); + return; + } + this.nextOrComplete(value, result); + }; + TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) { + var destination = this.destination; + if (Boolean(predicateResult)) { + destination.next(value); + } + else { + destination.complete(); + } + }; + return TakeWhileSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],647:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Emits a value from the source Observable, then ignores subsequent source + * values for a duration determined by another Observable, then repeats this + * process. + * + * It's like {@link throttleTime}, but the silencing + * duration is determined by a second Observable. + * + * + * + * `throttle` emits the source Observable values on the output Observable + * when its internal timer is disabled, and ignores source values when the timer + * is enabled. Initially, the timer is disabled. As soon as the first source + * value arrives, it is forwarded to the output Observable, and then the timer + * is enabled by calling the `durationSelector` function with the source value, + * which returns the "duration" Observable. When the duration Observable emits a + * value or completes, the timer is disabled, and this process repeats for the + * next source value. + * + * @example Emit clicks at a rate of at most one click per second + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.throttle(ev => Rx.Observable.interval(1000)); + * result.subscribe(x => console.log(x)); + * + * @see {@link audit} + * @see {@link debounce} + * @see {@link delayWhen} + * @see {@link sample} + * @see {@link throttleTime} + * + * @param {function(value: T): Observable|Promise} durationSelector A function + * that receives a value from the source Observable, for computing the silencing + * duration for each source value, returned as an Observable or a Promise. + * @return {Observable} An Observable that performs the throttle operation to + * limit the rate of emissions from the source. + * @method throttle + * @owner Observable + */ +function throttle(durationSelector) { + return this.lift(new ThrottleOperator(durationSelector)); +} +exports.throttle = throttle; +var ThrottleOperator = (function () { + function ThrottleOperator(durationSelector) { + this.durationSelector = durationSelector; + } + ThrottleOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ThrottleSubscriber(subscriber, this.durationSelector)); + }; + return ThrottleOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ThrottleSubscriber = (function (_super) { + __extends(ThrottleSubscriber, _super); + function ThrottleSubscriber(destination, durationSelector) { + _super.call(this, destination); + this.destination = destination; + this.durationSelector = durationSelector; + } + ThrottleSubscriber.prototype._next = function (value) { + if (!this.throttled) { + this.tryDurationSelector(value); + } + }; + ThrottleSubscriber.prototype.tryDurationSelector = function (value) { + var duration = null; + try { + duration = this.durationSelector(value); + } + catch (err) { + this.destination.error(err); + return; + } + this.emitAndThrottle(value, duration); + }; + ThrottleSubscriber.prototype.emitAndThrottle = function (value, duration) { + this.add(this.throttled = subscribeToResult_1.subscribeToResult(this, duration)); + this.destination.next(value); + }; + ThrottleSubscriber.prototype._unsubscribe = function () { + var throttled = this.throttled; + if (throttled) { + this.remove(throttled); + this.throttled = null; + throttled.unsubscribe(); + } + }; + ThrottleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this._unsubscribe(); + }; + ThrottleSubscriber.prototype.notifyComplete = function () { + this._unsubscribe(); + }; + return ThrottleSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],648:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var async_1 = require('../scheduler/async'); +/** + * Emits a value from the source Observable, then ignores subsequent source + * values for `duration` milliseconds, then repeats this process. + * + * Lets a value pass, then ignores source values for the + * next `duration` milliseconds. + * + * + * + * `throttleTime` emits the source Observable values on the output Observable + * when its internal timer is disabled, and ignores source values when the timer + * is enabled. Initially, the timer is disabled. As soon as the first source + * value arrives, it is forwarded to the output Observable, and then the timer + * is enabled. After `duration` milliseconds (or the time unit determined + * internally by the optional `scheduler`) has passed, the timer is disabled, + * and this process repeats for the next source value. Optionally takes a + * {@link Scheduler} for managing timers. + * + * @example Emit clicks at a rate of at most one click per second + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.throttleTime(1000); + * result.subscribe(x => console.log(x)); + * + * @see {@link auditTime} + * @see {@link debounceTime} + * @see {@link delay} + * @see {@link sampleTime} + * @see {@link throttle} + * + * @param {number} duration Time to wait before emitting another value after + * emitting the last value, measured in milliseconds or the time unit determined + * internally by the optional `scheduler`. + * @param {Scheduler} [scheduler=async] The {@link Scheduler} to use for + * managing the timers that handle the sampling. + * @return {Observable} An Observable that performs the throttle operation to + * limit the rate of emissions from the source. + * @method throttleTime + * @owner Observable + */ +function throttleTime(duration, scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new ThrottleTimeOperator(duration, scheduler)); +} +exports.throttleTime = throttleTime; +var ThrottleTimeOperator = (function () { + function ThrottleTimeOperator(duration, scheduler) { + this.duration = duration; + this.scheduler = scheduler; + } + ThrottleTimeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler)); + }; + return ThrottleTimeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ThrottleTimeSubscriber = (function (_super) { + __extends(ThrottleTimeSubscriber, _super); + function ThrottleTimeSubscriber(destination, duration, scheduler) { + _super.call(this, destination); + this.duration = duration; + this.scheduler = scheduler; + } + ThrottleTimeSubscriber.prototype._next = function (value) { + if (!this.throttled) { + this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, { subscriber: this })); + this.destination.next(value); + } + }; + ThrottleTimeSubscriber.prototype.clearThrottle = function () { + var throttled = this.throttled; + if (throttled) { + throttled.unsubscribe(); + this.remove(throttled); + this.throttled = null; + } + }; + return ThrottleTimeSubscriber; +}(Subscriber_1.Subscriber)); +function dispatchNext(arg) { + var subscriber = arg.subscriber; + subscriber.clearThrottle(); +} + +},{"../Subscriber":386,"../scheduler/async":674}],649:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var async_1 = require('../scheduler/async'); +/** + * @param scheduler + * @return {Observable>|WebSocketSubject|Observable} + * @method timeInterval + * @owner Observable + */ +function timeInterval(scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new TimeIntervalOperator(scheduler)); +} +exports.timeInterval = timeInterval; +var TimeInterval = (function () { + function TimeInterval(value, interval) { + this.value = value; + this.interval = interval; + } + return TimeInterval; +}()); +exports.TimeInterval = TimeInterval; +; +var TimeIntervalOperator = (function () { + function TimeIntervalOperator(scheduler) { + this.scheduler = scheduler; + } + TimeIntervalOperator.prototype.call = function (observer, source) { + return source._subscribe(new TimeIntervalSubscriber(observer, this.scheduler)); + }; + return TimeIntervalOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TimeIntervalSubscriber = (function (_super) { + __extends(TimeIntervalSubscriber, _super); + function TimeIntervalSubscriber(destination, scheduler) { + _super.call(this, destination); + this.scheduler = scheduler; + this.lastTime = 0; + this.lastTime = scheduler.now(); + } + TimeIntervalSubscriber.prototype._next = function (value) { + var now = this.scheduler.now(); + var span = now - this.lastTime; + this.lastTime = now; + this.destination.next(new TimeInterval(value, span)); + }; + return TimeIntervalSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../scheduler/async":674}],650:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var async_1 = require('../scheduler/async'); +var isDate_1 = require('../util/isDate'); +var Subscriber_1 = require('../Subscriber'); +/** + * @param due + * @param errorToSend + * @param scheduler + * @return {Observable|WebSocketSubject|Observable} + * @method timeout + * @owner Observable + */ +function timeout(due, errorToSend, scheduler) { + if (errorToSend === void 0) { errorToSend = null; } + if (scheduler === void 0) { scheduler = async_1.async; } + var absoluteTimeout = isDate_1.isDate(due); + var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due); + return this.lift(new TimeoutOperator(waitFor, absoluteTimeout, errorToSend, scheduler)); +} +exports.timeout = timeout; +var TimeoutOperator = (function () { + function TimeoutOperator(waitFor, absoluteTimeout, errorToSend, scheduler) { + this.waitFor = waitFor; + this.absoluteTimeout = absoluteTimeout; + this.errorToSend = errorToSend; + this.scheduler = scheduler; + } + TimeoutOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new TimeoutSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.errorToSend, this.scheduler)); + }; + return TimeoutOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TimeoutSubscriber = (function (_super) { + __extends(TimeoutSubscriber, _super); + function TimeoutSubscriber(destination, absoluteTimeout, waitFor, errorToSend, scheduler) { + _super.call(this, destination); + this.absoluteTimeout = absoluteTimeout; + this.waitFor = waitFor; + this.errorToSend = errorToSend; + this.scheduler = scheduler; + this.index = 0; + this._previousIndex = 0; + this._hasCompleted = false; + this.scheduleTimeout(); + } + Object.defineProperty(TimeoutSubscriber.prototype, "previousIndex", { + get: function () { + return this._previousIndex; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(TimeoutSubscriber.prototype, "hasCompleted", { + get: function () { + return this._hasCompleted; + }, + enumerable: true, + configurable: true + }); + TimeoutSubscriber.dispatchTimeout = function (state) { + var source = state.subscriber; + var currentIndex = state.index; + if (!source.hasCompleted && source.previousIndex === currentIndex) { + source.notifyTimeout(); + } + }; + TimeoutSubscriber.prototype.scheduleTimeout = function () { + var currentIndex = this.index; + this.scheduler.schedule(TimeoutSubscriber.dispatchTimeout, this.waitFor, { subscriber: this, index: currentIndex }); + this.index++; + this._previousIndex = currentIndex; + }; + TimeoutSubscriber.prototype._next = function (value) { + this.destination.next(value); + if (!this.absoluteTimeout) { + this.scheduleTimeout(); + } + }; + TimeoutSubscriber.prototype._error = function (err) { + this.destination.error(err); + this._hasCompleted = true; + }; + TimeoutSubscriber.prototype._complete = function () { + this.destination.complete(); + this._hasCompleted = true; + }; + TimeoutSubscriber.prototype.notifyTimeout = function () { + this.error(this.errorToSend || new Error('timeout')); + }; + return TimeoutSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../scheduler/async":674,"../util/isDate":696}],651:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var async_1 = require('../scheduler/async'); +var isDate_1 = require('../util/isDate'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * @param due + * @param withObservable + * @param scheduler + * @return {Observable|WebSocketSubject|Observable} + * @method timeoutWith + * @owner Observable + */ +function timeoutWith(due, withObservable, scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + var absoluteTimeout = isDate_1.isDate(due); + var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due); + return this.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler)); +} +exports.timeoutWith = timeoutWith; +var TimeoutWithOperator = (function () { + function TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler) { + this.waitFor = waitFor; + this.absoluteTimeout = absoluteTimeout; + this.withObservable = withObservable; + this.scheduler = scheduler; + } + TimeoutWithOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler)); + }; + return TimeoutWithOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var TimeoutWithSubscriber = (function (_super) { + __extends(TimeoutWithSubscriber, _super); + function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) { + _super.call(this); + this.destination = destination; + this.absoluteTimeout = absoluteTimeout; + this.waitFor = waitFor; + this.withObservable = withObservable; + this.scheduler = scheduler; + this.timeoutSubscription = undefined; + this.index = 0; + this._previousIndex = 0; + this._hasCompleted = false; + destination.add(this); + this.scheduleTimeout(); + } + Object.defineProperty(TimeoutWithSubscriber.prototype, "previousIndex", { + get: function () { + return this._previousIndex; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(TimeoutWithSubscriber.prototype, "hasCompleted", { + get: function () { + return this._hasCompleted; + }, + enumerable: true, + configurable: true + }); + TimeoutWithSubscriber.dispatchTimeout = function (state) { + var source = state.subscriber; + var currentIndex = state.index; + if (!source.hasCompleted && source.previousIndex === currentIndex) { + source.handleTimeout(); + } + }; + TimeoutWithSubscriber.prototype.scheduleTimeout = function () { + var currentIndex = this.index; + var timeoutState = { subscriber: this, index: currentIndex }; + this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, timeoutState); + this.index++; + this._previousIndex = currentIndex; + }; + TimeoutWithSubscriber.prototype._next = function (value) { + this.destination.next(value); + if (!this.absoluteTimeout) { + this.scheduleTimeout(); + } + }; + TimeoutWithSubscriber.prototype._error = function (err) { + this.destination.error(err); + this._hasCompleted = true; + }; + TimeoutWithSubscriber.prototype._complete = function () { + this.destination.complete(); + this._hasCompleted = true; + }; + TimeoutWithSubscriber.prototype.handleTimeout = function () { + if (!this.isUnsubscribed) { + var withObservable = this.withObservable; + this.unsubscribe(); + this.destination.add(this.timeoutSubscription = subscribeToResult_1.subscribeToResult(this, withObservable)); + } + }; + return TimeoutWithSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../scheduler/async":674,"../util/isDate":696,"../util/subscribeToResult":705}],652:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var async_1 = require('../scheduler/async'); +/** + * @param scheduler + * @return {Observable>|WebSocketSubject|Observable} + * @method timestamp + * @owner Observable + */ +function timestamp(scheduler) { + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new TimestampOperator(scheduler)); +} +exports.timestamp = timestamp; +var Timestamp = (function () { + function Timestamp(value, timestamp) { + this.value = value; + this.timestamp = timestamp; + } + return Timestamp; +}()); +exports.Timestamp = Timestamp; +; +var TimestampOperator = (function () { + function TimestampOperator(scheduler) { + this.scheduler = scheduler; + } + TimestampOperator.prototype.call = function (observer, source) { + return source._subscribe(new TimestampSubscriber(observer, this.scheduler)); + }; + return TimestampOperator; +}()); +var TimestampSubscriber = (function (_super) { + __extends(TimestampSubscriber, _super); + function TimestampSubscriber(destination, scheduler) { + _super.call(this, destination); + this.scheduler = scheduler; + } + TimestampSubscriber.prototype._next = function (value) { + var now = this.scheduler.now(); + this.destination.next(new Timestamp(value, now)); + }; + return TimestampSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386,"../scheduler/async":674}],653:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +/** + * @return {Observable|WebSocketSubject|Observable} + * @method toArray + * @owner Observable + */ +function toArray() { + return this.lift(new ToArrayOperator()); +} +exports.toArray = toArray; +var ToArrayOperator = (function () { + function ToArrayOperator() { + } + ToArrayOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ToArraySubscriber(subscriber)); + }; + return ToArrayOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ToArraySubscriber = (function (_super) { + __extends(ToArraySubscriber, _super); + function ToArraySubscriber(destination) { + _super.call(this, destination); + this.array = []; + } + ToArraySubscriber.prototype._next = function (x) { + this.array.push(x); + }; + ToArraySubscriber.prototype._complete = function () { + this.destination.next(this.array); + this.destination.complete(); + }; + return ToArraySubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subscriber":386}],654:[function(require,module,exports){ +"use strict"; +var root_1 = require('../util/root'); +/** + * @param PromiseCtor + * @return {Promise} + * @method toPromise + * @owner Observable + */ +function toPromise(PromiseCtor) { + var _this = this; + if (!PromiseCtor) { + if (root_1.root.Rx && root_1.root.Rx.config && root_1.root.Rx.config.Promise) { + PromiseCtor = root_1.root.Rx.config.Promise; + } + else if (root_1.root.Promise) { + PromiseCtor = root_1.root.Promise; + } + } + if (!PromiseCtor) { + throw new Error('no Promise impl found'); + } + return new PromiseCtor(function (resolve, reject) { + var value; + _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); }); + }); +} +exports.toPromise = toPromise; + +},{"../util/root":704}],655:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../Subject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Branch out the source Observable values as a nested Observable whenever + * `windowBoundaries` emits. + * + * It's like {@link buffer}, but emits a nested Observable + * instead of an array. + * + * + * + * Returns an Observable that emits windows of items it collects from the source + * Observable. The output Observable emits connected, non-overlapping + * windows. It emits the current window and opens a new one whenever the + * Observable `windowBoundaries` emits an item. Because each window is an + * Observable, the output is a higher-order Observable. + * + * @example In every window of 1 second each, emit at most 2 click events + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var interval = Rx.Observable.interval(1000); + * var result = clicks.window(interval) + * .map(win => win.take(2)) // each window has at most 2 emissions + * .mergeAll(); // flatten the Observable-of-Observables + * result.subscribe(x => console.log(x)); + * + * @see {@link windowCount} + * @see {@link windowTime} + * @see {@link windowToggle} + * @see {@link windowWhen} + * @see {@link buffer} + * + * @param {Observable} windowBoundaries An Observable that completes the + * previous window and starts a new window. + * @return {Observable>} An Observable of windows, which are + * Observables emitting values of the source Observable. + * @method window + * @owner Observable + */ +function window(windowBoundaries) { + return this.lift(new WindowOperator(windowBoundaries)); +} +exports.window = window; +var WindowOperator = (function () { + function WindowOperator(windowBoundaries) { + this.windowBoundaries = windowBoundaries; + } + WindowOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new WindowSubscriber(subscriber, this.windowBoundaries)); + }; + return WindowOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var WindowSubscriber = (function (_super) { + __extends(WindowSubscriber, _super); + function WindowSubscriber(destination, windowBoundaries) { + _super.call(this, destination); + this.destination = destination; + this.windowBoundaries = windowBoundaries; + this.add(subscribeToResult_1.subscribeToResult(this, windowBoundaries)); + this.openWindow(); + } + WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.openWindow(); + }; + WindowSubscriber.prototype.notifyError = function (error, innerSub) { + this._error(error); + }; + WindowSubscriber.prototype.notifyComplete = function (innerSub) { + this._complete(); + }; + WindowSubscriber.prototype._next = function (value) { + this.window.next(value); + }; + WindowSubscriber.prototype._error = function (err) { + this.window.error(err); + this.destination.error(err); + }; + WindowSubscriber.prototype._complete = function () { + this.window.complete(); + this.destination.complete(); + }; + WindowSubscriber.prototype.openWindow = function () { + var prevWindow = this.window; + if (prevWindow) { + prevWindow.complete(); + } + var destination = this.destination; + var newWindow = this.window = new Subject_1.Subject(); + destination.add(newWindow); + destination.next(newWindow); + }; + return WindowSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subject":384,"../util/subscribeToResult":705}],656:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Subject_1 = require('../Subject'); +/** + * Branch out the source Observable values as a nested Observable with each + * nested Observable emitting at most `windowSize` values. + * + * It's like {@link bufferCount}, but emits a nested + * Observable instead of an array. + * + * + * + * Returns an Observable that emits windows of items it collects from the source + * Observable. The output Observable emits windows every `startWindowEvery` + * items, each containing no more than `windowSize` items. When the source + * Observable completes or encounters an error, the output Observable emits + * the current window and propagates the notification from the source + * Observable. If `startWindowEvery` is not provided, then new windows are + * started immediately at the start of the source and when each window completes + * with size `windowSize`. + * + * @example Ignore every 3rd click event, starting from the first one + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.windowCount(3) + * .map(win => win.skip(1)) // skip first of every 3 clicks + * .mergeAll(); // flatten the Observable-of-Observables + * result.subscribe(x => console.log(x)); + * + * @example Ignore every 3rd click event, starting from the third one + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.windowCount(2, 3) + * .mergeAll(); // flatten the Observable-of-Observables + * result.subscribe(x => console.log(x)); + * + * @see {@link window} + * @see {@link windowTime} + * @see {@link windowToggle} + * @see {@link windowWhen} + * @see {@link bufferCount} + * + * @param {number} windowSize The maximum number of values emitted by each + * window. + * @param {number} [startWindowEvery] Interval at which to start a new window. + * For example if `startWindowEvery` is `2`, then a new window will be started + * on every other value from the source. A new window is started at the + * beginning of the source by default. + * @return {Observable>} An Observable of windows, which in turn + * are Observable of values. + * @method windowCount + * @owner Observable + */ +function windowCount(windowSize, startWindowEvery) { + if (startWindowEvery === void 0) { startWindowEvery = 0; } + return this.lift(new WindowCountOperator(windowSize, startWindowEvery)); +} +exports.windowCount = windowCount; +var WindowCountOperator = (function () { + function WindowCountOperator(windowSize, startWindowEvery) { + this.windowSize = windowSize; + this.startWindowEvery = startWindowEvery; + } + WindowCountOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery)); + }; + return WindowCountOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var WindowCountSubscriber = (function (_super) { + __extends(WindowCountSubscriber, _super); + function WindowCountSubscriber(destination, windowSize, startWindowEvery) { + _super.call(this, destination); + this.destination = destination; + this.windowSize = windowSize; + this.startWindowEvery = startWindowEvery; + this.windows = [new Subject_1.Subject()]; + this.count = 0; + var firstWindow = this.windows[0]; + destination.add(firstWindow); + destination.next(firstWindow); + } + WindowCountSubscriber.prototype._next = function (value) { + var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize; + var destination = this.destination; + var windowSize = this.windowSize; + var windows = this.windows; + var len = windows.length; + for (var i = 0; i < len; i++) { + windows[i].next(value); + } + var c = this.count - windowSize + 1; + if (c >= 0 && c % startWindowEvery === 0) { + windows.shift().complete(); + } + if (++this.count % startWindowEvery === 0) { + var window_1 = new Subject_1.Subject(); + windows.push(window_1); + destination.add(window_1); + destination.next(window_1); + } + }; + WindowCountSubscriber.prototype._error = function (err) { + var windows = this.windows; + while (windows.length > 0) { + windows.shift().error(err); + } + this.destination.error(err); + }; + WindowCountSubscriber.prototype._complete = function () { + var windows = this.windows; + while (windows.length > 0) { + windows.shift().complete(); + } + this.destination.complete(); + }; + return WindowCountSubscriber; +}(Subscriber_1.Subscriber)); + +},{"../Subject":384,"../Subscriber":386}],657:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscriber_1 = require('../Subscriber'); +var Subject_1 = require('../Subject'); +var async_1 = require('../scheduler/async'); +/** + * Branch out the source Observable values as a nested Observable periodically + * in time. + * + * It's like {@link bufferTime}, but emits a nested + * Observable instead of an array. + * + * + * + * Returns an Observable that emits windows of items it collects from the source + * Observable. The output Observable starts a new window periodically, as + * determined by the `windowCreationInterval` argument. It emits each window + * after a fixed timespan, specified by the `windowTimeSpan` argument. When the + * source Observable completes or encounters an error, the output Observable + * emits the current window and propagates the notification from the source + * Observable. If `windowCreationInterval` is not provided, the output + * Observable starts a new window when the previous window of duration + * `windowTimeSpan` completes. + * + * @example In every window of 1 second each, emit at most 2 click events + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.windowTime(1000) + * .map(win => win.take(2)) // each window has at most 2 emissions + * .mergeAll(); // flatten the Observable-of-Observables + * result.subscribe(x => console.log(x)); + * + * @example Every 5 seconds start a window 1 second long, and emit at most 2 click events per window + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks.windowTime(1000, 5000) + * .map(win => win.take(2)) // each window has at most 2 emissions + * .mergeAll(); // flatten the Observable-of-Observables + * result.subscribe(x => console.log(x)); + * + * @see {@link window} + * @see {@link windowCount} + * @see {@link windowToggle} + * @see {@link windowWhen} + * @see {@link bufferTime} + * + * @param {number} windowTimeSpan The amount of time to fill each window. + * @param {number} [windowCreationInterval] The interval at which to start new + * windows. + * @param {Scheduler} [scheduler=async] The scheduler on which to schedule the + * intervals that determine window boundaries. + * @return {Observable>} An observable of windows, which in turn + * are Observables. + * @method windowTime + * @owner Observable + */ +function windowTime(windowTimeSpan, windowCreationInterval, scheduler) { + if (windowCreationInterval === void 0) { windowCreationInterval = null; } + if (scheduler === void 0) { scheduler = async_1.async; } + return this.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, scheduler)); +} +exports.windowTime = windowTime; +var WindowTimeOperator = (function () { + function WindowTimeOperator(windowTimeSpan, windowCreationInterval, scheduler) { + this.windowTimeSpan = windowTimeSpan; + this.windowCreationInterval = windowCreationInterval; + this.scheduler = scheduler; + } + WindowTimeOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new WindowTimeSubscriber(subscriber, this.windowTimeSpan, this.windowCreationInterval, this.scheduler)); + }; + return WindowTimeOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var WindowTimeSubscriber = (function (_super) { + __extends(WindowTimeSubscriber, _super); + function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, scheduler) { + _super.call(this, destination); + this.destination = destination; + this.windowTimeSpan = windowTimeSpan; + this.windowCreationInterval = windowCreationInterval; + this.scheduler = scheduler; + this.windows = []; + if (windowCreationInterval !== null && windowCreationInterval >= 0) { + var window_1 = this.openWindow(); + var closeState = { subscriber: this, window: window_1, context: null }; + var creationState = { windowTimeSpan: windowTimeSpan, windowCreationInterval: windowCreationInterval, subscriber: this, scheduler: scheduler }; + this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState)); + this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState)); + } + else { + var window_2 = this.openWindow(); + var timeSpanOnlyState = { subscriber: this, window: window_2, windowTimeSpan: windowTimeSpan }; + this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState)); + } + } + WindowTimeSubscriber.prototype._next = function (value) { + var windows = this.windows; + var len = windows.length; + for (var i = 0; i < len; i++) { + var window_3 = windows[i]; + if (!window_3.isUnsubscribed) { + window_3.next(value); + } + } + }; + WindowTimeSubscriber.prototype._error = function (err) { + var windows = this.windows; + while (windows.length > 0) { + windows.shift().error(err); + } + this.destination.error(err); + }; + WindowTimeSubscriber.prototype._complete = function () { + var windows = this.windows; + while (windows.length > 0) { + var window_4 = windows.shift(); + if (!window_4.isUnsubscribed) { + window_4.complete(); + } + } + this.destination.complete(); + }; + WindowTimeSubscriber.prototype.openWindow = function () { + var window = new Subject_1.Subject(); + this.windows.push(window); + var destination = this.destination; + destination.add(window); + destination.next(window); + return window; + }; + WindowTimeSubscriber.prototype.closeWindow = function (window) { + window.complete(); + var windows = this.windows; + windows.splice(windows.indexOf(window), 1); + }; + return WindowTimeSubscriber; +}(Subscriber_1.Subscriber)); +function dispatchWindowTimeSpanOnly(state) { + var subscriber = state.subscriber, windowTimeSpan = state.windowTimeSpan, window = state.window; + if (window) { + window.complete(); + } + state.window = subscriber.openWindow(); + this.schedule(state, windowTimeSpan); +} +function dispatchWindowCreation(state) { + var windowTimeSpan = state.windowTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler, windowCreationInterval = state.windowCreationInterval; + var window = subscriber.openWindow(); + var action = this; + var context = { action: action, subscription: null }; + var timeSpanState = { subscriber: subscriber, window: window, context: context }; + context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState); + action.add(context.subscription); + action.schedule(state, windowCreationInterval); +} +function dispatchWindowClose(arg) { + var subscriber = arg.subscriber, window = arg.window, context = arg.context; + if (context && context.action && context.subscription) { + context.action.remove(context.subscription); + } + subscriber.closeWindow(window); +} + +},{"../Subject":384,"../Subscriber":386,"../scheduler/async":674}],658:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../Subject'); +var Subscription_1 = require('../Subscription'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Branch out the source Observable values as a nested Observable starting from + * an emission from `openings` and ending when the output of `closingSelector` + * emits. + * + * It's like {@link bufferToggle}, but emits a nested + * Observable instead of an array. + * + * + * + * Returns an Observable that emits windows of items it collects from the source + * Observable. The output Observable emits windows that contain those items + * emitted by the source Observable between the time when the `openings` + * Observable emits an item and when the Observable returned by + * `closingSelector` emits an item. + * + * @example Every other second, emit the click events from the next 500ms + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var openings = Rx.Observable.interval(1000); + * var result = clicks.windowToggle(openings, i => + * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty() + * ).mergeAll(); + * result.subscribe(x => console.log(x)); + * + * @see {@link window} + * @see {@link windowCount} + * @see {@link windowTime} + * @see {@link windowWhen} + * @see {@link bufferToggle} + * + * @param {Observable} openings An observable of notifications to start new + * windows. + * @param {function(value: O): Observable} closingSelector A function that takes + * the value emitted by the `openings` observable and returns an Observable, + * which, when it emits (either `next` or `complete`), signals that the + * associated window should complete. + * @return {Observable>} An observable of windows, which in turn + * are Observables. + * @method windowToggle + * @owner Observable + */ +function windowToggle(openings, closingSelector) { + return this.lift(new WindowToggleOperator(openings, closingSelector)); +} +exports.windowToggle = windowToggle; +var WindowToggleOperator = (function () { + function WindowToggleOperator(openings, closingSelector) { + this.openings = openings; + this.closingSelector = closingSelector; + } + WindowToggleOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector)); + }; + return WindowToggleOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var WindowToggleSubscriber = (function (_super) { + __extends(WindowToggleSubscriber, _super); + function WindowToggleSubscriber(destination, openings, closingSelector) { + _super.call(this, destination); + this.openings = openings; + this.closingSelector = closingSelector; + this.contexts = []; + this.add(this.openSubscription = subscribeToResult_1.subscribeToResult(this, openings, openings)); + } + WindowToggleSubscriber.prototype._next = function (value) { + var contexts = this.contexts; + if (contexts) { + var len = contexts.length; + for (var i = 0; i < len; i++) { + contexts[i].window.next(value); + } + } + }; + WindowToggleSubscriber.prototype._error = function (err) { + var contexts = this.contexts; + this.contexts = null; + if (contexts) { + var len = contexts.length; + var index = -1; + while (++index < len) { + var context = contexts[index]; + context.window.error(err); + context.subscription.unsubscribe(); + } + } + _super.prototype._error.call(this, err); + }; + WindowToggleSubscriber.prototype._complete = function () { + var contexts = this.contexts; + this.contexts = null; + if (contexts) { + var len = contexts.length; + var index = -1; + while (++index < len) { + var context = contexts[index]; + context.window.complete(); + context.subscription.unsubscribe(); + } + } + _super.prototype._complete.call(this); + }; + WindowToggleSubscriber.prototype._unsubscribe = function () { + var contexts = this.contexts; + this.contexts = null; + if (contexts) { + var len = contexts.length; + var index = -1; + while (++index < len) { + var context = contexts[index]; + context.window.unsubscribe(); + context.subscription.unsubscribe(); + } + } + }; + WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + if (outerValue === this.openings) { + var closingSelector = this.closingSelector; + var closingNotifier = tryCatch_1.tryCatch(closingSelector)(innerValue); + if (closingNotifier === errorObject_1.errorObject) { + return this.error(errorObject_1.errorObject.e); + } + else { + var window_1 = new Subject_1.Subject(); + var subscription = new Subscription_1.Subscription(); + var context = { window: window_1, subscription: subscription }; + this.contexts.push(context); + var innerSubscription = subscribeToResult_1.subscribeToResult(this, closingNotifier, context); + if (innerSubscription.isUnsubscribed) { + this.closeWindow(this.contexts.length - 1); + } + else { + innerSubscription.context = context; + subscription.add(innerSubscription); + } + this.destination.next(window_1); + } + } + else { + this.closeWindow(this.contexts.indexOf(outerValue)); + } + }; + WindowToggleSubscriber.prototype.notifyError = function (err) { + this.error(err); + }; + WindowToggleSubscriber.prototype.notifyComplete = function (inner) { + if (inner !== this.openSubscription) { + this.closeWindow(this.contexts.indexOf(inner.context)); + } + }; + WindowToggleSubscriber.prototype.closeWindow = function (index) { + if (index === -1) { + return; + } + var contexts = this.contexts; + var context = contexts[index]; + var window = context.window, subscription = context.subscription; + contexts.splice(index, 1); + window.complete(); + subscription.unsubscribe(); + }; + return WindowToggleSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subject":384,"../Subscription":387,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],659:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../Subject'); +var tryCatch_1 = require('../util/tryCatch'); +var errorObject_1 = require('../util/errorObject'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Branch out the source Observable values as a nested Observable using a + * factory function of closing Observables to determine when to start a new + * window. + * + * It's like {@link bufferWhen}, but emits a nested + * Observable instead of an array. + * + * + * + * Returns an Observable that emits windows of items it collects from the source + * Observable. The output Observable emits connected, non-overlapping windows. + * It emits the current window and opens a new one whenever the Observable + * produced by the specified `closingSelector` function emits an item. The first + * window is opened immediately when subscribing to the output Observable. + * + * @example Emit only the first two clicks events in every window of [1-5] random seconds + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var result = clicks + * .windowWhen(() => Rx.Observable.interval(1000 + Math.random() * 4000)) + * .map(win => win.take(2)) // each window has at most 2 emissions + * .mergeAll(); // flatten the Observable-of-Observables + * result.subscribe(x => console.log(x)); + * + * @see {@link window} + * @see {@link windowCount} + * @see {@link windowTime} + * @see {@link windowToggle} + * @see {@link bufferWhen} + * + * @param {function(): Observable} closingSelector A function that takes no + * arguments and returns an Observable that signals (on either `next` or + * `complete`) when to close the previous window and start a new one. + * @return {Observable>} An observable of windows, which in turn + * are Observables. + * @method windowWhen + * @owner Observable + */ +function windowWhen(closingSelector) { + return this.lift(new WindowOperator(closingSelector)); +} +exports.windowWhen = windowWhen; +var WindowOperator = (function () { + function WindowOperator(closingSelector) { + this.closingSelector = closingSelector; + } + WindowOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new WindowSubscriber(subscriber, this.closingSelector)); + }; + return WindowOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var WindowSubscriber = (function (_super) { + __extends(WindowSubscriber, _super); + function WindowSubscriber(destination, closingSelector) { + _super.call(this, destination); + this.destination = destination; + this.closingSelector = closingSelector; + this.openWindow(); + } + WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.openWindow(innerSub); + }; + WindowSubscriber.prototype.notifyError = function (error, innerSub) { + this._error(error); + }; + WindowSubscriber.prototype.notifyComplete = function (innerSub) { + this.openWindow(innerSub); + }; + WindowSubscriber.prototype._next = function (value) { + this.window.next(value); + }; + WindowSubscriber.prototype._error = function (err) { + this.window.error(err); + this.destination.error(err); + this.unsubscribeClosingNotification(); + }; + WindowSubscriber.prototype._complete = function () { + this.window.complete(); + this.destination.complete(); + this.unsubscribeClosingNotification(); + }; + WindowSubscriber.prototype.unsubscribeClosingNotification = function () { + if (this.closingNotification) { + this.closingNotification.unsubscribe(); + } + }; + WindowSubscriber.prototype.openWindow = function (innerSub) { + if (innerSub === void 0) { innerSub = null; } + if (innerSub) { + this.remove(innerSub); + innerSub.unsubscribe(); + } + var prevWindow = this.window; + if (prevWindow) { + prevWindow.complete(); + } + var window = this.window = new Subject_1.Subject(); + this.destination.next(window); + var closingNotifier = tryCatch_1.tryCatch(this.closingSelector)(); + if (closingNotifier === errorObject_1.errorObject) { + var err = errorObject_1.errorObject.e; + this.destination.error(err); + this.window.error(err); + } + else { + this.add(this.closingNotification = subscribeToResult_1.subscribeToResult(this, closingNotifier)); + this.add(window); + } + }; + return WindowSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subject":384,"../util/errorObject":694,"../util/subscribeToResult":705,"../util/tryCatch":708}],660:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +/** + * Combines the source Observable with other Observables to create an Observable + * whose values are calculated from the latest values of each, only when the + * source emits. + * + * Whenever the source Observable emits a value, it + * computes a formula using that value plus the latest values from other input + * Observables, then emits the output of that formula. + * + * + * + * `withLatestFrom` combines each value from the source Observable (the + * instance) with the latest values from the other input Observables only when + * the source emits a value, optionally using a `project` function to determine + * the value to be emitted on the output Observable. All input Observables must + * emit at least one value before the output Observable will emit a value. + * + * @example On every click event, emit an array with the latest timer event plus the click event + * var clicks = Rx.Observable.fromEvent(document, 'click'); + * var timer = Rx.Observable.interval(1000); + * var result = clicks.withLatestFrom(timer); + * result.subscribe(x => console.log(x)); + * + * @see {@link combineLatest} + * + * @param {Observable} other An input Observable to combine with the source + * Observable. More than one input Observables may be given as argument. + * @param {Function} [project] Projection function for combining values + * together. Receives all values in order of the Observables passed, where the + * first parameter is a value from the source Observable. (e.g. + * `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not + * passed, arrays will be emitted on the output Observable. + * @return {Observable} An Observable of projected values from the most recent + * values from each input Observable, or an array of the most recent values from + * each input Observable. + * @method withLatestFrom + * @owner Observable + */ +function withLatestFrom() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + var project; + if (typeof args[args.length - 1] === 'function') { + project = args.pop(); + } + var observables = args; + return this.lift(new WithLatestFromOperator(observables, project)); +} +exports.withLatestFrom = withLatestFrom; +/* tslint:enable:max-line-length */ +var WithLatestFromOperator = (function () { + function WithLatestFromOperator(observables, project) { + this.observables = observables; + this.project = project; + } + WithLatestFromOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project)); + }; + return WithLatestFromOperator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var WithLatestFromSubscriber = (function (_super) { + __extends(WithLatestFromSubscriber, _super); + function WithLatestFromSubscriber(destination, observables, project) { + _super.call(this, destination); + this.observables = observables; + this.project = project; + this.toRespond = []; + var len = observables.length; + this.values = new Array(len); + for (var i = 0; i < len; i++) { + this.toRespond.push(i); + } + for (var i = 0; i < len; i++) { + var observable = observables[i]; + this.add(subscribeToResult_1.subscribeToResult(this, observable, observable, i)); + } + } + WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.values[outerIndex] = innerValue; + var toRespond = this.toRespond; + if (toRespond.length > 0) { + var found = toRespond.indexOf(outerIndex); + if (found !== -1) { + toRespond.splice(found, 1); + } + } + }; + WithLatestFromSubscriber.prototype.notifyComplete = function () { + // noop + }; + WithLatestFromSubscriber.prototype._next = function (value) { + if (this.toRespond.length === 0) { + var args = [value].concat(this.values); + if (this.project) { + this._tryProject(args); + } + else { + this.destination.next(args); + } + } + }; + WithLatestFromSubscriber.prototype._tryProject = function (args) { + var result; + try { + result = this.project.apply(this, args); + } + catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + }; + return WithLatestFromSubscriber; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../util/subscribeToResult":705}],661:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var ArrayObservable_1 = require('../observable/ArrayObservable'); +var isArray_1 = require('../util/isArray'); +var Subscriber_1 = require('../Subscriber'); +var OuterSubscriber_1 = require('../OuterSubscriber'); +var subscribeToResult_1 = require('../util/subscribeToResult'); +var iterator_1 = require('../symbol/iterator'); +/** + * @param observables + * @return {Observable} + * @method zip + * @owner Observable + */ +function zipProto() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + observables.unshift(this); + return zipStatic.apply(this, observables); +} +exports.zipProto = zipProto; +/* tslint:enable:max-line-length */ +/** + * @param observables + * @return {Observable} + * @static true + * @name zip + * @owner Observable + */ +function zipStatic() { + var observables = []; + for (var _i = 0; _i < arguments.length; _i++) { + observables[_i - 0] = arguments[_i]; + } + var project = observables[observables.length - 1]; + if (typeof project === 'function') { + observables.pop(); + } + return new ArrayObservable_1.ArrayObservable(observables).lift(new ZipOperator(project)); +} +exports.zipStatic = zipStatic; +var ZipOperator = (function () { + function ZipOperator(project) { + this.project = project; + } + ZipOperator.prototype.call = function (subscriber, source) { + return source._subscribe(new ZipSubscriber(subscriber, this.project)); + }; + return ZipOperator; +}()); +exports.ZipOperator = ZipOperator; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ZipSubscriber = (function (_super) { + __extends(ZipSubscriber, _super); + function ZipSubscriber(destination, project, values) { + if (values === void 0) { values = Object.create(null); } + _super.call(this, destination); + this.index = 0; + this.iterators = []; + this.active = 0; + this.project = (typeof project === 'function') ? project : null; + this.values = values; + } + ZipSubscriber.prototype._next = function (value) { + var iterators = this.iterators; + var index = this.index++; + if (isArray_1.isArray(value)) { + iterators.push(new StaticArrayIterator(value)); + } + else if (typeof value[iterator_1.$$iterator] === 'function') { + iterators.push(new StaticIterator(value[iterator_1.$$iterator]())); + } + else { + iterators.push(new ZipBufferIterator(this.destination, this, value, index)); + } + }; + ZipSubscriber.prototype._complete = function () { + var iterators = this.iterators; + var len = iterators.length; + this.active = len; + for (var i = 0; i < len; i++) { + var iterator = iterators[i]; + if (iterator.stillUnsubscribed) { + this.add(iterator.subscribe(iterator, i)); + } + else { + this.active--; // not an observable + } + } + }; + ZipSubscriber.prototype.notifyInactive = function () { + this.active--; + if (this.active === 0) { + this.destination.complete(); + } + }; + ZipSubscriber.prototype.checkIterators = function () { + var iterators = this.iterators; + var len = iterators.length; + var destination = this.destination; + // abort if not all of them have values + for (var i = 0; i < len; i++) { + var iterator = iterators[i]; + if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) { + return; + } + } + var shouldComplete = false; + var args = []; + for (var i = 0; i < len; i++) { + var iterator = iterators[i]; + var result = iterator.next(); + // check to see if it's completed now that you've gotten + // the next value. + if (iterator.hasCompleted()) { + shouldComplete = true; + } + if (result.done) { + destination.complete(); + return; + } + args.push(result.value); + } + if (this.project) { + this._tryProject(args); + } + else { + destination.next(args); + } + if (shouldComplete) { + destination.complete(); + } + }; + ZipSubscriber.prototype._tryProject = function (args) { + var result; + try { + result = this.project.apply(this, args); + } + catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + }; + return ZipSubscriber; +}(Subscriber_1.Subscriber)); +exports.ZipSubscriber = ZipSubscriber; +var StaticIterator = (function () { + function StaticIterator(iterator) { + this.iterator = iterator; + this.nextResult = iterator.next(); + } + StaticIterator.prototype.hasValue = function () { + return true; + }; + StaticIterator.prototype.next = function () { + var result = this.nextResult; + this.nextResult = this.iterator.next(); + return result; + }; + StaticIterator.prototype.hasCompleted = function () { + var nextResult = this.nextResult; + return nextResult && nextResult.done; + }; + return StaticIterator; +}()); +var StaticArrayIterator = (function () { + function StaticArrayIterator(array) { + this.array = array; + this.index = 0; + this.length = 0; + this.length = array.length; + } + StaticArrayIterator.prototype[iterator_1.$$iterator] = function () { + return this; + }; + StaticArrayIterator.prototype.next = function (value) { + var i = this.index++; + var array = this.array; + return i < this.length ? { value: array[i], done: false } : { done: true }; + }; + StaticArrayIterator.prototype.hasValue = function () { + return this.array.length > this.index; + }; + StaticArrayIterator.prototype.hasCompleted = function () { + return this.array.length === this.index; + }; + return StaticArrayIterator; +}()); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ZipBufferIterator = (function (_super) { + __extends(ZipBufferIterator, _super); + function ZipBufferIterator(destination, parent, observable, index) { + _super.call(this, destination); + this.parent = parent; + this.observable = observable; + this.index = index; + this.stillUnsubscribed = true; + this.buffer = []; + this.isComplete = false; + } + ZipBufferIterator.prototype[iterator_1.$$iterator] = function () { + return this; + }; + // NOTE: there is actually a name collision here with Subscriber.next and Iterator.next + // this is legit because `next()` will never be called by a subscription in this case. + ZipBufferIterator.prototype.next = function () { + var buffer = this.buffer; + if (buffer.length === 0 && this.isComplete) { + return { done: true }; + } + else { + return { value: buffer.shift(), done: false }; + } + }; + ZipBufferIterator.prototype.hasValue = function () { + return this.buffer.length > 0; + }; + ZipBufferIterator.prototype.hasCompleted = function () { + return this.buffer.length === 0 && this.isComplete; + }; + ZipBufferIterator.prototype.notifyComplete = function () { + if (this.buffer.length > 0) { + this.isComplete = true; + this.parent.notifyInactive(); + } + else { + this.destination.complete(); + } + }; + ZipBufferIterator.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.buffer.push(innerValue); + this.parent.checkIterators(); + }; + ZipBufferIterator.prototype.subscribe = function (value, index) { + return subscribeToResult_1.subscribeToResult(this, this.observable, this, index); + }; + return ZipBufferIterator; +}(OuterSubscriber_1.OuterSubscriber)); + +},{"../OuterSubscriber":381,"../Subscriber":386,"../observable/ArrayObservable":515,"../symbol/iterator":676,"../util/isArray":695,"../util/subscribeToResult":705}],662:[function(require,module,exports){ +"use strict"; +var zip_1 = require('./zip'); +/** + * @param project + * @return {Observable|WebSocketSubject|Observable} + * @method zipAll + * @owner Observable + */ +function zipAll(project) { + return this.lift(new zip_1.ZipOperator(project)); +} +exports.zipAll = zipAll; + +},{"./zip":661}],663:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var FutureAction_1 = require('./FutureAction'); +var AnimationFrame_1 = require('../util/AnimationFrame'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var AnimationFrameAction = (function (_super) { + __extends(AnimationFrameAction, _super); + function AnimationFrameAction() { + _super.apply(this, arguments); + } + AnimationFrameAction.prototype._schedule = function (state, delay) { + if (delay === void 0) { delay = 0; } + if (delay > 0) { + return _super.prototype._schedule.call(this, state, delay); + } + this.delay = delay; + this.state = state; + var scheduler = this.scheduler; + scheduler.actions.push(this); + if (!scheduler.scheduledId) { + scheduler.scheduledId = AnimationFrame_1.AnimationFrame.requestAnimationFrame(function () { + scheduler.scheduledId = null; + scheduler.flush(); + }); + } + return this; + }; + AnimationFrameAction.prototype._unsubscribe = function () { + var scheduler = this.scheduler; + var scheduledId = scheduler.scheduledId, actions = scheduler.actions; + _super.prototype._unsubscribe.call(this); + if (actions.length === 0) { + scheduler.active = false; + if (scheduledId != null) { + scheduler.scheduledId = null; + AnimationFrame_1.AnimationFrame.cancelAnimationFrame(scheduledId); + } + } + }; + return AnimationFrameAction; +}(FutureAction_1.FutureAction)); +exports.AnimationFrameAction = AnimationFrameAction; + +},{"../util/AnimationFrame":683,"./FutureAction":668}],664:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var QueueScheduler_1 = require('./QueueScheduler'); +var AnimationFrameAction_1 = require('./AnimationFrameAction'); +var AnimationFrameScheduler = (function (_super) { + __extends(AnimationFrameScheduler, _super); + function AnimationFrameScheduler() { + _super.apply(this, arguments); + } + AnimationFrameScheduler.prototype.scheduleNow = function (work, state) { + return new AnimationFrameAction_1.AnimationFrameAction(this, work).schedule(state); + }; + return AnimationFrameScheduler; +}(QueueScheduler_1.QueueScheduler)); +exports.AnimationFrameScheduler = AnimationFrameScheduler; + +},{"./AnimationFrameAction":663,"./QueueScheduler":670}],665:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Immediate_1 = require('../util/Immediate'); +var FutureAction_1 = require('./FutureAction'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var AsapAction = (function (_super) { + __extends(AsapAction, _super); + function AsapAction() { + _super.apply(this, arguments); + } + AsapAction.prototype._schedule = function (state, delay) { + if (delay === void 0) { delay = 0; } + if (delay > 0) { + return _super.prototype._schedule.call(this, state, delay); + } + this.delay = delay; + this.state = state; + var scheduler = this.scheduler; + scheduler.actions.push(this); + if (!scheduler.scheduledId) { + scheduler.scheduledId = Immediate_1.Immediate.setImmediate(function () { + scheduler.scheduledId = null; + scheduler.flush(); + }); + } + return this; + }; + AsapAction.prototype._unsubscribe = function () { + var scheduler = this.scheduler; + var scheduledId = scheduler.scheduledId, actions = scheduler.actions; + _super.prototype._unsubscribe.call(this); + if (actions.length === 0) { + scheduler.active = false; + if (scheduledId != null) { + scheduler.scheduledId = null; + Immediate_1.Immediate.clearImmediate(scheduledId); + } + } + }; + return AsapAction; +}(FutureAction_1.FutureAction)); +exports.AsapAction = AsapAction; + +},{"../util/Immediate":687,"./FutureAction":668}],666:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var AsapAction_1 = require('./AsapAction'); +var QueueScheduler_1 = require('./QueueScheduler'); +var AsapScheduler = (function (_super) { + __extends(AsapScheduler, _super); + function AsapScheduler() { + _super.apply(this, arguments); + } + AsapScheduler.prototype.scheduleNow = function (work, state) { + return new AsapAction_1.AsapAction(this, work).schedule(state); + }; + return AsapScheduler; +}(QueueScheduler_1.QueueScheduler)); +exports.AsapScheduler = AsapScheduler; + +},{"./AsapAction":665,"./QueueScheduler":670}],667:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var FutureAction_1 = require('./FutureAction'); +var QueueScheduler_1 = require('./QueueScheduler'); +var AsyncScheduler = (function (_super) { + __extends(AsyncScheduler, _super); + function AsyncScheduler() { + _super.apply(this, arguments); + } + AsyncScheduler.prototype.scheduleNow = function (work, state) { + return new FutureAction_1.FutureAction(this, work).schedule(state, 0); + }; + return AsyncScheduler; +}(QueueScheduler_1.QueueScheduler)); +exports.AsyncScheduler = AsyncScheduler; + +},{"./FutureAction":668,"./QueueScheduler":670}],668:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var root_1 = require('../util/root'); +var Subscription_1 = require('../Subscription'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var FutureAction = (function (_super) { + __extends(FutureAction, _super); + function FutureAction(scheduler, work) { + _super.call(this); + this.scheduler = scheduler; + this.work = work; + this.pending = false; + } + FutureAction.prototype.execute = function () { + if (this.isUnsubscribed) { + this.error = new Error('executing a cancelled action'); + } + else { + try { + this.work(this.state); + } + catch (e) { + this.unsubscribe(); + this.error = e; + } + } + }; + FutureAction.prototype.schedule = function (state, delay) { + if (delay === void 0) { delay = 0; } + if (this.isUnsubscribed) { + return this; + } + return this._schedule(state, delay); + }; + FutureAction.prototype._schedule = function (state, delay) { + var _this = this; + if (delay === void 0) { delay = 0; } + // Always replace the current state with the new state. + this.state = state; + // Set the pending flag indicating that this action has been scheduled, or + // has recursively rescheduled itself. + this.pending = true; + var id = this.id; + // If this action has an intervalID and the specified delay matches the + // delay we used to create the intervalID, don't call `setInterval` again. + if (id != null && this.delay === delay) { + return this; + } + this.delay = delay; + // If this action has an intervalID, but was rescheduled with a different + // `delay` time, cancel the current intervalID and call `setInterval` with + // the new `delay` time. + if (id != null) { + this.id = null; + root_1.root.clearInterval(id); + } + // + // Important implementation note: + // + // By default, FutureAction only executes once. However, Actions have the + // ability to be rescheduled from within the scheduled callback (mimicking + // recursion for asynchronous methods). This allows us to implement single + // and repeated actions with the same code path without adding API surface + // area, and implement tail-call optimization over asynchronous boundaries. + // + // However, JS runtimes make a distinction between intervals scheduled by + // repeatedly calling `setTimeout` vs. a single `setInterval` call, with + // the latter providing a better guarantee of precision. + // + // In order to accommodate both single and repeatedly rescheduled actions, + // use `setInterval` here for both cases. By default, the interval will be + // canceled after its first execution, or if the action schedules itself to + // run again with a different `delay` time. + // + // If the action recursively schedules itself to run again with the same + // `delay` time, the interval is not canceled, but allowed to loop again. + // The check of whether the interval should be canceled or not is run every + // time the interval is executed. The first time an action fails to + // reschedule itself, the interval is canceled. + // + this.id = root_1.root.setInterval(function () { + _this.pending = false; + var _a = _this, id = _a.id, scheduler = _a.scheduler; + scheduler.actions.push(_this); + scheduler.flush(); + // + // Terminate this interval if the action didn't reschedule itself. + // Don't call `this.unsubscribe()` here, because the action could be + // rescheduled later. For example: + // + // ``` + // scheduler.schedule(function doWork(counter) { + // /* ... I'm a busy worker bee ... */ + // var originalAction = this; + // /* wait 100ms before rescheduling this action again */ + // setTimeout(function () { + // originalAction.schedule(counter + 1); + // }, 100); + // }, 1000); + // ``` + if (_this.pending === false && id != null) { + _this.id = null; + root_1.root.clearInterval(id); + } + }, delay); + return this; + }; + FutureAction.prototype._unsubscribe = function () { + this.pending = false; + var _a = this, id = _a.id, scheduler = _a.scheduler; + var actions = scheduler.actions; + var index = actions.indexOf(this); + if (id != null) { + this.id = null; + root_1.root.clearInterval(id); + } + if (index !== -1) { + actions.splice(index, 1); + } + this.work = null; + this.state = null; + this.scheduler = null; + }; + return FutureAction; +}(Subscription_1.Subscription)); +exports.FutureAction = FutureAction; + +},{"../Subscription":387,"../util/root":704}],669:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var FutureAction_1 = require('./FutureAction'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var QueueAction = (function (_super) { + __extends(QueueAction, _super); + function QueueAction() { + _super.apply(this, arguments); + } + QueueAction.prototype._schedule = function (state, delay) { + if (delay === void 0) { delay = 0; } + if (delay > 0) { + return _super.prototype._schedule.call(this, state, delay); + } + this.delay = delay; + this.state = state; + var scheduler = this.scheduler; + scheduler.actions.push(this); + scheduler.flush(); + return this; + }; + return QueueAction; +}(FutureAction_1.FutureAction)); +exports.QueueAction = QueueAction; + +},{"./FutureAction":668}],670:[function(require,module,exports){ +"use strict"; +var QueueAction_1 = require('./QueueAction'); +var FutureAction_1 = require('./FutureAction'); +var QueueScheduler = (function () { + function QueueScheduler() { + this.active = false; + this.actions = []; // XXX: use `any` to remove type param `T` from `VirtualTimeScheduler`. + this.scheduledId = null; + } + QueueScheduler.prototype.now = function () { + return Date.now(); + }; + QueueScheduler.prototype.flush = function () { + if (this.active || this.scheduledId) { + return; + } + this.active = true; + var actions = this.actions; + // XXX: use `any` to remove type param `T` from `VirtualTimeScheduler`. + for (var action = null; action = actions.shift();) { + action.execute(); + if (action.error) { + this.active = false; + throw action.error; + } + } + this.active = false; + }; + QueueScheduler.prototype.schedule = function (work, delay, state) { + if (delay === void 0) { delay = 0; } + return (delay <= 0) ? + this.scheduleNow(work, state) : + this.scheduleLater(work, delay, state); + }; + QueueScheduler.prototype.scheduleNow = function (work, state) { + return new QueueAction_1.QueueAction(this, work).schedule(state); + }; + QueueScheduler.prototype.scheduleLater = function (work, delay, state) { + return new FutureAction_1.FutureAction(this, work).schedule(state, delay); + }; + return QueueScheduler; +}()); +exports.QueueScheduler = QueueScheduler; + +},{"./FutureAction":668,"./QueueAction":669}],671:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subscription_1 = require('../Subscription'); +var VirtualTimeScheduler = (function () { + function VirtualTimeScheduler() { + this.actions = []; // XXX: use `any` to remove type param `T` from `VirtualTimeScheduler`. + this.active = false; + this.scheduledId = null; + this.index = 0; + this.sorted = false; + this.frame = 0; + this.maxFrames = 750; + } + VirtualTimeScheduler.prototype.now = function () { + return this.frame; + }; + VirtualTimeScheduler.prototype.flush = function () { + var actions = this.actions; + var maxFrames = this.maxFrames; + while (actions.length > 0) { + var action = actions.shift(); + this.frame = action.delay; + if (this.frame <= maxFrames) { + action.execute(); + if (action.error) { + actions.length = 0; + this.frame = 0; + throw action.error; + } + } + else { + break; + } + } + actions.length = 0; + this.frame = 0; + }; + VirtualTimeScheduler.prototype.addAction = function (action) { + var actions = this.actions; + actions.push(action); + actions.sort(function (a, b) { + if (a.delay === b.delay) { + if (a.index === b.index) { + return 0; + } + else if (a.index > b.index) { + return 1; + } + else { + return -1; + } + } + else if (a.delay > b.delay) { + return 1; + } + else { + return -1; + } + }); + }; + VirtualTimeScheduler.prototype.schedule = function (work, delay, state) { + if (delay === void 0) { delay = 0; } + this.sorted = false; + return new VirtualAction(this, work, this.index++).schedule(state, delay); + }; + VirtualTimeScheduler.frameTimeFactor = 10; + return VirtualTimeScheduler; +}()); +exports.VirtualTimeScheduler = VirtualTimeScheduler; +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var VirtualAction = (function (_super) { + __extends(VirtualAction, _super); + function VirtualAction(scheduler, work, index) { + _super.call(this); + this.scheduler = scheduler; + this.work = work; + this.index = index; + this.calls = 0; + } + VirtualAction.prototype.schedule = function (state, delay) { + if (delay === void 0) { delay = 0; } + if (this.isUnsubscribed) { + return this; + } + var scheduler = this.scheduler; + var action = null; + if (this.calls++ === 0) { + // the action is not being rescheduled. + action = this; + } + else { + // the action is being rescheduled, and we can't mutate the one in the actions list + // in the scheduler, so we'll create a new one. + action = new VirtualAction(scheduler, this.work, scheduler.index += 1); + this.add(action); + } + action.state = state; + action.delay = scheduler.frame + delay; + scheduler.addAction(action); + return this; + }; + VirtualAction.prototype.execute = function () { + if (this.isUnsubscribed) { + throw new Error('How did did we execute a canceled Action?'); + } + this.work(this.state); + }; + VirtualAction.prototype.unsubscribe = function () { + var actions = this.scheduler.actions; + var index = actions.indexOf(this); + this.work = void 0; + this.state = void 0; + this.scheduler = void 0; + if (index !== -1) { + actions.splice(index, 1); + } + _super.prototype.unsubscribe.call(this); + }; + return VirtualAction; +}(Subscription_1.Subscription)); + +},{"../Subscription":387}],672:[function(require,module,exports){ +"use strict"; +var AnimationFrameScheduler_1 = require('./AnimationFrameScheduler'); +exports.animationFrame = new AnimationFrameScheduler_1.AnimationFrameScheduler(); + +},{"./AnimationFrameScheduler":664}],673:[function(require,module,exports){ +"use strict"; +var AsapScheduler_1 = require('./AsapScheduler'); +exports.asap = new AsapScheduler_1.AsapScheduler(); + +},{"./AsapScheduler":666}],674:[function(require,module,exports){ +"use strict"; +var AsyncScheduler_1 = require('./AsyncScheduler'); +exports.async = new AsyncScheduler_1.AsyncScheduler(); + +},{"./AsyncScheduler":667}],675:[function(require,module,exports){ +"use strict"; +var QueueScheduler_1 = require('./QueueScheduler'); +exports.queue = new QueueScheduler_1.QueueScheduler(); + +},{"./QueueScheduler":670}],676:[function(require,module,exports){ +"use strict"; +var root_1 = require('../util/root'); +var Symbol = root_1.root.Symbol; +if (typeof Symbol === 'function') { + if (Symbol.iterator) { + exports.$$iterator = Symbol.iterator; + } + else if (typeof Symbol.for === 'function') { + exports.$$iterator = Symbol.for('iterator'); + } +} +else { + if (root_1.root.Set && typeof new root_1.root.Set()['@@iterator'] === 'function') { + // Bug for mozilla version + exports.$$iterator = '@@iterator'; + } + else if (root_1.root.Map) { + // es6-shim specific logic + var keys = Object.getOwnPropertyNames(root_1.root.Map.prototype); + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + if (key !== 'entries' && key !== 'size' && root_1.root.Map.prototype[key] === root_1.root.Map.prototype['entries']) { + exports.$$iterator = key; + break; + } + } + } + else { + exports.$$iterator = '@@iterator'; } +} - try { - isDispatching = true; - currentState = currentReducer(currentState, action); - } finally { - isDispatching = false; +},{"../util/root":704}],677:[function(require,module,exports){ +"use strict"; +var root_1 = require('../util/root'); +var Symbol = root_1.root.Symbol; +exports.$$rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ? + Symbol.for('rxSubscriber') : '@@rxSubscriber'; + +},{"../util/root":704}],678:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var Subscription_1 = require('../Subscription'); +var SubscriptionLoggable_1 = require('./SubscriptionLoggable'); +var applyMixins_1 = require('../util/applyMixins'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var ColdObservable = (function (_super) { + __extends(ColdObservable, _super); + function ColdObservable(messages, scheduler) { + _super.call(this, function (subscriber) { + var observable = this; + var index = observable.logSubscribedFrame(); + subscriber.add(new Subscription_1.Subscription(function () { + observable.logUnsubscribedFrame(index); + })); + observable.scheduleMessages(subscriber); + return subscriber; + }); + this.messages = messages; + this.subscriptions = []; + this.scheduler = scheduler; + } + ColdObservable.prototype.scheduleMessages = function (subscriber) { + var messagesLength = this.messages.length; + for (var i = 0; i < messagesLength; i++) { + var message = this.messages[i]; + subscriber.add(this.scheduler.schedule(function (_a) { + var message = _a.message, subscriber = _a.subscriber; + message.notification.observe(subscriber); + }, message.frame, { message: message, subscriber: subscriber })); + } + }; + return ColdObservable; +}(Observable_1.Observable)); +exports.ColdObservable = ColdObservable; +applyMixins_1.applyMixins(ColdObservable, [SubscriptionLoggable_1.SubscriptionLoggable]); + +},{"../Observable":378,"../Subscription":387,"../util/applyMixins":692,"./SubscriptionLoggable":681}],679:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Subject_1 = require('../Subject'); +var Subscription_1 = require('../Subscription'); +var SubscriptionLoggable_1 = require('./SubscriptionLoggable'); +var applyMixins_1 = require('../util/applyMixins'); +/** + * We need this JSDoc comment for affecting ESDoc. + * @ignore + * @extends {Ignored} + */ +var HotObservable = (function (_super) { + __extends(HotObservable, _super); + function HotObservable(messages, scheduler) { + _super.call(this); + this.messages = messages; + this.subscriptions = []; + this.scheduler = scheduler; + } + HotObservable.prototype._subscribe = function (subscriber) { + var subject = this; + var index = subject.logSubscribedFrame(); + subscriber.add(new Subscription_1.Subscription(function () { + subject.logUnsubscribedFrame(index); + })); + return _super.prototype._subscribe.call(this, subscriber); + }; + HotObservable.prototype.setup = function () { + var subject = this; + var messagesLength = subject.messages.length; + /* tslint:disable:no-var-keyword */ + for (var i = 0; i < messagesLength; i++) { + (function () { + var message = subject.messages[i]; + /* tslint:enable */ + subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame); + })(); + } + }; + return HotObservable; +}(Subject_1.Subject)); +exports.HotObservable = HotObservable; +applyMixins_1.applyMixins(HotObservable, [SubscriptionLoggable_1.SubscriptionLoggable]); + +},{"../Subject":384,"../Subscription":387,"../util/applyMixins":692,"./SubscriptionLoggable":681}],680:[function(require,module,exports){ +"use strict"; +var SubscriptionLog = (function () { + function SubscriptionLog(subscribedFrame, unsubscribedFrame) { + if (unsubscribedFrame === void 0) { unsubscribedFrame = Number.POSITIVE_INFINITY; } + this.subscribedFrame = subscribedFrame; + this.unsubscribedFrame = unsubscribedFrame; } + return SubscriptionLog; +}()); +exports.SubscriptionLog = SubscriptionLog; - var listeners = currentListeners = nextListeners; - for (var i = 0; i < listeners.length; i++) { - listeners[i](); +},{}],681:[function(require,module,exports){ +"use strict"; +var SubscriptionLog_1 = require('./SubscriptionLog'); +var SubscriptionLoggable = (function () { + function SubscriptionLoggable() { + this.subscriptions = []; + } + SubscriptionLoggable.prototype.logSubscribedFrame = function () { + this.subscriptions.push(new SubscriptionLog_1.SubscriptionLog(this.scheduler.now())); + return this.subscriptions.length - 1; + }; + SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) { + var subscriptionLogs = this.subscriptions; + var oldSubscriptionLog = subscriptionLogs[index]; + subscriptionLogs[index] = new SubscriptionLog_1.SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now()); + }; + return SubscriptionLoggable; +}()); +exports.SubscriptionLoggable = SubscriptionLoggable; + +},{"./SubscriptionLog":680}],682:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Observable_1 = require('../Observable'); +var VirtualTimeScheduler_1 = require('../scheduler/VirtualTimeScheduler'); +var Notification_1 = require('../Notification'); +var ColdObservable_1 = require('./ColdObservable'); +var HotObservable_1 = require('./HotObservable'); +var SubscriptionLog_1 = require('./SubscriptionLog'); +var TestScheduler = (function (_super) { + __extends(TestScheduler, _super); + function TestScheduler(assertDeepEqual) { + _super.call(this); + this.assertDeepEqual = assertDeepEqual; + this.hotObservables = []; + this.coldObservables = []; + this.flushTests = []; + } + TestScheduler.prototype.createTime = function (marbles) { + var indexOf = marbles.indexOf('|'); + if (indexOf === -1) { + throw new Error('Marble diagram for time should have a completion marker "|"'); + } + return indexOf * TestScheduler.frameTimeFactor; + }; + TestScheduler.prototype.createColdObservable = function (marbles, values, error) { + if (marbles.indexOf('^') !== -1) { + throw new Error('Cold observable cannot have subscription offset "^"'); + } + if (marbles.indexOf('!') !== -1) { + throw new Error('Cold observable cannot have unsubscription marker "!"'); + } + var messages = TestScheduler.parseMarbles(marbles, values, error); + var cold = new ColdObservable_1.ColdObservable(messages, this); + this.coldObservables.push(cold); + return cold; + }; + TestScheduler.prototype.createHotObservable = function (marbles, values, error) { + if (marbles.indexOf('!') !== -1) { + throw new Error('Hot observable cannot have unsubscription marker "!"'); + } + var messages = TestScheduler.parseMarbles(marbles, values, error); + var subject = new HotObservable_1.HotObservable(messages, this); + this.hotObservables.push(subject); + return subject; + }; + TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) { + var _this = this; + var messages = []; + observable.subscribe(function (value) { + messages.push({ frame: _this.frame - outerFrame, notification: Notification_1.Notification.createNext(value) }); + }, function (err) { + messages.push({ frame: _this.frame - outerFrame, notification: Notification_1.Notification.createError(err) }); + }, function () { + messages.push({ frame: _this.frame - outerFrame, notification: Notification_1.Notification.createComplete() }); + }); + return messages; + }; + TestScheduler.prototype.expectObservable = function (observable, unsubscriptionMarbles) { + var _this = this; + if (unsubscriptionMarbles === void 0) { unsubscriptionMarbles = null; } + var actual = []; + var flushTest = { actual: actual, ready: false }; + var unsubscriptionFrame = TestScheduler + .parseMarblesAsSubscriptions(unsubscriptionMarbles).unsubscribedFrame; + var subscription; + this.schedule(function () { + subscription = observable.subscribe(function (x) { + var value = x; + // Support Observable-of-Observables + if (x instanceof Observable_1.Observable) { + value = _this.materializeInnerObservable(value, _this.frame); + } + actual.push({ frame: _this.frame, notification: Notification_1.Notification.createNext(value) }); + }, function (err) { + actual.push({ frame: _this.frame, notification: Notification_1.Notification.createError(err) }); + }, function () { + actual.push({ frame: _this.frame, notification: Notification_1.Notification.createComplete() }); + }); + }, 0); + if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) { + this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame); + } + this.flushTests.push(flushTest); + return { + toBe: function (marbles, values, errorValue) { + flushTest.ready = true; + flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true); + } + }; + }; + TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) { + var flushTest = { actual: actualSubscriptionLogs, ready: false }; + this.flushTests.push(flushTest); + return { + toBe: function (marbles) { + var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles; + flushTest.ready = true; + flushTest.expected = marblesArray.map(function (marbles) { + return TestScheduler.parseMarblesAsSubscriptions(marbles); + }); + } + }; + }; + TestScheduler.prototype.flush = function () { + var hotObservables = this.hotObservables; + while (hotObservables.length > 0) { + hotObservables.shift().setup(); + } + _super.prototype.flush.call(this); + var readyFlushTests = this.flushTests.filter(function (test) { return test.ready; }); + while (readyFlushTests.length > 0) { + var test = readyFlushTests.shift(); + this.assertDeepEqual(test.actual, test.expected); + } + }; + TestScheduler.parseMarblesAsSubscriptions = function (marbles) { + if (typeof marbles !== 'string') { + return new SubscriptionLog_1.SubscriptionLog(Number.POSITIVE_INFINITY); + } + var len = marbles.length; + var groupStart = -1; + var subscriptionFrame = Number.POSITIVE_INFINITY; + var unsubscriptionFrame = Number.POSITIVE_INFINITY; + for (var i = 0; i < len; i++) { + var frame = i * this.frameTimeFactor; + var c = marbles[i]; + switch (c) { + case '-': + case ' ': + break; + case '(': + groupStart = frame; + break; + case ')': + groupStart = -1; + break; + case '^': + if (subscriptionFrame !== Number.POSITIVE_INFINITY) { + throw new Error('Found a second subscription point \'^\' in a ' + + 'subscription marble diagram. There can only be one.'); + } + subscriptionFrame = groupStart > -1 ? groupStart : frame; + break; + case '!': + if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) { + throw new Error('Found a second subscription point \'^\' in a ' + + 'subscription marble diagram. There can only be one.'); + } + unsubscriptionFrame = groupStart > -1 ? groupStart : frame; + break; + default: + throw new Error('There can only be \'^\' and \'!\' markers in a ' + + 'subscription marble diagram. Found instead \'' + c + '\'.'); + } + } + if (unsubscriptionFrame < 0) { + return new SubscriptionLog_1.SubscriptionLog(subscriptionFrame); + } + else { + return new SubscriptionLog_1.SubscriptionLog(subscriptionFrame, unsubscriptionFrame); + } + }; + TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables) { + if (materializeInnerObservables === void 0) { materializeInnerObservables = false; } + if (marbles.indexOf('!') !== -1) { + throw new Error('Conventional marble diagrams cannot have the ' + + 'unsubscription marker "!"'); + } + var len = marbles.length; + var testMessages = []; + var subIndex = marbles.indexOf('^'); + var frameOffset = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor); + var getValue = typeof values !== 'object' ? + function (x) { return x; } : + function (x) { + // Support Observable-of-Observables + if (materializeInnerObservables && values[x] instanceof ColdObservable_1.ColdObservable) { + return values[x].messages; + } + return values[x]; + }; + var groupStart = -1; + for (var i = 0; i < len; i++) { + var frame = i * this.frameTimeFactor + frameOffset; + var notification = void 0; + var c = marbles[i]; + switch (c) { + case '-': + case ' ': + break; + case '(': + groupStart = frame; + break; + case ')': + groupStart = -1; + break; + case '|': + notification = Notification_1.Notification.createComplete(); + break; + case '^': + break; + case '#': + notification = Notification_1.Notification.createError(errorValue || 'error'); + break; + default: + notification = Notification_1.Notification.createNext(getValue(c)); + break; + } + if (notification) { + testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification }); + } + } + return testMessages; + }; + return TestScheduler; +}(VirtualTimeScheduler_1.VirtualTimeScheduler)); +exports.TestScheduler = TestScheduler; + +},{"../Notification":377,"../Observable":378,"../scheduler/VirtualTimeScheduler":671,"./ColdObservable":678,"./HotObservable":679,"./SubscriptionLog":680}],683:[function(require,module,exports){ +"use strict"; +var root_1 = require('./root'); +var RequestAnimationFrameDefinition = (function () { + function RequestAnimationFrameDefinition(root) { + if (root.requestAnimationFrame) { + this.cancelAnimationFrame = root.cancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.requestAnimationFrame.bind(root); + } + else if (root.mozRequestAnimationFrame) { + this.cancelAnimationFrame = root.mozCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.mozRequestAnimationFrame.bind(root); + } + else if (root.webkitRequestAnimationFrame) { + this.cancelAnimationFrame = root.webkitCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.webkitRequestAnimationFrame.bind(root); + } + else if (root.msRequestAnimationFrame) { + this.cancelAnimationFrame = root.msCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.msRequestAnimationFrame.bind(root); + } + else if (root.oRequestAnimationFrame) { + this.cancelAnimationFrame = root.oCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.oRequestAnimationFrame.bind(root); + } + else { + this.cancelAnimationFrame = root.clearTimeout.bind(root); + this.requestAnimationFrame = function (cb) { return root.setTimeout(cb, 1000 / 60); }; + } } + return RequestAnimationFrameDefinition; +}()); +exports.RequestAnimationFrameDefinition = RequestAnimationFrameDefinition; +exports.AnimationFrame = new RequestAnimationFrameDefinition(root_1.root); - return action; - } +},{"./root":704}],684:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +/** + * An error thrown when an element was queried at a certain index of an + * Observable, but no such index or position exists in that sequence. + * + * @see {@link elementAt} + * @see {@link take} + * @see {@link takeLast} + * + * @class ArgumentOutOfRangeError + */ +var ArgumentOutOfRangeError = (function (_super) { + __extends(ArgumentOutOfRangeError, _super); + function ArgumentOutOfRangeError() { + _super.call(this, 'argument out of range'); + this.name = 'ArgumentOutOfRangeError'; + } + return ArgumentOutOfRangeError; +}(Error)); +exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError; - /** - * Replaces the reducer currently used by the store to calculate the state. - * - * You might need this if your app implements code splitting and you want to - * load some of the reducers dynamically. You might also need this if you - * implement a hot reloading mechanism for Redux. - * - * @param {Function} nextReducer The reducer for the store to use instead. - * @returns {void} - */ - function replaceReducer(nextReducer) { - if (typeof nextReducer !== 'function') { - throw new Error('Expected the nextReducer to be a function.'); +},{}],685:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +/** + * An error thrown when an Observable or a sequence was queried but has no + * elements. + * + * @see {@link first} + * @see {@link last} + * @see {@link single} + * + * @class EmptyError + */ +var EmptyError = (function (_super) { + __extends(EmptyError, _super); + function EmptyError() { + _super.call(this, 'no elements in sequence'); + this.name = 'EmptyError'; } + return EmptyError; +}(Error)); +exports.EmptyError = EmptyError; - currentReducer = nextReducer; - dispatch({ type: ActionTypes.INIT }); - } +},{}],686:[function(require,module,exports){ +"use strict"; +var FastMap = (function () { + function FastMap() { + this.values = {}; + } + FastMap.prototype.delete = function (key) { + this.values[key] = null; + return true; + }; + FastMap.prototype.set = function (key, value) { + this.values[key] = value; + return this; + }; + FastMap.prototype.get = function (key) { + return this.values[key]; + }; + FastMap.prototype.forEach = function (cb, thisArg) { + var values = this.values; + for (var key in values) { + if (values.hasOwnProperty(key) && values[key] !== null) { + cb.call(thisArg, values[key], key); + } + } + }; + FastMap.prototype.clear = function () { + this.values = {}; + }; + return FastMap; +}()); +exports.FastMap = FastMap; - /** - * Interoperability point for observable/reactive libraries. - * @returns {observable} A minimal observable of state changes. - * For more information, see the observable proposal: - * https://github.com/zenparsing/es-observable - */ - function observable() { - var _ref; +},{}],687:[function(require,module,exports){ +/** +Some credit for this helper goes to http://github.com/YuzuJS/setImmediate +*/ +"use strict"; +var root_1 = require('./root'); +var ImmediateDefinition = (function () { + function ImmediateDefinition(root) { + this.root = root; + if (root.setImmediate && typeof root.setImmediate === 'function') { + this.setImmediate = root.setImmediate.bind(root); + this.clearImmediate = root.clearImmediate.bind(root); + } + else { + this.nextHandle = 1; + this.tasksByHandle = {}; + this.currentlyRunningATask = false; + // Don't get fooled by e.g. browserify environments. + if (this.canUseProcessNextTick()) { + // For Node.js before 0.9 + this.setImmediate = this.createProcessNextTickSetImmediate(); + } + else if (this.canUsePostMessage()) { + // For non-IE10 modern browsers + this.setImmediate = this.createPostMessageSetImmediate(); + } + else if (this.canUseMessageChannel()) { + // For web workers, where supported + this.setImmediate = this.createMessageChannelSetImmediate(); + } + else if (this.canUseReadyStateChange()) { + // For IE 6–8 + this.setImmediate = this.createReadyStateChangeSetImmediate(); + } + else { + // For older browsers + this.setImmediate = this.createSetTimeoutSetImmediate(); + } + var ci = function clearImmediate(handle) { + delete clearImmediate.instance.tasksByHandle[handle]; + }; + ci.instance = this; + this.clearImmediate = ci; + } + } + ImmediateDefinition.prototype.identify = function (o) { + return this.root.Object.prototype.toString.call(o); + }; + ImmediateDefinition.prototype.canUseProcessNextTick = function () { + return this.identify(this.root.process) === '[object process]'; + }; + ImmediateDefinition.prototype.canUseMessageChannel = function () { + return Boolean(this.root.MessageChannel); + }; + ImmediateDefinition.prototype.canUseReadyStateChange = function () { + var document = this.root.document; + return Boolean(document && 'onreadystatechange' in document.createElement('script')); + }; + ImmediateDefinition.prototype.canUsePostMessage = function () { + var root = this.root; + // The test against `importScripts` prevents this implementation from being installed inside a web worker, + // where `root.postMessage` means something completely different and can't be used for this purpose. + if (root.postMessage && !root.importScripts) { + var postMessageIsAsynchronous_1 = true; + var oldOnMessage = root.onmessage; + root.onmessage = function () { + postMessageIsAsynchronous_1 = false; + }; + root.postMessage('', '*'); + root.onmessage = oldOnMessage; + return postMessageIsAsynchronous_1; + } + return false; + }; + // This function accepts the same arguments as setImmediate, but + // returns a function that requires no arguments. + ImmediateDefinition.prototype.partiallyApplied = function (handler) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var fn = function result() { + var _a = result, handler = _a.handler, args = _a.args; + if (typeof handler === 'function') { + handler.apply(undefined, args); + } + else { + (new Function('' + handler))(); + } + }; + fn.handler = handler; + fn.args = args; + return fn; + }; + ImmediateDefinition.prototype.addFromSetImmediateArguments = function (args) { + this.tasksByHandle[this.nextHandle] = this.partiallyApplied.apply(undefined, args); + return this.nextHandle++; + }; + ImmediateDefinition.prototype.createProcessNextTickSetImmediate = function () { + var fn = function setImmediate() { + var instance = setImmediate.instance; + var handle = instance.addFromSetImmediateArguments(arguments); + instance.root.process.nextTick(instance.partiallyApplied(instance.runIfPresent, handle)); + return handle; + }; + fn.instance = this; + return fn; + }; + ImmediateDefinition.prototype.createPostMessageSetImmediate = function () { + // Installs an event handler on `global` for the `message` event: see + // * https://developer.mozilla.org/en/DOM/window.postMessage + // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages + var root = this.root; + var messagePrefix = 'setImmediate$' + root.Math.random() + '$'; + var onGlobalMessage = function globalMessageHandler(event) { + var instance = globalMessageHandler.instance; + if (event.source === root && + typeof event.data === 'string' && + event.data.indexOf(messagePrefix) === 0) { + instance.runIfPresent(+event.data.slice(messagePrefix.length)); + } + }; + onGlobalMessage.instance = this; + root.addEventListener('message', onGlobalMessage, false); + var fn = function setImmediate() { + var _a = setImmediate, messagePrefix = _a.messagePrefix, instance = _a.instance; + var handle = instance.addFromSetImmediateArguments(arguments); + instance.root.postMessage(messagePrefix + handle, '*'); + return handle; + }; + fn.instance = this; + fn.messagePrefix = messagePrefix; + return fn; + }; + ImmediateDefinition.prototype.runIfPresent = function (handle) { + // From the spec: 'Wait until any invocations of this algorithm started before this one have completed.' + // So if we're currently running a task, we'll need to delay this invocation. + if (this.currentlyRunningATask) { + // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a + // 'too much recursion' error. + this.root.setTimeout(this.partiallyApplied(this.runIfPresent, handle), 0); + } + else { + var task = this.tasksByHandle[handle]; + if (task) { + this.currentlyRunningATask = true; + try { + task(); + } + finally { + this.clearImmediate(handle); + this.currentlyRunningATask = false; + } + } + } + }; + ImmediateDefinition.prototype.createMessageChannelSetImmediate = function () { + var _this = this; + var channel = new this.root.MessageChannel(); + channel.port1.onmessage = function (event) { + var handle = event.data; + _this.runIfPresent(handle); + }; + var fn = function setImmediate() { + var _a = setImmediate, channel = _a.channel, instance = _a.instance; + var handle = instance.addFromSetImmediateArguments(arguments); + channel.port2.postMessage(handle); + return handle; + }; + fn.channel = channel; + fn.instance = this; + return fn; + }; + ImmediateDefinition.prototype.createReadyStateChangeSetImmediate = function () { + var fn = function setImmediate() { + var instance = setImmediate.instance; + var root = instance.root; + var doc = root.document; + var html = doc.documentElement; + var handle = instance.addFromSetImmediateArguments(arguments); + // Create a