Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 87dfd51109f5e061a084d428b322955376d5bfc4 @bennage bennage committed
163 .gitignore
@@ -0,0 +1,163 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
3 authors.txt
@@ -0,0 +1,3 @@
+Matthew Podwysocki <matthewp@microsoft.com>
+Bart de Smet <bartde@microsoft.com>
+Erik Meijer <emeijer@microsoft.com>
26 package.json
@@ -0,0 +1,26 @@
+{
+ "name": "rxjs",
+ "title": "Reactive Extensions for JavaScript (RxJS)",
+ "description": "Library for composing asynchronous and event-based operations in JavaScript",
+ "version": "2",
+ "homepage": "http://msdn.microsoft.com/en-us/data/gg577609.aspx",
+ "author": {
+ "name": "Cloud Programmability Team",
+ "url": "https://github.com/Reactive-Extensions/Rx.JS/blob/master/AUTHORS.txt"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/Reactive-Extensions/Rx.JS.git"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/Reactive-Extensions/Rx.JS/blob/master/license.txt"
+ }
+ ],
+ "dependencies": {},
+ "devDependencies": {
+ "grunt": "~0.3.9"
+ },
+ "keywords": []
+}
0 readme.md
No changes.
3,873 rx-vsdoc.js
3,873 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
598 rx.aggregates-vsdoc.js
@@ -0,0 +1,598 @@
+/**
+* @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the Microsoft Reference Source License (MS-RSL).
+* http://referencesource.microsoft.com/referencesourcelicense.aspx.
+*/
+
+(function (root, factory) {
+ var freeExports = typeof exports == 'object' && exports &&
+ (typeof root == 'object' && root && root == root.global && (window = root), exports);
+
+ // Because of build optimizers
+ if (typeof define === 'function' && define.amd) {
+ define(['rx', 'exports'], function (Rx, exports) {
+ root.Rx = factory(root, exports, Rx);
+ return root.Rx;
+ });
+ } else if (typeof module == 'object' && module && module.exports == freeExports) {
+ module.exports = factory(root, module.exports, require('./rx'));
+ } else {
+ root.Rx = factory(root, {}, root.Rx);
+ }
+}(this, function (global, exp, root, undefined) {
+
+ // References
+ var Observable = root.Observable,
+ observableProto = Observable.prototype,
+ CompositeDisposable = root.CompositeDisposable,
+ AnonymousObservable = root.Internals.AnonymousObservable;
+
+ // Defaults
+ var argumentOutOfRange = 'Argument out of range';
+ var sequenceContainsNoElements = "Sequence contains no elements.";
+ function defaultComparer(x, y) { return x === y; }
+ function identity(x) { return x; }
+ function subComparer(x, y) {
+ if (x > y) {
+ return 1;
+ }
+ if (x === y) {
+ return 0;
+ }
+ return -1;
+ }
+
+ function extremaBy(source, keySelector, comparer) {
+ return new AnonymousObservable(function (observer) {
+ var hasValue = false, lastKey = null, list = [];
+ return source.subscribe(function (x) {
+ var comparison, key;
+ try {
+ key = keySelector(x);
+ } catch (ex) {
+ observer.onError(ex);
+ return;
+ }
+ comparison = 0;
+ if (!hasValue) {
+ hasValue = true;
+ lastKey = key;
+ } else {
+ try {
+ comparison = comparer(key, lastKey);
+ } catch (ex1) {
+ observer.onError(ex1);
+ return;
+ }
+ }
+ if (comparison > 0) {
+ lastKey = key;
+ list = [];
+ }
+ if (comparison >= 0) {
+ list.push(x);
+ }
+ }, observer.onError.bind(observer), function () {
+ observer.onNext(list);
+ observer.onCompleted();
+ });
+ });
+ }
+
+ function firstOnly(x) {
+ if (x.length == 0) {
+ throw new Error(sequenceContainsNoElements);
+ }
+ return x[0];
+ }
+
+ // Aggregation methods
+ observableProto.aggregate = function () {
+ /// <summary>
+ /// Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
+ /// For aggregation behavior with incremental intermediate results, see Observable.scan.
+ /// &#10;
+ /// &#10;1 - res = source.aggregate(function (acc, x) { return acc + x; });
+ /// &#10;2 - res = source.aggregate(0, function (acc, x) { return acc + x; });
+ /// </summary>
+ /// <param name="seed">[Optional] The initial accumulator value.</param>
+ /// <param name="accumulator">An accumulator function to be invoked on each element.</param>
+ /// <returns>An observable sequence containing a single element with the final accumulator value.</returns>
+ var seed, hasSeed, accumulator;
+ if (arguments.length === 2) {
+ seed = arguments[0];
+ hasSeed = true;
+ accumulator = arguments[1];
+ } else {
+ accumulator = arguments[0];
+ }
+ return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
+ };
+
+ observableProto.any = function (predicate) {
+ /// <summary>
+ /// Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
+ /// &#10;
+ /// &#10;1 - res = source.any();
+ /// &#10;2 - res = source.any(function (x) { return x > 3; });
+ /// </summary>
+ /// <param name="predicate">[Optional] A function to test each element for a condition.</param>
+ /// <returns>An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.</returns>
+ var source = this;
+ return predicate
+ ? source.where(predicate).any()
+ : new AnonymousObservable(function (observer) {
+ return source.subscribe(function () {
+ observer.onNext(true);
+ observer.onCompleted();
+ }, observer.onError.bind(observer), function () {
+ observer.onNext(false);
+ observer.onCompleted();
+ });
+ });
+ };
+
+ observableProto.isEmpty = function () {
+ /// <summary>
+ /// Determines whether an observable sequence is empty.
+ /// </summary>
+ /// <returns>An observable sequence containing a single element determining whether the source sequence is empty.</returns>
+ return this.any().select(function (b) { return !b; });
+ };
+
+ observableProto.all = function (predicate) {
+ /// <summary>
+ /// Determines whether all elements of an observable sequence satisfy a condition.
+ /// &#10;
+ /// &#10;1 - res = source.all(function (value) { return value.length > 3; });
+ /// </summary>
+ /// <param name="predicate">A function to test each element for a condition.</param>
+ /// <returns>An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.</returns>
+ return this.where(function (v) {
+ return !predicate(v);
+ }).any().select(function (b) {
+ return !b;
+ });
+ };
+
+ observableProto.contains = function (value, comparer) {
+ /// <summary>
+ /// Determines whether an observable sequence contains a specified element with an optional equality comparer.
+ /// &#10;
+ /// &#10;1 - res = source.contains(42);
+ /// &#10;2 - res = source.contains({ value: 42 }, function (x, y) { return x.value === y.value; });
+ /// </summary>
+ /// <param name="value">The value to locate in the source sequence.</param>
+ /// <param name="comparer">[Optional] An equality comparer to compare elements.</param>
+ /// <returns>An observable sequence containing a single element determining whether the source sequence contains an element that has the specified value.</returns>
+ comparer || (comparer = defaultComparer);
+ return this.where(function (v) {
+ return comparer(v, value);
+ }).any();
+ };
+
+ observableProto.count = function (predicate) {
+ /// <summary>
+ /// Returns an observable sequence containing a value that represents how many elements in the specified observable sequence satisfy a condition if provided, else the count of items.
+ /// &#10;
+ /// &#10;1 - res = source.count();
+ /// &#10;2 - res = source.count(function (x) { return x > 3; });
+ /// </summary>
+ /// <param name="predicate">[Optional] A function to test each element for a condition.</param>
+ /// <returns>An observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function if provided, else the count of items in the sequence.</returns>
+ return predicate ?
+ this.where(predicate).count() :
+ this.aggregate(0, function (count) {
+ return count + 1;
+ });
+ };
+
+ observableProto.sum = function (keySelector) {
+ /// <summary>
+ /// Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
+ /// &#10;
+ /// &#10;1 - res = source.sum();
+ /// &#10;2 - res = source.sum(function (x) { return x.value; });
+ /// </summary>
+ /// <param name="selector">[Optional] A transform function to apply to each element.</param>
+ /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
+ return keySelector ?
+ this.select(keySelector).sum() :
+ this.aggregate(0, function (prev, curr) {
+ return prev + curr;
+ });
+ };
+
+ observableProto.minBy = function (keySelector, comparer) {
+ /// <summary>
+ /// Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
+ /// &#10;
+ /// &#10;1 - res = source.minBy(function (x) { return x.value; });
+ /// &#10;2 - res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
+ /// </summary>
+ /// <param name="keySelector">Key selector function.</param>
+ /// <param name="comparer">[Optional] Comparer used to compare key values.</param>
+ /// <returns>An observable sequence containing a list of zero or more elements that have a minimum key value.</returns>
+ comparer || (comparer = subComparer);
+ return extremaBy(this, keySelector, function (x, y) {
+ return comparer(x, y) * -1;
+ });
+ };
+
+ observableProto.min = function (comparer) {
+ /// <summary>
+ /// Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
+ /// &#10;
+ /// &#10;1 - res = source.min();
+ /// &#10;2 - res = source.min(function (x, y) { return x.value - y.value; });
+ /// </summary>
+ /// <param name="comparer">Comparer used to compare elements.</param>
+ /// <returns>An observable sequence containing a single element with the minimum element in the source sequence.</returns>
+ return this.minBy(identity, comparer).select(function (x) {
+ return firstOnly(x);
+ });
+ };
+
+ observableProto.maxBy = function (keySelector, comparer) {
+ /// <summary>
+ /// Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
+ /// &#10;
+ /// &#10;1 - res = source.maxBy(function (x) { return x.value; });
+ /// &#10;2 - res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
+ /// </summary>
+ /// <param name="keySelector">Key selector function.</param>
+ /// <param name="comparer">[Optional] Comparer used to compare key values.</param>
+ /// <returns>An observable sequence containing a list of zero or more elements that have a maximum key value.</returns>
+ comparer || (comparer = subComparer);
+ return extremaBy(this, keySelector, comparer);
+ };
+
+ observableProto.max = function (comparer) {
+ /// <summary>
+ /// Returns the maximum value in an observable sequence according to the specified comparer.
+ /// &#10;
+ /// &#10;1 - res = source.max();
+ /// &#10;2 - res = source.max(function (x, y) { return x.value - y.value; });
+ /// </summary>
+ /// <param name="comparer">[Optional] Comparer used to compare elements.</param>
+ /// <returns>An observable sequence containing a single element with the maximum element in the source sequence.</returns>
+ return this.maxBy(identity, comparer).select(function (x) {
+ return firstOnly(x);
+ });
+ };
+
+ observableProto.average = function (keySelector) {
+ /// <summary>
+ /// Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
+ /// &#10;
+ /// &#10;1 - res = source.average();
+ /// &#10;2 - res = source.average(function (x) { return x.value; });
+ /// </summary>
+ /// <param name="selector">[Optional] A transform function to apply to each element.</param>
+ /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
+ return keySelector ?
+ this.select(keySelector).average() :
+ this.scan({
+ sum: 0,
+ count: 0
+ }, function (prev, cur) {
+ return {
+ sum: prev.sum + cur,
+ count: prev.count + 1
+ };
+ }).finalValue().select(function (s) {
+ return s.sum / s.count;
+ });
+ };
+
+ function sequenceEqualArray(first, second, comparer) {
+ return new AnonymousObservable(function (observer) {
+ var count = 0, len = second.length;
+ return first.subscribe(function (value) {
+ var equal = false;
+ try {
+ if (count < len) {
+ equal = comparer(value, second[count++]);
+ }
+ } catch (e) {
+ observer.onError(e);
+ return;
+ }
+ if (!equal) {
+ observer.onNext(false);
+ observer.onCompleted();
+ }
+ }, observer.onError.bind(observer), function () {
+ observer.onNext(count === len);
+ observer.onCompleted();
+ });
+ });
+ }
+
+ observableProto.sequenceEqual = function (second, comparer) {
+ /// <summary>
+ /// Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
+ /// &#10;
+ /// &#10;1 - res = source.sequenceEqual([1,2,3]);
+ /// &#10;2 - res = source.sequenceEqual([{ value: 42 }], function (x, y) { return x.value === y.value; });
+ /// &#10;3 - res = source.sequenceEqual(Rx.Observable.returnValue(42));
+ /// &#10;4 - res = source.sequenceEqual(Rx.Observable.returnValue({ value: 42 }), function (x, y) { return x.value === y.value; });
+ /// </summary>
+ /// <param name="second">Second observable sequence or array to compare.</param>
+ /// <param name="comparer">[Optional] Comparer used to compare elements of both sequences.</param>
+ /// <returns>An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer.</returns>
+ var first = this;
+ comparer || (comparer = defaultComparer);
+ if (Array.isArray(second)) {
+ return sequenceEqualArray(first, second, comparer);
+ }
+ return new AnonymousObservable(function (observer) {
+ var donel = false, doner = false, ql = [], qr = [];
+ var subscription1 = first.subscribe(function (x) {
+ var equal, v;
+ if (qr.length > 0) {
+ v = qr.shift();
+ try {
+ equal = comparer(v, x);
+ } catch (e) {
+ observer.onError(e);
+ return;
+ }
+ if (!equal) {
+ observer.onNext(false);
+ observer.onCompleted();
+ }
+ } else if (doner) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else {
+ ql.push(x);
+ }
+ }, observer.onError.bind(observer), function () {
+ donel = true;
+ if (ql.length === 0) {
+ if (qr.length > 0) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else if (doner) {
+ observer.onNext(true);
+ observer.onCompleted();
+ }
+ }
+ });
+ var subscription2 = second.subscribe(function (x) {
+ var equal, v;
+ if (ql.length > 0) {
+ v = ql.shift();
+ try {
+ equal = comparer(v, x);
+ } catch (exception) {
+ observer.onError(exception);
+ return;
+ }
+ if (!equal) {
+ observer.onNext(false);
+ observer.onCompleted();
+ }
+ } else if (donel) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else {
+ qr.push(x);
+ }
+ }, observer.onError.bind(observer), function () {
+ doner = true;
+ if (qr.length === 0) {
+ if (ql.length > 0) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else if (donel) {
+ observer.onNext(true);
+ observer.onCompleted();
+ }
+ }
+ });
+ return new CompositeDisposable(subscription1, subscription2);
+ });
+ };
+
+ function elementAtOrDefault(source, index, hasDefault, defaultValue) {
+ if (index < 0) {
+ throw new Error(argumentOutOfRange);
+ }
+ return new AnonymousObservable(function (observer) {
+ var i = index;
+ return source.subscribe(function (x) {
+ if (i === 0) {
+ observer.onNext(x);
+ observer.onCompleted();
+ }
+ i--;
+ }, observer.onError.bind(observer), function () {
+ if (!hasDefault) {
+ observer.onError(new Error(argumentOutOfRange));
+ } else {
+ observer.onNext(defaultValue);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.elementAt = function (index) {
+ /// <summary>
+ /// Returns the element at a specified index in a sequence.
+ /// &#10;
+ /// &#10;1 - res = source.elementAt(5);
+ /// </summary>
+ /// <param name="index">The zero-based index of the element to retrieve.</param>
+ /// <returns>An observable sequence that produces the element at the specified position in the source sequence.</returns>
+ return elementAtOrDefault(this, index, false);
+ };
+
+ observableProto.elementAtOrDefault = function (index, defaultValue) {
+ /// <summary>
+ /// Returns the element at a specified index in a sequence or a default value if the index is out of range.
+ /// &#10;
+ /// &#10;1 - res = source.elementAtOrDefault(5);
+ /// &#10;2 - res = source.elementAtOrDefault(5, 0);
+ /// </summary>
+ /// <param name="index">The zero-based index of the element to retrieve.</param>
+ /// <param name="defaultValue">[Optional] The default value if the index is outside the bounds of the source sequence.</param>
+ /// <returns>An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.</returns>
+ return elementAtOrDefault(this, index, true, defaultValue);
+ };
+
+ function singleOrDefaultAsync(source, hasDefault, defaultValue) {
+ return new AnonymousObservable(function (observer) {
+ var value = defaultValue, seenValue = false;
+ return source.subscribe(function (x) {
+ if (seenValue) {
+ observer.onError(new Error('Sequence contains more than one element'));
+ } else {
+ value = x;
+ seenValue = true;
+ }
+ }, observer.onError.bind(observer), function () {
+ if (!seenValue && !hasDefault) {
+ observer.onError(new Error(sequenceContainsNoElements));
+ } else {
+ observer.onNext(value);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.single = function (predicate) {
+ /// <summary>
+ /// Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
+ /// &#10;
+ /// &#10;1 - res = source.single();
+ /// &#10;2 - res = source.single(function (x) { return x === 42; });
+ /// </summary>
+ /// <param name="predicate">[Optional] A predicate function to evaluate for elements in the source sequence.</param>
+ /// <returns>Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.</returns>
+ if (predicate) {
+ return this.where(predicate).single();
+ }
+ return singleOrDefaultAsync(this, false);
+ };
+
+ observableProto.singleOrDefault = function (predicate, defaultValue) {
+ /// <summary>
+ /// Returns the only element of an observable sequence that matches the predicate, or a default value if no such element exists; this method reports an exception if there is more than one element in the observable sequence.
+ /// &#10;
+ /// &#10;1 - res = source.singleOrDefault();
+ /// &#10;2 - res = source.singleOrDefault(function (x) { return x === 42; });
+ /// &#10;3 - res = source.singleOrDefault(function (x) { return x === 42; }, 0);
+ /// &#10;4 - res = source.singleOrDefault(null, 0);
+ /// </summary>
+ /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
+ /// <returns>Sequence containing the single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.</returns>
+ if (predicate) {
+ return this.where(predicate).singleOrDefault(null, defaultValue);
+ }
+ return singleOrDefaultAsync(this, true, defaultValue);
+ };
+
+ function firstOrDefaultAsync(source, hasDefault, defaultValue) {
+ return new AnonymousObservable(function (observer) {
+ return source.subscribe(function (x) {
+ observer.onNext(x);
+ observer.onCompleted();
+ }, observer.onError.bind(observer), function () {
+ if (!hasDefault) {
+ observer.onError(new Error(sequenceContainsNoElements));
+ } else {
+ observer.onNext(defaultValue);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.first = function (predicate) {
+ /// <summary>
+ /// Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
+ /// &#10;
+ /// &#10;1 - res = source.first();
+ /// &#10;2 - res = source.first(function (x) { return x > 3; });
+ /// </summary>
+ /// <param name="predicate">[Optional] A predicate function to evaluate for elements in the source sequence.</param>
+ /// <returns>Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.</returns>
+ if (predicate) {
+ return this.where(predicate).first();
+ }
+ return firstOrDefaultAsync(this, false);
+ };
+
+ observableProto.firstOrDefault = function (predicate, defaultValue) {
+ /// <summary>
+ /// Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
+ /// &#10;1 - res = source.firstOrDefault();
+ /// &#10;2 - res = source.firstOrDefault(function (x) { return x > 3; });
+ /// &#10;3 - res = source.firstOrDefault(function (x) { return x > 3; }, 0);
+ /// &#10;4 - res = source.firstOrDefault(null, 0);
+ /// </summary>
+ /// <param name="predicate">[Optional] A predicate function to evaluate for elements in the source sequence. </param>
+ /// <param name="defaultValue">[Optional] The default value if no such element exists. If not specified, defaults to null.</param>
+ /// <returns>Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.</returns>
+ if (predicate) {
+ return this.where(predicate).firstOrDefault(null, defaultValue);
+ }
+ return firstOrDefaultAsync(this, true, defaultValue);
+ };
+
+ function lastOrDefaultAsync(source, hasDefault, defaultValue) {
+ return new AnonymousObservable(function (observer) {
+ var value = defaultValue, seenValue = false;
+ return source.subscribe(function (x) {
+ value = x;
+ seenValue = true;
+ }, observer.onError.bind(observer), function () {
+ if (!seenValue && !hasDefault) {
+ observer.onError(new Error(sequenceContainsNoElements));
+ } else {
+ observer.onNext(value);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.last = function (predicate) {
+ /// <summary>
+ /// Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
+ /// &#10;
+ /// &#10;1 - res = source.last();
+ /// &#10;2 - res = source.last(function (x) { return x > 3; });
+ /// </summary>
+ /// <param name="predicate">[Optional] A predicate function to evaluate for elements in the source sequence.</param>
+ /// <returns>Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.</returns>
+ if (predicate) {
+ return this.where(predicate).last();
+ }
+ return lastOrDefaultAsync(this, false);
+ };
+
+ observableProto.lastOrDefault = function (predicate, defaultValue) {
+ /// <summary>
+ /// Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
+ /// &#10;
+ /// &#10;1 - res = source.lastOrDefault();
+ /// &#10;2 - res = source.lastOrDefault(function (x) { return x > 3; });
+ /// &#10;3 - res = source.lastOrDefault(function (x) { return x > 3; }, 0);
+ /// &#10;4 - res = source.lastOrDefault(null, 0);
+ /// </summary>
+ /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
+ /// <returns>Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.</returns>
+ if (predicate) {
+ return this.where(predicate).lastOrDefault(null, defaultValue);
+ }
+ return lastOrDefaultAsync(this, true, defaultValue);
+ };
+
+ return root;
+}));
421 rx.aggregates.js
@@ -0,0 +1,421 @@
+/**
+* @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the Microsoft Reference Source License (MS-RSL).
+* http://referencesource.microsoft.com/referencesourcelicense.aspx.
+*/
+
+(function (root, factory) {
+ var freeExports = typeof exports == 'object' && exports &&
+ (typeof root == 'object' && root && root == root.global && (window = root), exports);
+
+ // Because of build optimizers
+ if (typeof define === 'function' && define.amd) {
+ define(['rx', 'exports'], function (Rx, exports) {
+ root.Rx = factory(root, exports, Rx);
+ return root.Rx;
+ });
+ } else if (typeof module == 'object' && module && module.exports == freeExports) {
+ module.exports = factory(root, module.exports, require('./rx'));
+ } else {
+ root.Rx = factory(root, {}, root.Rx);
+ }
+}(this, function (global, exp, root, undefined) {
+
+ // References
+ var Observable = root.Observable,
+ observableProto = Observable.prototype,
+ CompositeDisposable = root.CompositeDisposable,
+ AnonymousObservable = root.Internals.AnonymousObservable;
+
+ // Defaults
+ var argumentOutOfRange = 'Argument out of range';
+ var sequenceContainsNoElements = "Sequence contains no elements.";
+ function defaultComparer(x, y) { return x === y; }
+ function identity(x) { return x; }
+ function subComparer(x, y) {
+ if (x > y) {
+ return 1;
+ }
+ if (x === y) {
+ return 0;
+ }
+ return -1;
+ }
+
+ function extremaBy(source, keySelector, comparer) {
+ return new AnonymousObservable(function (observer) {
+ var hasValue = false, lastKey = null, list = [];
+ return source.subscribe(function (x) {
+ var comparison, key;
+ try {
+ key = keySelector(x);
+ } catch (ex) {
+ observer.onError(ex);
+ return;
+ }
+ comparison = 0;
+ if (!hasValue) {
+ hasValue = true;
+ lastKey = key;
+ } else {
+ try {
+ comparison = comparer(key, lastKey);
+ } catch (ex1) {
+ observer.onError(ex1);
+ return;
+ }
+ }
+ if (comparison > 0) {
+ lastKey = key;
+ list = [];
+ }
+ if (comparison >= 0) {
+ list.push(x);
+ }
+ }, observer.onError.bind(observer), function () {
+ observer.onNext(list);
+ observer.onCompleted();
+ });
+ });
+ }
+
+ function firstOnly(x) {
+ if (x.length == 0) {
+ throw new Error(sequenceContainsNoElements);
+ }
+ return x[0];
+ }
+
+ // Aggregation methods
+ observableProto.aggregate = function () {
+ var seed, hasSeed, accumulator;
+ if (arguments.length === 2) {
+ seed = arguments[0];
+ hasSeed = true;
+ accumulator = arguments[1];
+ } else {
+ accumulator = arguments[0];
+ }
+ return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
+ };
+
+ observableProto.any = function (predicate) {
+ var source = this;
+ return predicate
+ ? source.where(predicate).any()
+ : new AnonymousObservable(function (observer) {
+ return source.subscribe(function () {
+ observer.onNext(true);
+ observer.onCompleted();
+ }, observer.onError.bind(observer), function () {
+ observer.onNext(false);
+ observer.onCompleted();
+ });
+ });
+ };
+
+ observableProto.isEmpty = function () {
+ return this.any().select(function (b) { return !b; });
+ };
+
+ observableProto.all = function (predicate) {
+ return this.where(function (v) {
+ return !predicate(v);
+ }).any().select(function (b) {
+ return !b;
+ });
+ };
+
+ observableProto.contains = function (value, comparer) {
+ comparer || (comparer = defaultComparer);
+ return this.where(function (v) {
+ return comparer(v, value);
+ }).any();
+ };
+
+ observableProto.count = function (predicate) {
+ return predicate ?
+ this.where(predicate).count() :
+ this.aggregate(0, function (count) {
+ return count + 1;
+ });
+ };
+
+ observableProto.sum = function (keySelector) {
+ return keySelector ?
+ this.select(keySelector).sum() :
+ this.aggregate(0, function (prev, curr) {
+ return prev + curr;
+ });
+ };
+
+ observableProto.minBy = function (keySelector, comparer) {
+ comparer || (comparer = subComparer);
+ return extremaBy(this, keySelector, function (x, y) {
+ return comparer(x, y) * -1;
+ });
+ };
+
+ observableProto.min = function (comparer) {
+ return this.minBy(identity, comparer).select(function (x) {
+ return firstOnly(x);
+ });
+ };
+
+ observableProto.maxBy = function (keySelector, comparer) {
+ comparer || (comparer = subComparer);
+ return extremaBy(this, keySelector, comparer);
+ };
+
+ observableProto.max = function (comparer) {
+ return this.maxBy(identity, comparer).select(function (x) {
+ return firstOnly(x);
+ });
+ };
+
+ observableProto.average = function (keySelector) {
+ return keySelector ?
+ this.select(keySelector).average() :
+ this.scan({
+ sum: 0,
+ count: 0
+ }, function (prev, cur) {
+ return {
+ sum: prev.sum + cur,
+ count: prev.count + 1
+ };
+ }).finalValue().select(function (s) {
+ return s.sum / s.count;
+ });
+ };
+
+ function sequenceEqualArray(first, second, comparer) {
+ return new AnonymousObservable(function (observer) {
+ var count = 0, len = second.length;
+ return first.subscribe(function (value) {
+ var equal = false;
+ try {
+ if (count < len) {
+ equal = comparer(value, second[count++]);
+ }
+ } catch (e) {
+ observer.onError(e);
+ return;
+ }
+ if (!equal) {
+ observer.onNext(false);
+ observer.onCompleted();
+ }
+ }, observer.onError.bind(observer), function () {
+ observer.onNext(count === len);
+ observer.onCompleted();
+ });
+ });
+ }
+
+ observableProto.sequenceEqual = function (second, comparer) {
+ var first = this;
+ comparer || (comparer = defaultComparer);
+ if (Array.isArray(second)) {
+ return sequenceEqualArray(first, second, comparer);
+ }
+ return new AnonymousObservable(function (observer) {
+ var donel = false, doner = false, ql = [], qr = [];
+ var subscription1 = first.subscribe(function (x) {
+ var equal, v;
+ if (qr.length > 0) {
+ v = qr.shift();
+ try {
+ equal = comparer(v, x);
+ } catch (e) {
+ observer.onError(e);
+ return;
+ }
+ if (!equal) {
+ observer.onNext(false);
+ observer.onCompleted();
+ }
+ } else if (doner) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else {
+ ql.push(x);
+ }
+ }, observer.onError.bind(observer), function () {
+ donel = true;
+ if (ql.length === 0) {
+ if (qr.length > 0) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else if (doner) {
+ observer.onNext(true);
+ observer.onCompleted();
+ }
+ }
+ });
+ var subscription2 = second.subscribe(function (x) {
+ var equal, v;
+ if (ql.length > 0) {
+ v = ql.shift();
+ try {
+ equal = comparer(v, x);
+ } catch (exception) {
+ observer.onError(exception);
+ return;
+ }
+ if (!equal) {
+ observer.onNext(false);
+ observer.onCompleted();
+ }
+ } else if (donel) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else {
+ qr.push(x);
+ }
+ }, observer.onError.bind(observer), function () {
+ doner = true;
+ if (qr.length === 0) {
+ if (ql.length > 0) {
+ observer.onNext(false);
+ observer.onCompleted();
+ } else if (donel) {
+ observer.onNext(true);
+ observer.onCompleted();
+ }
+ }
+ });
+ return new CompositeDisposable(subscription1, subscription2);
+ });
+ };
+
+ function elementAtOrDefault(source, index, hasDefault, defaultValue) {
+ if (index < 0) {
+ throw new Error(argumentOutOfRange);
+ }
+ return new AnonymousObservable(function (observer) {
+ var i = index;
+ return source.subscribe(function (x) {
+ if (i === 0) {
+ observer.onNext(x);
+ observer.onCompleted();
+ }
+ i--;
+ }, observer.onError.bind(observer), function () {
+ if (!hasDefault) {
+ observer.onError(new Error(argumentOutOfRange));
+ } else {
+ observer.onNext(defaultValue);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.elementAt = function (index) {
+ return elementAtOrDefault(this, index, false);
+ };
+
+ observableProto.elementAtOrDefault = function (index, defaultValue) {
+ return elementAtOrDefault(this, index, true, defaultValue);
+ };
+
+ function singleOrDefaultAsync(source, hasDefault, defaultValue) {
+ return new AnonymousObservable(function (observer) {
+ var value = defaultValue, seenValue = false;
+ return source.subscribe(function (x) {
+ if (seenValue) {
+ observer.onError(new Error('Sequence contains more than one element'));
+ } else {
+ value = x;
+ seenValue = true;
+ }
+ }, observer.onError.bind(observer), function () {
+ if (!seenValue && !hasDefault) {
+ observer.onError(new Error(sequenceContainsNoElements));
+ } else {
+ observer.onNext(value);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.single = function (predicate) {
+ if (predicate) {
+ return this.where(predicate).single();
+ }
+ return singleOrDefaultAsync(this, false);
+ };
+
+ observableProto.singleOrDefault = function (predicate, defaultValue) {
+ if (predicate) {
+ return this.where(predicate).singleOrDefault(null, defaultValue);
+ }
+ return singleOrDefaultAsync(this, true, defaultValue);
+ };
+
+ function firstOrDefaultAsync(source, hasDefault, defaultValue) {
+ return new AnonymousObservable(function (observer) {
+ return source.subscribe(function (x) {
+ observer.onNext(x);
+ observer.onCompleted();
+ }, observer.onError.bind(observer), function () {
+ if (!hasDefault) {
+ observer.onError(new Error(sequenceContainsNoElements));
+ } else {
+ observer.onNext(defaultValue);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.first = function (predicate) {
+ if (predicate) {
+ return this.where(predicate).first();
+ }
+ return firstOrDefaultAsync(this, false);
+ };
+
+ observableProto.firstOrDefault = function (predicate, defaultValue) {
+ if (predicate) {
+ return this.where(predicate).firstOrDefault(null, defaultValue);
+ }
+ return firstOrDefaultAsync(this, true, defaultValue);
+ };
+
+ function lastOrDefaultAsync(source, hasDefault, defaultValue) {
+ return new AnonymousObservable(function (observer) {
+ var value = defaultValue, seenValue = false;
+ return source.subscribe(function (x) {
+ value = x;
+ seenValue = true;
+ }, observer.onError.bind(observer), function () {
+ if (!seenValue && !hasDefault) {
+ observer.onError(new Error(sequenceContainsNoElements));
+ } else {
+ observer.onNext(value);
+ observer.onCompleted();
+ }
+ });
+ });
+ }
+
+ observableProto.last = function (predicate) {
+ if (predicate) {
+ return this.where(predicate).last();
+ }
+ return lastOrDefaultAsync(this, false);
+ };
+
+ observableProto.lastOrDefault = function (predicate, defaultValue) {
+ if (predicate) {
+ return this.where(predicate).lastOrDefault(null, defaultValue);
+ }
+ return lastOrDefaultAsync(this, true, defaultValue);
+ };
+
+ return root;
+}));
6 rx.aggregates.min.js
@@ -0,0 +1,6 @@
+/*** @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the MICROSOFT REACTIVE EXTENSIONS FOR JAVASCRIPT AND .NET LIBRARIES License.
+* See http://go.microsoft.com/fwlink/?LinkID=220762.
+*/
+(function(e,t){var n=typeof exports=="object"&&exports&&(typeof e=="object"&&e&&e==e.global&&(window=e),exports);typeof define=="function"&&define.amd?define(["rx","exports"],function(n,r){return e.Rx=t(e,r,n),e.Rx}):typeof module=="object"&&module&&module.exports==n?module.exports=t(e,module.exports,require("./rx")):e.Rx=t(e,{},e.Rx)})(this,function(e,t,n,r){function l(e,t){return e===t}function c(e){return e}function h(e,t){return e>t?1:e===t?0:-1}function p(e,t,n){return new u(function(r){var i=!1,s=null,o=[];return e.subscribe(function(e){var u,a;try{a=t(e)}catch(f){r.onError(f);return}u=0;if(!i)i=!0,s=a;else try{u=n(a,s)}catch(l){r.onError(l);return}u>0&&(s=a,o=[]),u>=0&&o.push(e)},r.onError.bind(r),function(){r.onNext(o),r.onCompleted()})})}function d(e){if(e.length==0)throw new Error(f);return e[0]}function v(e,t,n){return new u(function(r){var i=0,s=t.length;return e.subscribe(function(e){var o=!1;try{i<s&&(o=n(e,t[i++]))}catch(u){r.onError(u);return}o||(r.onNext(!1),r.onCompleted())},r.onError.bind(r),function(){r.onNext(i===s),r.onCompleted()})})}function m(e,t,n,r){if(t<0)throw new Error(a);return new u(function(i){var s=t;return e.subscribe(function(e){s===0&&(i.onNext(e),i.onCompleted()),s--},i.onError.bind(i),function(){n?(i.onNext(r),i.onCompleted()):i.onError(new Error(a))})})}function g(e,t,n){return new u(function(r){var i=n,s=!1;return e.subscribe(function(e){s?r.onError(new Error("Sequence contains more than one element")):(i=e,s=!0)},r.onError.bind(r),function(){!s&&!t?r.onError(new Error(f)):(r.onNext(i),r.onCompleted())})})}function y(e,t,n){return new u(function(r){return e.subscribe(function(e){r.onNext(e),r.onCompleted()},r.onError.bind(r),function(){t?(r.onNext(n),r.onCompleted()):r.onError(new Error(f))})})}function b(e,t,n){return new u(function(r){var i=n,s=!1;return e.subscribe(function(e){i=e,s=!0},r.onError.bind(r),function(){!s&&!t?r.onError(new Error(f)):(r.onNext(i),r.onCompleted())})})}var i=n.Observable,s=i.prototype,o=n.CompositeDisposable,u=n.Internals.AnonymousObservable,a="Argument out of range",f="Sequence contains no elements.";return s.aggregate=function(){var e,t,n;return arguments.length===2?(e=arguments[0],t=!0,n=arguments[1]):n=arguments[0],t?this.scan(e,n).startWith(e).finalValue():this.scan(n).finalValue()},s.any=function(e){var t=this;return e?t.where(e).any():new u(function(e){return t.subscribe(function(){e.onNext(!0),e.onCompleted()},e.onError.bind(e),function(){e.onNext(!1),e.onCompleted()})})},s.isEmpty=function(){return this.any().select(function(e){return!e})},s.all=function(e){return this.where(function(t){return!e(t)}).any().select(function(e){return!e})},s.contains=function(e,t){return t||(t=l),this.where(function(n){return t(n,e)}).any()},s.count=function(e){return e?this.where(e).count():this.aggregate(0,function(e){return e+1})},s.sum=function(e){return e?this.select(e).sum():this.aggregate(0,function(e,t){return e+t})},s.minBy=function(e,t){return t||(t=h),p(this,e,function(e,n){return t(e,n)*-1})},s.min=function(e){return this.minBy(c,e).select(function(e){return d(e)})},s.maxBy=function(e,t){return t||(t=h),p(this,e,t)},s.max=function(e){return this.maxBy(c,e).select(function(e){return d(e)})},s.average=function(e){return e?this.select(e).average():this.scan({sum:0,count:0},function(e,t){return{sum:e.sum+t,count:e.count+1}}).finalValue().select(function(e){return e.sum/e.count})},s.sequenceEqual=function(e,t){var n=this;return t||(t=l),Array.isArray(e)?v(n,e,t):new u(function(r){var i=!1,s=!1,u=[],a=[],f=n.subscribe(function(e){var n,i;if(a.length>0){i=a.shift();try{n=t(i,e)}catch(o){r.onError(o);return}n||(r.onNext(!1),r.onCompleted())}else s?(r.onNext(!1),r.onCompleted()):u.push(e)},r.onError.bind(r),function(){i=!0,u.length===0&&(a.length>0?(r.onNext(!1),r.onCompleted()):s&&(r.onNext(!0),r.onCompleted()))}),l=e.subscribe(function(e){var n,s;if(u.length>0){s=u.shift();try{n=t(s,e)}catch(o){r.onError(o);return}n||(r.onNext(!1),r.onCompleted())}else i?(r.onNext(!1),r.onCompleted()):a.push(e)},r.onError.bind(r),function(){s=!0,a.length===0&&(u.length>0?(r.onNext(!1),r.onCompleted()):i&&(r.onNext(!0),r.onCompleted()))});return new o(f,l)})},s.elementAt=function(e){return m(this,e,!1)},s.elementAtOrDefault=function(e,t){return m(this,e,!0,t)},s.single=function(e){return e?this.where(e).single():g(this,!1)},s.singleOrDefault=function(e,t){return e?this.where(e).singleOrDefault(null,t):g(this,!0,t)},s.first=function(e){return e?this.where(e).first():y(this,!1)},s.firstOrDefault=function(e,t){return e?this.where(e).firstOrDefault(null,t):y(this,!0,t)},s.last=function(e){return e?this.where(e).last():b(this,!1)},s.lastOrDefault=function(e,t){return e?this.where(e).lastOrDefault(null,t):b(this,!0,t)},n});
449 rx.binding-vsdoc.js
@@ -0,0 +1,449 @@
+/**
+* @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the Microsoft Reference Source License (MS-RSL).
+* http://referencesource.microsoft.com/referencesourcelicense.aspx.
+*/
+
+(function (root, factory) {
+ var freeExports = typeof exports == 'object' && exports &&
+ (typeof root == 'object' && root && root == root.global && (window = root), exports);
+
+ // Because of build optimizers
+ if (typeof define === 'function' && define.amd) {
+ define(['rx', 'exports'], function (Rx, exports) {
+ root.Rx = factory(root, exports, Rx);
+ return root.Rx;
+ });
+ } else if (typeof module == 'object' && module && module.exports == freeExports) {
+ module.exports = factory(root, module.exports, require('./rx'));
+ } else {
+ root.Rx = factory(root, {}, root.Rx);
+ }
+}(this, function (global, exp, root, undefined) {
+
+ var Observable = root.Observable,
+ observableProto = Observable.prototype,
+ AnonymousObservable = root.Internals.AnonymousObservable,
+ Subject = root.Subject,
+ AsyncSubject = root.AsyncSubject,
+ Observer = root.Observer,
+ ScheduledObserver = root.Internals.ScheduledObserver,
+ disposableCreate = root.Disposable.create,
+ disposableEmpty = root.Disposable.empty,
+ CompositeDisposable = root.CompositeDisposable,
+ currentThreadScheduler = root.Scheduler.currentThread,
+ inherits = root.Internals.inherits,
+ addProperties = root.Internals.addProperties;
+
+ // Utilities
+ var objectDisposed = 'Object has been disposed';
+ function checkDisposed() {
+ if (this.isDisposed) {
+ throw new Error(objectDisposed);
+ }
+ }
+
+ observableProto.multicast = function (subjectOrSubjectSelector, selector) {
+ /// <summary>
+ /// Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
+ /// subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
+ /// invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.
+ /// &#10;
+ /// &#10;1 - res = source.multicast(observable);
+ /// &#10;2 - res = source.multicast(function () { return new Subject(); }, function (x) { return x; });
+ /// </summary>
+ /// <param name="subjectOrSubjectSelector">
+ /// 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>
+ /// <param name="selector">[Optional] Selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if <paramref name="subjectOrSubjectSelector" is a factory function.</param>
+ /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
+ var source = this;
+ return typeof subjectOrSubjectSelector === 'function' ?
+ new AnonymousObservable(function (observer) {
+ var connectable = source.multicast(subjectOrSubjectSelector());
+ return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
+ }) :
+ new ConnectableObservable(source, subjectOrSubjectSelector);
+ };
+
+ observableProto.publish = function (selector) {
+ /// <summary>
+ /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
+ /// This operator is a specialization of Multicast using a regular Subject.
+ /// &#10;
+ /// &#10;1 - res = source.publish();
+ /// &#10;2 - res = source.publish(function (x) { return x; });
+ /// </summary>
+ /// <param name="selector">[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.</param>
+ /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
+ return !selector ?
+ this.multicast(new Subject()) :
+ this.multicast(function () {
+ return new Subject();
+ }, selector);
+ };
+
+ observableProto.publishLast = function (selector) {
+ /// <summary>
+ /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
+ /// This operator is a specialization of Multicast using a AsyncSubject.
+ /// &#10;
+ /// &#10;1 - res = source.publishLast();
+ /// &#10;2 - res = source.publishLast(function (x) { return x; });
+ /// </summary>
+ /// <param name="selector">[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 only receive the last notification of the source.</param>
+ /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
+ return !selector ?
+ this.multicast(new AsyncSubject()) :
+ this.multicast(function () {
+ return new AsyncSubject();
+ }, selector);
+ };
+
+ observableProto.publishValue = function (initialValueOrSelector, initialValue) {
+ /// <summary>
+ /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
+ /// This operator is a specialization of Multicast using a BehaviorSubject.
+ /// &#10;
+ /// &#10;1 - res = source.publishValue(42);
+ /// &#10;2 - res = source.publishLast(function (x) { return x.select(function (y) { return y * y; }) }, 42);
+ /// </summary>
+ /// <param name="selector">[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 immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.</param>
+ /// <param name="initialValue">Initial value received by observers upon subscription.</param>
+ /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
+ return arguments.length === 2 ?
+ this.multicast(function () {
+ return new BehaviorSubject(initialValue);
+ }, initialValueOrSelector) :
+ this.multicast(new BehaviorSubject(initialValueOrSelector));
+ };
+
+ observableProto.replay = function (selector, bufferSize, window, scheduler) {
+ /// <summary>
+ /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
+ /// This operator is a specialization of Multicast using a ReplaySubject.
+ /// &#10;
+ /// &#10;1 - res = source.replay(null, 3);
+ /// &#10;2 - res = source.replay(null, 3, 500 /* ms */);
+ /// &#10;3 - res = source.replay(null, 3, 500 /* ms */, /* scheduler */);
+ /// &#10;3 - res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500 /* ms */, /* scheduler */);
+ /// </summary>
+ /// <param name="selector">[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 the notifications of the source subject to the specified replay buffer trimming policy.</param>
+ /// <param name="bufferSize">[Optional] Maximum element count of the replay buffer.</param>
+ /// <param name="window">[Optional] Maximum time length of the replay buffer.</param>
+ /// <param name="scheduler">[Optional] Scheduler where connected observers within the selector function will be invoked on.</param>
+ /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
+ return !selector ?
+ this.multicast(new ReplaySubject(bufferSize, window, scheduler)) :
+ this.multicast(function () {
+ return new ReplaySubject(bufferSize, window, scheduler);
+ }, selector);
+ };
+
+ var InnerSubscription = function (subject, observer) {
+ this.subject = subject;
+ this.observer = observer;
+ };
+ InnerSubscription.prototype.dispose = function () {
+ if (!this.subject.isDisposed && this.observer !== null) {
+ var idx = this.subject.observers.indexOf(this.observer);
+ this.subject.observers.splice(idx, 1);
+ this.observer = null;
+ }
+ };
+
+ var BehaviorSubject = root.BehaviorSubject = (function () {
+ function subscribe(observer) {
+ var ex;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.observers.push(observer);
+ observer.onNext(this.value);
+ return new InnerSubscription(this, observer);
+ }
+ ex = this.exception;
+ if (ex) {
+ observer.onError(ex);
+ } else {
+ observer.onCompleted();
+ }
+ return disposableEmpty;
+ }
+
+ inherits(BehaviorSubject, Observable);
+ function BehaviorSubject(value) {
+ /// <summary>
+ /// Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
+ /// </summary>
+ /// <param name="value">Initial value sent to observers when no other value has been received by the subject yet.</param>
+ BehaviorSubject.super_.constructor.call(this, subscribe);
+
+ this.value = value,
+ this.observers = [],
+ this.isDisposed = false,
+ this.isStopped = false,
+ this.exception = null;
+ }
+
+ addProperties(BehaviorSubject.prototype, Observer, {
+ onCompleted: function () {
+ /// <summary>
+ /// Notifies all subscribed observers about the end of the sequence.
+ /// </summary>
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ var os = this.observers.slice(0);
+ this.isStopped = true;
+ for (var i = 0, len = os.length; i < len; i++) {
+ os[i].onCompleted();
+ }
+
+ this.observers = [];
+ }
+ },
+ onError: function (error) {
+ /// <summary>
+ /// Notifies all subscribed observers about the exception.
+ /// </summary>
+ /// <param name="error">The exception to send to all observers.</param>
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ var os = this.observers.slice(0);
+ this.isStopped = true;
+ this.exception = error;
+
+ for (var i = 0, len = os.length; i < len; i++) {
+ os[i].onError(error);
+ }
+
+ this.observers = [];
+ }
+ },
+ onNext: function (value) {
+ /// <summary>
+ /// Notifies all subscribed observers about the arrival of the specified element in the sequence.
+ /// </summary>
+ /// <param name="value">The value to send to all observers.</param>
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.value = value;
+ var os = this.observers.slice(0);
+ for (var i = 0, len = os.length; i < len; i++) {
+ os[i].onNext(value);
+ }
+ }
+ },
+ dispose: function () {
+ /// <summary>
+ /// Unsubscribe all observers and release resources.
+ /// </summary>
+ this.isDisposed = true;
+ this.observers = null;
+ this.value = null;
+ this.exception = null;
+ }
+ });
+
+ return BehaviorSubject;
+ }());
+
+ // Replay Subject
+ var ReplaySubject = root.ReplaySubject = (function (base) {
+ var RemovableDisposable = function (subject, observer) {
+ this.subject = subject;
+ this.observer = observer;
+ };
+
+ RemovableDisposable.prototype.dispose = function () {
+ this.observer.dispose();
+ if (!this.subject.isDisposed) {
+ var idx = this.subject.observers.indexOf(this.observer);
+ this.subject.observers.splice(idx, 1);
+ }
+ };
+
+ function subscribe(observer) {
+ var so = new ScheduledObserver(this.scheduler, observer),
+ subscription = new RemovableDisposable(this, so);
+ checkDisposed.call(this);
+ this._trim(this.scheduler.now());
+ this.observers.push(so);
+
+ var n = this.q.length;
+
+ for (var i = 0, len = this.q.length; i < len; i++) {
+ so.onNext(this.q[i].value);
+ }
+
+ if (this.hasError) {
+ n++;
+ so.onError(this.error);
+ } else if (this.isStopped) {
+ n++;
+ so.onCompleted();
+ }
+
+ so.ensureActive(n);
+ return subscription;
+ }
+
+ inherits(ReplaySubject, Observable);
+
+ function ReplaySubject(bufferSize, window, scheduler) {
+ /// <summary>
+ /// Initializes a new instance of the ReplaySubject class with the specified buffer size, window and scheduler.
+ /// </summary>
+ /// <param name="bufferSize">[Optional] Maximum element count of the replay buffer. If not specified, defaults to Number.MAX_VALUE.</param>
+ /// <param name="window">[Optional] Maximum time length of the replay buffer. If not specified, defaults to Number.MAX_VALUE.</param>
+ /// <param name="scheduler">[Optional] Scheduler the observers are invoked on. If not specified, defaults to Scheduler.currentThread.</param>
+ this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
+ this.window = window == null ? Number.MAX_VALUE : window;
+ this.scheduler = scheduler || currentThreadScheduler;
+ this.q = [];
+ this.observers = [];
+ this.isStopped = false;
+ this.isDisposed = false;
+ this.hasError = false;
+ this.error = null;
+ ReplaySubject.super_.constructor.call(this, subscribe);
+ }
+
+ addProperties(ReplaySubject.prototype, Observer, {
+ _trim: function (now) {
+ while (this.q.length > this.bufferSize) {
+ this.q.shift();
+ }
+ while (this.q.length > 0 && (now - this.q[0].interval) > this.window) {
+ this.q.shift();
+ }
+ },
+ onNext: function (value) {
+ /// <summary>
+ /// Notifies all subscribed and future observers about the arrival of the specified element in the sequence.
+ /// </summary>
+ /// <param name="value">The value to send to all observers.</param>
+ var observer;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ var now = this.scheduler.now();
+ this.q.push({ interval: now, value: value });
+ this._trim(now);
+
+ var o = this.observers.slice(0);
+ for (var i = 0, len = o.length; i < len; i++) {
+ observer = o[i];
+ observer.onNext(value);
+ observer.ensureActive();
+ }
+ }
+ },
+ onError: function (error) {
+ /// <summary>
+ /// Notifies all subscribed and future observers about the specified exception.
+ /// </summary>
+ /// <param name="error">The exception to send to all observers.</param>
+ var observer;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.isStopped = true;
+ this.error = error;
+ this.hasError = true;
+ var now = this.scheduler.now();
+ this._trim(now);
+ var o = this.observers.slice(0);
+ for (var i = 0, len = o.length; i < len; i++) {
+ observer = o[i];
+ observer.onError(error);
+ observer.ensureActive();
+ }
+ this.observers = [];
+ }
+ },
+ onCompleted: function () {
+ /// <summary>
+ /// Notifies all subscribed and future observers about the end of the sequence.
+ /// </summary>
+ var observer;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.isStopped = true;
+ var now = this.scheduler.now();
+ this._trim(now);
+ var o = this.observers.slice(0);
+ for (var i = 0, len = o.length; i < len; i++) {
+ observer = o[i];
+ observer.onCompleted();
+ observer.ensureActive();
+ }
+ this.observers = [];
+ }
+ },
+ dispose: function () {
+ /// <summary>
+ /// Releases all resources used by the current instance of the ReplaySubject class and unsubscribe all observers.
+ /// </summary>
+ this.isDisposed = true;
+ this.observers = null;
+ }
+ });
+
+ return ReplaySubject;
+ }());
+
+ var ConnectableObservable = (function () {
+ inherits(ConnectableObservable, Observable);
+ function ConnectableObservable(source, subject) {
+ var state = {
+ subject: subject,
+ source: source.asObservable(),
+ hasSubscription: false,
+ subscription: null
+ };
+
+ this.connect = function () {
+ if (!state.hasSubscription) {
+ state.hasSubscription = true;
+ state.subscription = new CompositeDisposable(state.source.subscribe(state.subject), disposableCreate(function () {
+ state.hasSubscription = false;
+ }));
+ }
+ return state.subscription;
+ };
+
+ var subscribe = function (observer) {
+ return state.subject.subscribe(observer);
+ };
+ ConnectableObservable.super_.constructor.call(this, subscribe);
+ }
+
+ ConnectableObservable.prototype.connect = function () { return this.connect(); };
+ ConnectableObservable.prototype.refCount = function () {
+ var connectableSubscription = null,
+ count = 0,
+ source = this;
+ return new AnonymousObservable(function (observer) {
+ var shouldConnect, subscription;
+ count++;
+ shouldConnect = count === 1;
+ subscription = source.subscribe(observer);
+ if (shouldConnect) {
+ connectableSubscription = source.connect();
+ }
+ return disposableCreate(function () {
+ subscription.dispose();
+ count--;
+ if (count === 0) {
+ connectableSubscription.dispose();
+ }
+ });
+ });
+ };
+
+ return ConnectableObservable;
+ }());
+
+ return root;
+}));
354 rx.binding.js
@@ -0,0 +1,354 @@
+/**
+* @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the Microsoft Reference Source License (MS-RSL).
+* http://referencesource.microsoft.com/referencesourcelicense.aspx.
+*/
+
+(function (root, factory) {
+ var freeExports = typeof exports == 'object' && exports &&
+ (typeof root == 'object' && root && root == root.global && (window = root), exports);
+
+ // Because of build optimizers
+ if (typeof define === 'function' && define.amd) {
+ define(['rx', 'exports'], function (Rx, exports) {
+ root.Rx = factory(root, exports, Rx);
+ return root.Rx;
+ });
+ } else if (typeof module == 'object' && module && module.exports == freeExports) {
+ module.exports = factory(root, module.exports, require('./rx'));
+ } else {
+ root.Rx = factory(root, {}, root.Rx);
+ }
+}(this, function (global, exp, root, undefined) {
+
+ var Observable = root.Observable,
+ observableProto = Observable.prototype,
+ AnonymousObservable = root.Internals.AnonymousObservable,
+ Subject = root.Subject,
+ AsyncSubject = root.AsyncSubject,
+ Observer = root.Observer,
+ ScheduledObserver = root.Internals.ScheduledObserver,
+ disposableCreate = root.Disposable.create,
+ disposableEmpty = root.Disposable.empty,
+ CompositeDisposable = root.CompositeDisposable,
+ currentThreadScheduler = root.Scheduler.currentThread,
+ inherits = root.Internals.inherits,
+ addProperties = root.Internals.addProperties;
+
+ // Utilities
+ var objectDisposed = 'Object has been disposed';
+ function checkDisposed() {
+ if (this.isDisposed) {
+ throw new Error(objectDisposed);
+ }
+ }
+
+ observableProto.multicast = function (subjectOrSubjectSelector, selector) {
+ var source = this;
+ return typeof subjectOrSubjectSelector === 'function' ?
+ new AnonymousObservable(function (observer) {
+ var connectable = source.multicast(subjectOrSubjectSelector());
+ return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
+ }) :
+ new ConnectableObservable(source, subjectOrSubjectSelector);
+ };
+
+ observableProto.publish = function (selector) {
+ return !selector ?
+ this.multicast(new Subject()) :
+ this.multicast(function () {
+ return new Subject();
+ }, selector);
+ };
+
+ observableProto.publishLast = function (selector) {
+ return !selector ?
+ this.multicast(new AsyncSubject()) :
+ this.multicast(function () {
+ return new AsyncSubject();
+ }, selector);
+ };
+
+ observableProto.publishValue = function (initialValueOrSelector, initialValue) {
+ return arguments.length === 2 ?
+ this.multicast(function () {
+ return new BehaviorSubject(initialValue);
+ }, initialValueOrSelector) :
+ this.multicast(new BehaviorSubject(initialValueOrSelector));
+ };
+
+ observableProto.replay = function (selector, bufferSize, window, scheduler) {
+ return !selector ?
+ this.multicast(new ReplaySubject(bufferSize, window, scheduler)) :
+ this.multicast(function () {
+ return new ReplaySubject(bufferSize, window, scheduler);
+ }, selector);
+ };
+
+ var InnerSubscription = function (subject, observer) {
+ this.subject = subject;
+ this.observer = observer;
+ };
+ InnerSubscription.prototype.dispose = function () {
+ if (!this.subject.isDisposed && this.observer !== null) {
+ var idx = this.subject.observers.indexOf(this.observer);
+ this.subject.observers.splice(idx, 1);
+ this.observer = null;
+ }
+ };
+
+ var BehaviorSubject = root.BehaviorSubject = (function () {
+ function subscribe(observer) {
+ var ex;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.observers.push(observer);
+ observer.onNext(this.value);
+ return new InnerSubscription(this, observer);
+ }
+ ex = this.exception;
+ if (ex) {
+ observer.onError(ex);
+ } else {
+ observer.onCompleted();
+ }
+ return disposableEmpty;
+ }
+
+ inherits(BehaviorSubject, Observable);
+ function BehaviorSubject(value) {
+ BehaviorSubject.super_.constructor.call(this, subscribe);
+
+ this.value = value,
+ this.observers = [],
+ this.isDisposed = false,
+ this.isStopped = false,
+ this.exception = null;
+ }
+
+ addProperties(BehaviorSubject.prototype, Observer, {
+ onCompleted: function () {
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ var os = this.observers.slice(0);
+ this.isStopped = true;
+ for (var i = 0, len = os.length; i < len; i++) {
+ os[i].onCompleted();
+ }
+
+ this.observers = [];
+ }
+ },
+ onError: function (error) {
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ var os = this.observers.slice(0);
+ this.isStopped = true;
+ this.exception = error;
+
+ for (var i = 0, len = os.length; i < len; i++) {
+ os[i].onError(error);
+ }
+
+ this.observers = [];
+ }
+ },
+ onNext: function (value) {
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.value = value;
+ var os = this.observers.slice(0);
+ for (var i = 0, len = os.length; i < len; i++) {
+ os[i].onNext(value);
+ }
+ }
+ },
+ dispose: function () {
+ this.isDisposed = true;
+ this.observers = null;
+ this.value = null;
+ this.exception = null;
+ }
+ });
+
+ return BehaviorSubject;
+ }());
+
+ // Replay Subject
+ var ReplaySubject = root.ReplaySubject = (function (base) {
+ var RemovableDisposable = function (subject, observer) {
+ this.subject = subject;
+ this.observer = observer;
+ };
+
+ RemovableDisposable.prototype.dispose = function () {
+ this.observer.dispose();
+ if (!this.subject.isDisposed) {
+ var idx = this.subject.observers.indexOf(this.observer);
+ this.subject.observers.splice(idx, 1);
+ }
+ };
+
+ function subscribe(observer) {
+ var so = new ScheduledObserver(this.scheduler, observer),
+ subscription = new RemovableDisposable(this, so);
+ checkDisposed.call(this);
+ this._trim(this.scheduler.now());
+ this.observers.push(so);
+
+ var n = this.q.length;
+
+ for (var i = 0, len = this.q.length; i < len; i++) {
+ so.onNext(this.q[i].value);
+ }
+
+ if (this.hasError) {
+ n++;
+ so.onError(this.error);
+ } else if (this.isStopped) {
+ n++;
+ so.onCompleted();
+ }
+
+ so.ensureActive(n);
+ return subscription;
+ }
+
+ inherits(ReplaySubject, Observable);
+
+ function ReplaySubject(bufferSize, window, scheduler) {
+ this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
+ this.window = window == null ? Number.MAX_VALUE : window;
+ this.scheduler = scheduler || currentThreadScheduler;
+ this.q = [];
+ this.observers = [];
+ this.isStopped = false;
+ this.isDisposed = false;
+ this.hasError = false;
+ this.error = null;
+ ReplaySubject.super_.constructor.call(this, subscribe);
+ }
+
+ addProperties(ReplaySubject.prototype, Observer, {
+ _trim: function (now) {
+ while (this.q.length > this.bufferSize) {
+ this.q.shift();
+ }
+ while (this.q.length > 0 && (now - this.q[0].interval) > this.window) {
+ this.q.shift();
+ }
+ },
+ onNext: function (value) {
+ var observer;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ var now = this.scheduler.now();
+ this.q.push({ interval: now, value: value });
+ this._trim(now);
+
+ var o = this.observers.slice(0);
+ for (var i = 0, len = o.length; i < len; i++) {
+ observer = o[i];
+ observer.onNext(value);
+ observer.ensureActive();
+ }
+ }
+ },
+ onError: function (error) {
+ var observer;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.isStopped = true;
+ this.error = error;
+ this.hasError = true;
+ var now = this.scheduler.now();
+ this._trim(now);
+ var o = this.observers.slice(0);
+ for (var i = 0, len = o.length; i < len; i++) {
+ observer = o[i];
+ observer.onError(error);
+ observer.ensureActive();
+ }
+ this.observers = [];
+ }
+ },
+ onCompleted: function () {
+ var observer;
+ checkDisposed.call(this);
+ if (!this.isStopped) {
+ this.isStopped = true;
+ var now = this.scheduler.now();
+ this._trim(now);
+ var o = this.observers.slice(0);
+ for (var i = 0, len = o.length; i < len; i++) {
+ observer = o[i];
+ observer.onCompleted();
+ observer.ensureActive();
+ }
+ this.observers = [];
+ }
+ },
+ dispose: function () {
+ this.isDisposed = true;
+ this.observers = null;
+ }
+ });
+
+ return ReplaySubject;
+ }());
+
+ var ConnectableObservable = (function () {
+ inherits(ConnectableObservable, Observable);
+ function ConnectableObservable(source, subject) {
+ var state = {
+ subject: subject,
+ source: source.asObservable(),
+ hasSubscription: false,
+ subscription: null
+ };
+
+ this.connect = function () {
+ if (!state.hasSubscription) {
+ state.hasSubscription = true;
+ state.subscription = new CompositeDisposable(state.source.subscribe(state.subject), disposableCreate(function () {
+ state.hasSubscription = false;
+ }));
+ }
+ return state.subscription;
+ };
+
+ var subscribe = function (observer) {
+ return state.subject.subscribe(observer);
+ };
+ ConnectableObservable.super_.constructor.call(this, subscribe);
+ }
+
+ ConnectableObservable.prototype.connect = function () { return this.connect(); };
+ ConnectableObservable.prototype.refCount = function () {
+ var connectableSubscription = null,
+ count = 0,
+ source = this;
+ return new AnonymousObservable(function (observer) {
+ var shouldConnect, subscription;
+ count++;
+ shouldConnect = count === 1;
+ subscription = source.subscribe(observer);
+ if (shouldConnect) {
+ connectableSubscription = source.connect();
+ }
+ return disposableCreate(function () {
+ subscription.dispose();
+ count--;
+ if (count === 0) {
+ connectableSubscription.dispose();
+ }
+ });
+ });
+ };
+
+ return ConnectableObservable;
+ }());
+
+ return root;
+}));
6 rx.binding.min.js
@@ -0,0 +1,6 @@
+/*** @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the MICROSOFT REACTIVE EXTENSIONS FOR JAVASCRIPT AND .NET LIBRARIES License.
+* See http://go.microsoft.com/fwlink/?LinkID=220762.
+*/
+(function(e,t){var n=typeof exports=="object"&&exports&&(typeof e=="object"&&e&&e==e.global&&(window=e),exports);typeof define=="function"&&define.amd?define(["rx","exports"],function(n,r){return e.Rx=t(e,r,n),e.Rx}):typeof module=="object"&&module&&module.exports==n?module.exports=t(e,module.exports,require("./rx")):e.Rx=t(e,{},e.Rx)})(this,function(e,t,n,r){function y(){if(this.isDisposed)throw new Error(g)}var i=n.Observable,s=i.prototype,o=n.Internals.AnonymousObservable,u=n.Subject,a=n.AsyncSubject,f=n.Observer,l=n.Internals.ScheduledObserver,c=n.Disposable.create,h=n.Disposable.empty,p=n.CompositeDisposable,d=n.Scheduler.currentThread,v=n.Internals.inherits,m=n.Internals.addProperties,g="Object has been disposed";s.multicast=function(e,t){var n=this;return typeof e=="function"?new o(function(r){var i=n.multicast(e());return new p(t(i).subscribe(r),i.connect())}):new S(n,e)},s.publish=function(e){return e?this.multicast(function(){return new u},e):this.multicast(new u)},s.publishLast=function(e){return e?this.multicast(function(){return new a},e):this.multicast(new a)},s.publishValue=function(e,t){return arguments.length===2?this.multicast(function(){return new w(t)},e):this.multicast(new w(e))},s.replay=function(e,t,n,r){return e?this.multicast(function(){return new E(t,n,r)},e):this.multicast(new E(t,n,r))};var b=function(e,t){this.subject=e,this.observer=t};b.prototype.dispose=function(){if(!this.subject.isDisposed&&this.observer!==null){var e=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(e,1),this.observer=null}};var w=n.BehaviorSubject=function(){function e(e){var t;return y.call(this),this.isStopped?(t=this.exception,t?e.onError(t):e.onCompleted(),h):(this.observers.push(e),e.onNext(this.value),new b(this,e))}function t(n){t.super_.constructor.call(this,e),this.value=n,this.observers=[],this.isDisposed=!1,this.isStopped=!1,this.exception=null}return v(t,i),m(t.prototype,f,{onCompleted:function(){y.call(this);if(!this.isStopped){var e=this.observers.slice(0);this.isStopped=!0;for(var t=0,n=e.length;t<n;t++)e[t].onCompleted();this.observers=[]}},onError:function(e){y.call(this);if(!this.isStopped){var t=this.observers.slice(0);this.isStopped=!0,this.exception=e;for(var n=0,r=t.length;n<r;n++)t[n].onError(e);this.observers=[]}},onNext:function(e){y.call(this);if(!this.isStopped){this.value=e;var t=this.observers.slice(0);for(var n=0,r=t.length;n<r;n++)t[n].onNext(e)}},dispose:function(){this.isDisposed=!0,this.observers=null,this.value=null,this.exception=null}}),t}(),E=n.ReplaySubject=function(e){function n(e){var n=new l(this.scheduler,e),r=new t(this,n);y.call(this),this._trim(this.scheduler.now()),this.observers.push(n);var i=this.q.length;for(var s=0,o=this.q.length;s<o;s++)n.onNext(this.q[s].value);return this.hasError?(i++,n.onError(this.error)):this.isStopped&&(i++,n.onCompleted()),n.ensureActive(i),r}function r(e,t,i){this.bufferSize=e==null?Number.MAX_VALUE:e,this.window=t==null?Number.MAX_VALUE:t,this.scheduler=i||d,this.q=[],this.observers=[],this.isStopped=!1,this.isDisposed=!1,this.hasError=!1,this.error=null,r.super_.constructor.call(this,n)}var t=function(e,t){this.subject=e,this.observer=t};return t.prototype.dispose=function(){this.observer.dispose();if(!this.subject.isDisposed){var e=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(e,1)}},v(r,i),m(r.prototype,f,{_trim:function(e){while(this.q.length>this.bufferSize)this.q.shift();while(this.q.length>0&&e-this.q[0].interval>this.window)this.q.shift()},onNext:function(e){var t;y.call(this);if(!this.isStopped){var n=this.scheduler.now();this.q.push({interval:n,value:e}),this._trim(n);var r=this.observers.slice(0);for(var i=0,s=r.length;i<s;i++)t=r[i],t.onNext(e),t.ensureActive()}},onError:function(e){var t;y.call(this);if(!this.isStopped){this.isStopped=!0,this.error=e,this.hasError=!0;var n=this.scheduler.now();this._trim(n);var r=this.observers.slice(0);for(var i=0,s=r.length;i<s;i++)t=r[i],t.onError(e),t.ensureActive();this.observers=[]}},onCompleted:function(){var e;y.call(this);if(!this.isStopped){this.isStopped=!0;var t=this.scheduler.now();this._trim(t);var n=this.observers.slice(0);for(var r=0,i=n.length;r<i;r++)e=n[r],e.onCompleted(),e.ensureActive();this.observers=[]}},dispose:function(){this.isDisposed=!0,this.observers=null}}),r}(),S=function(){function e(t,n){var r={subject:n,source:t.asObservable(),hasSubscription:!1,subscription:null};this.connect=function(){return r.hasSubscription||(r.hasSubscription=!0,r.subscription=new p(r.source.subscribe(r.subject),c(function(){r.hasSubscription=!1}))),r.subscription};var i=function(e){return r.subject.subscribe(e)};e.super_.constructor.call(this,i)}return v(e,i),e.prototype.connect=function(){return this.connect()},e.prototype.refCount=function(){var e=null,t=0,n=this;return new o(function(r){var i,s;return t++,i=t===1,s=n.subscribe(r),i&&(e=n.connect()),c(function(){s.dispose(),t--,t===0&&e.dispose()})})},e}();return n});
586 rx.coincidence-vsdoc.js
@@ -0,0 +1,586 @@
+/**
+* @preserve Copyright (c) Microsoft Corporation. All rights reserved.
+* This code is licensed by Microsoft Corporation under the terms
+* of the Microsoft Reference Source License (MS-RSL).
+* http://referencesource.microsoft.com/referencesourcelicense.aspx.
+*/
+
+(function (root, factory) {
+ var freeExports = typeof exports == 'object' && exports &&
+ (typeof root == 'object' && root && root == root.global && (window = root), exports);
+
+ // Because of build optimizers
+ if (typeof define === 'function' && define.amd) {
+ define(['rx', 'exports'], function (Rx, exports) {
+ root.Rx = factory(root, exports, Rx);
+ return root.Rx;
+ });
+ } else if (typeof module == 'object' && module && module.exports == freeExports) {
+ module.exports = factory(root, module.exports, require('./rx'));
+ } else {
+ root.Rx = factory(root, {}, root.Rx);
+ }
+}(this, function (global, exp, root, undefined) {
+
+ var Observable = root.Observable,
+ CompositeDisposable = root.CompositeDisposable,
+ RefCountDisposable = root.RefCountDisposable,
+ SingleAssignmentDisposable = root.SingleAssignmentDisposable,
+ SerialDisposable = root.SerialDisposable,
+ Subject = root.Subject,
+ observableProto = Observable.prototype,
+ observableEmpty = Observable.empty,
+ AnonymousObservable = root.Internals.AnonymousObservable,
+ observerCreate = root.Observer.create,
+ addRef = root.Internals.addRef;
+
+ // defaults
+ function noop() { }
+ function defaultComparer(x, y) { return x === y; }
+
+ // Real Dictionary
+ var primes = [1, 3, 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071, 262139, 524287, 1048573, 2097143, 4194301, 8388593, 16777213, 33554393, 67108859, 134217689, 268435399, 536870909, 1073741789, 2147483647];
+ var noSuchkey = "no such key";
+ var duplicatekey = "duplicate key";
+
+ function isPrime(candidate) {
+ var num1, num2;
+ if (candidate & 1 === 0) {
+ return candidate === 2;
+ }
+ num1 = Math.sqrt(candidate);
+ num2 = 3;
+ while (num2 <= num1) {
+ if (candidate % num2 === 0) {
+ return false;
+ }
+ num2 += 2;
+ }
+ return true;
+ }
+
+ function getPrime(min) {
+ var index, num, candidate;
+ for (index = 0; index < primes.length; ++index) {
+ num = primes[index];
+ if (num >= min) {
+ return num;
+ }
+ }
+ candidate = min | 1;
+ while (candidate < primes[primes.length - 1]) {
+ if (isPrime(candidate)) {
+ return candidate;
+ }
+ candidate += 2;
+ }
+ return min;
+ }
+
+ var getHashCode = (function () {
+ var uniqueIdCounter = 0;
+
+ return function (obj) {
+ var id;
+ if (obj === undefined)
+ throw new Error(noSuchkey);
+ if (obj.getHashCode !== undefined) {
+ return obj.getHashCode();
+ }
+ id = 17 * uniqueIdCounter++;
+ obj.getHashCode = function () { return id; };
+ return id;
+ };
+ } ());
+
+ function newEntry() {
+ return { key: null, value: null, next: 0, hashCode: 0 };
+ }
+
+ // Dictionary implementation
+
+ var Dictionary = function (capacity, comparer) {
+ this._initialize(capacity);
+ this.comparer = comparer || defaultComparer;
+ this.freeCount = 0;
+ this.size = 0;
+ this.freeList = -1;
+ };
+
+ Dictionary.prototype._initialize = function (capacity) {
+ var prime = getPrime(capacity), i;
+ this.buckets = new Array(prime);
+ this.entries = new Array(prime);
+ for (i = 0; i < prime; i++) {
+ this.buckets[i] = -1;
+ this.entries[i] = newEntry();
+ }
+ this.freeList = -1;
+ };
+ Dictionary.prototype.count = function () {
+ return this.size;
+ };
+ Dictionary.prototype.add = function (key, value) {
+ return this._insert(key, value, true);
+ };
+ Dictionary.prototype._insert = function (key, value, add) {
+ if (this.buckets === undefined) {
+ this._initialize(0);
+ }
+ var num = getHashCode(key) & 2147483647;
+ var index1 = num % this.buckets.length;
+ for (var index2 = this.buckets[index1]; index2 >= 0; index2 = this.entries[index2].next) {
+ if (this.entries[index2].hashCode === num && this.comparer(this.entries[index2].key, key)) {
+ if (add) {
+ throw duplicatekey;
+ }
+ this.entries[index2].value = value;
+ return;
+ }
+ }
+ if (this.freeCount > 0) {
+ var index3 = this.freeList;
+ this.freeList = this.entries[index3].next;
+ --this.freeCount;
+ } else {
+ if (this.size === this.entries.length) {
+ this._resize();
+ index1 = num % this.buckets.length;
+ }
+ index3 = this.size;
+ ++this.size;
+ }
+ this.entries[index3].hashCode = num;
+ this.entries[index3].next = this.buckets[index1];
+ this.entries[index3].key = key;
+ this.entries[index3].value = value;
+ this.buckets[index1] = index3;
+ };
+ Dictionary.prototype._resize = function () {
+ var prime = getPrime(this.size * 2);
+ var numArray = new Array(prime);
+ for (index = 0; index < numArray.length; ++index) {
+ numArray[index] = -1;
+ }
+ var entryArray = new Array(prime);
+ for (index = 0; index < this.size; ++index) {
+ entryArray[index] = this.entries[index];
+ }
+ for (var index = this.size; index < prime; ++index) {
+ entryArray[index] = newEntry();
+ }
+ for (var index1 = 0; index1 < this.size; ++index1) {
+ var index2 = entryArray[index1].hashCode % prime;
+ entryArray[index1].next = numArray[index2];
+ numArray[index2] = index1;
+ }
+ this.buckets = numArray;
+ this.entries = entryArray;
+ };
+ Dictionary.prototype.remove = function (key) {
+ if (this.buckets !== undefined) {
+ var num = getHashCode(key) & 2147483647;
+ var index1 = num % this.buckets.length;
+ var index2 = -1;
+ for (var index3 = this.buckets[index1]; index3 >= 0; index3 = this.entries[index3].next) {
+ if (this.entries[index3].hashCode === num && this.comparer(this.entries[index3].key, key)) {
+ if (index2 < 0) {
+ this.buckets[index1] = this.entries[index3].next;
+ } else {
+ this.entries[index2].next = this.entries[index3].next;
+ }
+ this.entries[index3].hashCode = -1;
+ this.entries[index3].next = this.freeList;
+ this.entries[index3].key = null;
+ this.entries[index3].value = null;
+ this.freeList = index3;
+ ++this.freeCount;
+ return true;
+ } else {
+ index2 = index3;
+ }
+ }
+ }
+ return false;
+ };
+ Dictionary.prototype.clear = function () {
+ var index, len;
+ if (this.size <= 0) {
+ return;
+ }
+ for (index = 0, len = this.buckets.length; index < len; ++index) {
+ this.buckets[index] = -1;
+ }
+ for (index = 0; index < this.size; ++index) {
+ this.entries[index] = newEntry();
+ }
+ this.freeList = -1;
+ this.size = 0;
+ };
+ Dictionary.prototype._findEntry = function (key) {
+ if (this.buckets !== undefined) {
+ var num = getHashCode(key) & 2147483647;
+ for (var index = this.buckets[num % this.buckets.length]; index >= 0; index = this.entries[index].next) {
+ if (this.entries[index].hashCode === num && this.comparer(this.entries[index].key, key)) {
+ return index;
+ }
+ }
+ }
+ return -1;
+ };
+ Dictionary.prototype.count = function () {
+ return this.size - this.freeCount;
+ };
+ Dictionary.prototype.tryGetEntry = function (key) {
+ var entry = this._findEntry(key);
+ if (entry >= 0) {