@reactivex/rxjs
Version:
Reactive Extensions for modern JavaScript
1,123 lines (1,080 loc) • 500 kB
JavaScript
/**
@license
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2015-2016 Netflix, Inc., Microsoft Corp. and contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
**/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Rx = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[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');
/**
* @class AsyncSubject<T>
*/
var AsyncSubject = (function (_super) {
__extends(AsyncSubject, _super);
function AsyncSubject() {
_super.apply(this, arguments);
this.value = null;
this.hasNext = false;
}
AsyncSubject.prototype._subscribe = function (subscriber) {
if (this.hasCompleted && this.hasNext) {
subscriber.next(this.value);
}
return _super.prototype._subscribe.call(this, subscriber);
};
AsyncSubject.prototype._next = function (value) {
this.value = value;
this.hasNext = true;
};
AsyncSubject.prototype._complete = function () {
var index = -1;
var observers = this.observers;
var len = observers.length;
// optimization to block our SubjectSubscriptions from
// splicing themselves out of the observers list one by one.
this.isUnsubscribed = true;
if (this.hasNext) {
while (++index < len) {
var o = observers[index];
o.next(this.value);
o.complete();
}
}
else {
while (++index < len) {
observers[index].complete();
}
}
this.isUnsubscribed = false;
this.unsubscribe();
};
return AsyncSubject;
}(Subject_1.Subject));
exports.AsyncSubject = AsyncSubject;
},{"./Subject":11}],2:[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<T>
*/
var BehaviorSubject = (function (_super) {
__extends(BehaviorSubject, _super);
function BehaviorSubject(_value) {
_super.call(this);
this._value = _value;
}
BehaviorSubject.prototype.getValue = function () {
if (this.hasErrored) {
throwError_1.throwError(this.errorValue);
}
else if (this.isUnsubscribed) {
throwError_1.throwError(new ObjectUnsubscribedError_1.ObjectUnsubscribedError());
}
else {
return this._value;
}
};
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);
};
BehaviorSubject.prototype._error = function (err) {
this.hasErrored = true;
_super.prototype._error.call(this, this.errorValue = err);
};
return BehaviorSubject;
}(Subject_1.Subject));
exports.BehaviorSubject = BehaviorSubject;
},{"./Subject":11,"./util/ObjectUnsubscribedError":259,"./util/throwError":273}],3:[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;
},{"./Subscriber":13}],4:[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<T>
*/
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();
}
};
/**
* 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();
}
};
/**
* 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<T>} 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<T>} 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<any>} 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;
},{"./Observable":5}],5:[function(require,module,exports){
"use strict";
var root_1 = require('./util/root');
var observable_1 = require('./symbol/observable');
var toSubscriber_1 = require('./util/toSubscriber');
/**
* A representation of any set of values over any amount of time. This the most basic building block
* of RxJS.
*
* @class Observable<T>
*/
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);
sink.add(operator ? operator.call(sink, this) : 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);
});
};
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_1.$$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;
},{"./symbol/observable":251,"./util/root":271,"./util/toSubscriber":274}],6:[function(require,module,exports){
"use strict";
exports.empty = {
isUnsubscribed: true,
next: function (value) { },
error: function (err) { throw err; },
complete: function () { }
};
},{}],7:[function(require,module,exports){
"use strict";
var Subscriber_1 = require('./Subscriber');
var Operator = (function () {
function Operator() {
}
Operator.prototype.call = function (subscriber, source) {
return source._subscribe(new Subscriber_1.Subscriber(subscriber));
};
return Operator;
}());
exports.Operator = Operator;
},{"./Subscriber":13}],8:[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;
},{"./Subscriber":13}],9:[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<T>
*/
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.events = [];
this.scheduler = scheduler;
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(now);
_super.prototype._next.call(this, value);
};
ReplaySubject.prototype._subscribe = function (subscriber) {
var events = this._trimBufferThenGetEvents(this._getNow());
var scheduler = this.scheduler;
if (scheduler) {
subscriber.add(subscriber = new observeOn_1.ObserveOnSubscriber(subscriber, scheduler));
}
var index = -1;
var len = events.length;
while (++index < len && !subscriber.isUnsubscribed) {
subscriber.next(events[index].value);
}
return _super.prototype._subscribe.call(this, subscriber);
};
ReplaySubject.prototype._getNow = function () {
return (this.scheduler || queue_1.queue).now();
};
ReplaySubject.prototype._trimBufferThenGetEvents = function (now) {
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 += 1;
}
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":11,"./operator/observeOn":198,"./scheduler/queue":249}],10:[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/interval');
require('./add/observable/merge');
require('./add/observable/race');
require('./add/observable/never');
require('./add/observable/of');
require('./add/observable/range');
require('./add/observable/throw');
require('./add/observable/timer');
require('./add/observable/zip');
//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/distinctUntilChanged');
require('./add/operator/do');
require('./add/operator/expand');
require('./add/operator/filter');
require('./add/operator/finally');
require('./add/operator/first');
require('./add/operator/groupBy');
require('./add/operator/ignoreElements');
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/merge');
require('./add/operator/mergeAll');
require('./add/operator/mergeMap');
require('./add/operator/mergeMapTo');
require('./add/operator/multicast');
require('./add/operator/observeOn');
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/timeout');
require('./add/operator/timeoutWith');
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 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 asap_1 = require('./scheduler/asap');
var async_1 = require('./scheduler/async');
var queue_1 = require('./scheduler/queue');
var rxSubscriber_1 = require('./symbol/rxSubscriber');
var observable_1 = require('./symbol/observable');
var iterator_1 = require('./symbol/iterator');
/* 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
};
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_1.$$observable,
iterator: iterator_1.$$iterator
};
exports.Symbol = Symbol;
},{"./AsyncSubject":1,"./BehaviorSubject":2,"./Notification":4,"./Observable":5,"./Operator":7,"./ReplaySubject":9,"./Subject":11,"./Subscriber":13,"./Subscription":14,"./add/observable/bindCallback":15,"./add/observable/bindNodeCallback":16,"./add/observable/combineLatest":17,"./add/observable/concat":18,"./add/observable/defer":19,"./add/observable/empty":20,"./add/observable/forkJoin":21,"./add/observable/from":22,"./add/observable/fromEvent":23,"./add/observable/fromEventPattern":24,"./add/observable/fromPromise":25,"./add/observable/interval":26,"./add/observable/merge":27,"./add/observable/never":28,"./add/observable/of":29,"./add/observable/race":30,"./add/observable/range":31,"./add/observable/throw":32,"./add/observable/timer":33,"./add/observable/zip":34,"./add/operator/audit":35,"./add/operator/auditTime":36,"./add/operator/buffer":37,"./add/operator/bufferCount":38,"./add/operator/bufferTime":39,"./add/operator/bufferToggle":40,"./add/operator/bufferWhen":41,"./add/operator/cache":42,"./add/operator/catch":43,"./add/operator/combineAll":44,"./add/operator/combineLatest":45,"./add/operator/concat":46,"./add/operator/concatAll":47,"./add/operator/concatMap":48,"./add/operator/concatMapTo":49,"./add/operator/count":50,"./add/operator/debounce":51,"./add/operator/debounceTime":52,"./add/operator/defaultIfEmpty":53,"./add/operator/delay":54,"./add/operator/delayWhen":55,"./add/operator/dematerialize":56,"./add/operator/distinctUntilChanged":57,"./add/operator/do":58,"./add/operator/every":59,"./add/operator/expand":60,"./add/operator/filter":61,"./add/operator/finally":62,"./add/operator/first":63,"./add/operator/groupBy":64,"./add/operator/ignoreElements":65,"./add/operator/last":66,"./add/operator/let":67,"./add/operator/map":68,"./add/operator/mapTo":69,"./add/operator/materialize":70,"./add/operator/merge":71,"./add/operator/mergeAll":72,"./add/operator/mergeMap":73,"./add/operator/mergeMapTo":74,"./add/operator/multicast":75,"./add/operator/observeOn":76,"./add/operator/partition":77,"./add/operator/pluck":78,"./add/operator/publish":79,"./add/operator/publishBehavior":80,"./add/operator/publishLast":81,"./add/operator/publishReplay":82,"./add/operator/race":83,"./add/operator/reduce":84,"./add/operator/repeat":85,"./add/operator/retry":86,"./add/operator/retryWhen":87,"./add/operator/sample":88,"./add/operator/sampleTime":89,"./add/operator/scan":90,"./add/operator/share":91,"./add/operator/single":92,"./add/operator/skip":93,"./add/operator/skipUntil":94,"./add/operator/skipWhile":95,"./add/operator/startWith":96,"./add/operator/subscribeOn":97,"./add/operator/switch":98,"./add/operator/switchMap":99,"./add/operator/switchMapTo":100,"./add/operator/take":101,"./add/operator/takeLast":102,"./add/operator/takeUntil":103,"./add/operator/takeWhile":104,"./add/operator/throttle":105,"./add/operator/throttleTime":106,"./add/operator/timeout":107,"./add/operator/timeoutWith":108,"./add/operator/toArray":109,"./add/operator/toPromise":110,"./add/operator/window":111,"./add/operator/windowCount":112,"./add/operator/windowTime":113,"./add/operator/windowToggle":114,"./add/operator/windowWhen":115,"./add/operator/withLatestFrom":116,"./add/operator/zip":117,"./add/operator/zipAll":118,"./observable/ConnectableObservable":123,"./scheduler/asap":247,"./scheduler/async":248,"./scheduler/queue":249,"./symbol/iterator":250,"./symbol/observable":251,"./symbol/rxSubscriber":252,"./util/ArgumentOutOfRangeError":253,"./util/EmptyError":254,"./util/ObjectUnsubscribedError":259,"./util/UnsubscriptionError":260}],11:[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 SubjectSubscription_1 = require('./SubjectSubscription');
var rxSubscriber_1 = require('./symbol/rxSubscriber');
var throwError_1 = require('./util/throwError');
var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError');
/**
* @class Subject<T>
*/
var Subject = (function (_super) {
__extends(Subject, _super);
function Subject(destination, source) {
_super.call(this);
this.destination = destination;
this.source = source;
this.observers = [];
this.isUnsubscribed = false;
this.isStopped = false;
this.hasErrored = false;
this.dispatching = false;
this.hasCompleted = false;
this.source = source;
}
Subject.prototype.lift = function (operator) {
var subject = new Subject(this.destination || this, this);
subject.operator = operator;
return subject;
};
Subject.prototype.add = function (subscription) {
return Subscription_1.Subscription.prototype.add.call(this, subscription);
};
Subject.prototype.remove = function (subscription) {
Subscription_1.Subscription.prototype.remove.call(this, subscription);
};
Subject.prototype.unsubscribe = function () {
Subscription_1.Subscription.prototype.unsubscribe.call(this);
};
Subject.prototype._subscribe = function (subscriber) {
if (this.source) {
return this.source.subscribe(subscriber);
}
else {
if (subscriber.isUnsubscribed) {
return;
}
else if (this.hasErrored) {
return subscriber.error(this.errorValue);
}
else if (this.hasCompleted) {
return subscriber.complete();
}
this.throwIfUnsubscribed();
var subscription = new SubjectSubscription_1.SubjectSubscription(this, subscriber);
this.observers.push(subscriber);
return subscription;
}
};
Subject.prototype._unsubscribe = function () {
this.source = null;
this.isStopped = true;
this.observers = null;
this.destination = null;
};
Subject.prototype.next = function (value) {
this.throwIfUnsubscribed();
if (this.isStopped) {
return;
}
this.dispatching = true;
this._next(value);
this.dispatching = false;
if (this.hasErrored) {
this._error(this.errorValue);
}
else if (this.hasCompleted) {
this._complete();
}
};
Subject.prototype.error = function (err) {
this.throwIfUnsubscribed();
if (this.isStopped) {
return;
}
this.isStopped = true;
this.hasErrored = true;
this.errorValue = err;
if (this.dispatching) {
return;
}
this._error(err);
};
Subject.prototype.complete = function () {
this.throwIfUnsubscribed();
if (this.isStopped) {
return;
}
this.isStopped = true;
this.hasCompleted = true;
if (this.dispatching) {
return;
}
this._complete();
};
Subject.prototype.asObservable = function () {
var observable = new SubjectObservable(this);
return observable;
};
Subject.prototype._next = function (value) {
if (this.destination) {
this.destination.next(value);
}
else {
this._finalNext(value);
}
};
Subject.prototype._finalNext = function (value) {
var index = -1;
var observers = this.observers.slice(0);
var len = observers.length;
while (++index < len) {
observers[index].next(value);
}
};
Subject.prototype._error = function (err) {
if (this.destination) {
this.destination.error(err);
}
else {
this._finalError(err);
}
};
Subject.prototype._finalError = function (err) {
var index = -1;
var observers = this.observers;
// optimization to block our SubjectSubscriptions from
// splicing themselves out of the observers list one by one.
this.observers = null;
this.isUnsubscribed = true;
if (observers) {
var len = observers.length;
while (++index < len) {
observers[index].error(err);
}
}
this.isUnsubscribed = false;
this.unsubscribe();
};
Subject.prototype._complete = function () {
if (this.destination) {
this.destination.complete();
}
else {
this._finalComplete();
}
};
Subject.prototype._finalComplete = function () {
var index = -1;
var observers = this.observers;
// optimization to block our SubjectSubscriptions from
// splicing themselves out of the observers list one by one.
this.observers = null;
this.isUnsubscribed = true;
if (observers) {
var len = observers.length;
while (++index < len) {
observers[index].complete();
}
}
this.isUnsubscribed = false;
this.unsubscribe();
};
Subject.prototype.throwIfUnsubscribed = function () {
if (this.isUnsubscribed) {
throwError_1.throwError(new ObjectUnsubscribedError_1.ObjectUnsubscribedError());
}
};
Subject.prototype[rxSubscriber_1.$$rxSubscriber] = function () {
return new Subscriber_1.Subscriber(this);
};
Subject.create = function (destination, source) {
return new Subject(destina