├── .gitignore ├── README.md ├── project.clj ├── resources └── private │ ├── js │ ├── rx.aggregates.min.js │ ├── rx.binding.min.js │ ├── rx.coincidence.min.js │ ├── rx.html.min.js │ ├── rx.jquery.min.js │ ├── rx.min.js │ ├── rx.modern.min.js │ └── rx.time.min.js │ └── unit-test.html ├── runners └── phantomjs.js ├── src-cljs └── rx_cljs │ └── observable.cljs └── test-cljs └── rx_cljs └── observable_test.cljs /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | resources/public/js/main.js 3 | resources/public/js/test.js 4 | .lein-repl-history 5 | pom.xml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rx-cljs 2 | 3 | A ClojureScript wrapper for [Reactive Extensions (Rx) for Javascript](https://github.com/Reactive-Extensions/RxJS). 4 | 5 | 6 | ## Motivation 7 | 8 | The aim of this wrapper is to let developers write this: 9 | 10 | ```clojure 11 | (defn project-range [n] 12 | (return-value (range n))) 13 | 14 | (-> (from-array [4 6 8]) 15 | (select-many project-range) 16 | (subscribe #(.log js/console (clj->js %)))) 17 | ``` 18 | 19 | Instead of: 20 | 21 | ```clojure 22 | (defn project-range [n] (.returnValue js/Rx.Observable (range n))) (-> (.fromArray js/Rx.Observable (clj->js [1 2 3])) (.selectMany project-range) (.subscribe #(.log js/console (clj->js %)))) 23 | ``` 24 | 25 | ## Usage 26 | 27 | **Be warned**: it's very early days and this wrapper is still very much incomplete. 28 | 29 | For the brave amongst you, add this to your `project.clj`: 30 | 31 | ```clojure 32 | [com.leonardoborges/rx-cljs "0.0.2-SNAPSHOT"] 33 | ``` 34 | 35 | Or if you're using maven: 36 | 37 | ```xml 38 | 39 | com.leonardoborges 40 | rx-cljs 41 | 0.0.2-SNAPSHOT 42 | 43 | ``` 44 | 45 | For a sample app that uses this wrapper, check out this [repository](https://github.com/leonardoborges/frp-code). 46 | 47 | 48 | ## What's in the package 49 | 50 | ### Creating observables 51 | 52 | - create 53 | - return-value 54 | - from-array 55 | - interval 56 | 57 | ### Working with Observables 58 | 59 | - take 60 | - map 61 | - reduce 62 | - skip 63 | - zip 64 | - select-many 65 | - subscribe 66 | - start-with 67 | - buffer-with-count 68 | 69 | ### Working with Connectable observables 70 | 71 | - publish 72 | - connect 73 | - ref-count 74 | 75 | ### Working with Observers 76 | 77 | - on-next 78 | - on-completed 79 | 80 | ### Working with Subscriptions 81 | 82 | - dispose 83 | 84 | ## Running the tests 85 | 86 | From the project root: 87 | 88 | ```bash 89 | $ lein cljsbuild test 90 | ``` 91 | 92 | ## TODO 93 | 94 | Everything else. (but mainly other arities of functions already in here.) 95 | 96 | ## Contributing 97 | 98 | Bug reports and pull requests are much welcome. If submitting code, please add a test to it. 99 | 100 | ## License 101 | 102 | Copyright (C) 2013 [Leonardo Borges](http://www.leonardoborges.com) 103 | 104 | Distributed under the Eclipse Public License, the same as Clojure. -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject com.leonardoborges/rx-cljs "0.0.2-SNAPSHOT" 2 | :description "A ClojureScript wrapper for RxJS" 3 | :url "http://github.com/leonardoborges/rx-cljs" 4 | :source-paths ["src-clj"] 5 | :dependencies [[org.clojure/clojure "1.5.1"]] 6 | :plugins [[lein-cljsbuild "0.3.2"]] 7 | :profiles {:dev 8 | {:dependencies [[com.cemerick/clojurescript.test "0.0.4"] 9 | [org.bodil/error "0.1.2"]]}} 10 | :hooks [leiningen.cljsbuild] 11 | :cljsbuild { 12 | :builds {:dev {:source-paths ["src-cljs"] 13 | :compiler {:output-to "resources/public/js/main.js" 14 | :optimizations :whitespace 15 | :pretty-print true} 16 | :jar true} 17 | :test {:source-paths ["src-cljs" "test-cljs"] 18 | :compiler {:output-to "resources/public/js/test.js" 19 | :optimizations :whitespace 20 | :pretty-print true}}} 21 | :test-commands {"unit-tests" ["runners/phantomjs.js" 22 | "resources/private/js/rx.min.js" 23 | "resources/private/js/rx.modern.min.js" 24 | "resources/private/js/rx.binding.min.js" 25 | "resources/private/js/rx.time.min.js" 26 | "resources/private/js/rx.aggregates.min.js" 27 | "resources/private/js/rx.coincidence.min.js" 28 | "resources/public/js/test.js"]}}) 29 | -------------------------------------------------------------------------------- /resources/private/js/rx.aggregates.min.js: -------------------------------------------------------------------------------- 1 | (function(t,e){var n="object"==typeof exports&&exports,r=("object"==typeof module&&module&&module.exports==n&&module,"object"==typeof global&&global);r.global===r&&(window=r),"function"==typeof define&&define.amd?define(["rx","exports"],function(n,r){return t.Rx=e(t,r,n),t.Rx}):"object"==typeof module&&module&&module.exports===n?module.exports=e(t,module.exports,require("./rx")):t.Rx=e(t,{},t.Rx)})(this,function(t,e,n,r){function i(t,e){return t===e}function o(t){return t}function s(t,e){return t>e?1:t===e?0:-1}function u(t,e,n){return new y(function(i){var o=!1,s=null,u=[];return t.subscribe(function(t){var c,a;try{a=e(t)}catch(h){return i.onError(h),r}if(c=0,o)try{c=n(a,s)}catch(l){return i.onError(l),r}else o=!0,s=a;c>0&&(s=a,u=[]),c>=0&&u.push(t)},i.onError.bind(i),function(){i.onNext(u),i.onCompleted()})})}function c(t){if(0===t.length)throw Error(g);return t[0]}function a(t,e,n){return new y(function(i){var o=0,s=e.length;return t.subscribe(function(t){var u=!1;try{s>o&&(u=n(t,e[o++]))}catch(c){return i.onError(c),r}u||(i.onNext(!1),i.onCompleted())},i.onError.bind(i),function(){i.onNext(o===s),i.onCompleted()})})}function h(t,e,n,r){if(0>e)throw Error(w);return new y(function(i){var o=e;return t.subscribe(function(t){0===o&&(i.onNext(t),i.onCompleted()),o--},i.onError.bind(i),function(){n?(i.onNext(r),i.onCompleted()):i.onError(Error(w))})})}function l(t,e,n){return new y(function(r){var i=n,o=!1;return t.subscribe(function(t){o?r.onError(Error("Sequence contains more than one element")):(i=t,o=!0)},r.onError.bind(r),function(){o||e?(r.onNext(i),r.onCompleted()):r.onError(Error(g))})})}function f(t,e,n){return new y(function(r){return t.subscribe(function(t){r.onNext(t),r.onCompleted()},r.onError.bind(r),function(){e?(r.onNext(n),r.onCompleted()):r.onError(Error(g))})})}function p(t,e,n){return new y(function(r){var i=n,o=!1;return t.subscribe(function(t){i=t,o=!0},r.onError.bind(r),function(){o||e?(r.onNext(i),r.onCompleted()):r.onError(Error(g))})})}function d(t,e,n,i){return new y(function(o){var s=0;return t.subscribe(function(u){var c;try{c=e.call(n,u,s,t)}catch(a){return o.onError(a),r}c?(o.onNext(i?s:u),o.onCompleted()):s++},o.onError.bind(o),function(){o.onNext(i?-1:r),o.onCompleted()})})}var b=n.Observable,v=b.prototype,m=n.CompositeDisposable,y=n.Internals.AnonymousObservable,w="Argument out of range",g="Sequence contains no elements.";return v.aggregate=function(){var t,e,n;return 2===arguments.length?(t=arguments[0],e=!0,n=arguments[1]):n=arguments[0],e?this.scan(t,n).startWith(t).finalValue():this.scan(n).finalValue()},v.reduce=function(){var t,e,n=arguments[0];return 2===arguments.length&&(e=!0,t=arguments[1]),e?this.scan(t,n).startWith(t).finalValue():this.scan(n).finalValue()},v.any=function(t,e){var n=this;return t?n.where(t,e).any():new y(function(t){return n.subscribe(function(){t.onNext(!0),t.onCompleted()},t.onError.bind(t),function(){t.onNext(!1),t.onCompleted()})})},v.some=v.any,v.isEmpty=function(){return this.any().select(function(t){return!t})},v.all=function(t,e){return this.where(function(e){return!t(e)},e).any().select(function(t){return!t})},v.every=v.all,v.contains=function(t,e){return e||(e=i),this.where(function(n){return e(n,t)}).any()},v.count=function(t){return t?this.where(t).count():this.aggregate(0,function(t){return t+1})},v.sum=function(t){return t?this.select(t).sum():this.aggregate(0,function(t,e){return t+e})},v.minBy=function(t,e){return e||(e=s),u(this,t,function(t,n){return-1*e(t,n)})},v.min=function(t){return this.minBy(o,t).select(function(t){return c(t)})},v.maxBy=function(t,e){return e||(e=s),u(this,t,e)},v.max=function(t){return this.maxBy(o,t).select(function(t){return c(t)})},v.average=function(t){return t?this.select(t).average():this.scan({sum:0,count:0},function(t,e){return{sum:t.sum+e,count:t.count+1}}).finalValue().select(function(t){return t.sum/t.count})},v.sequenceEqual=function(t,e){var n=this;return e||(e=i),Array.isArray(t)?a(n,t,e):new y(function(i){var o=!1,s=!1,u=[],c=[],a=n.subscribe(function(t){var n,o;if(c.length>0){o=c.shift();try{n=e(o,t)}catch(a){return i.onError(a),r}n||(i.onNext(!1),i.onCompleted())}else s?(i.onNext(!1),i.onCompleted()):u.push(t)},i.onError.bind(i),function(){o=!0,0===u.length&&(c.length>0?(i.onNext(!1),i.onCompleted()):s&&(i.onNext(!0),i.onCompleted()))}),h=t.subscribe(function(t){var n,s;if(u.length>0){s=u.shift();try{n=e(s,t)}catch(a){return i.onError(a),r}n||(i.onNext(!1),i.onCompleted())}else o?(i.onNext(!1),i.onCompleted()):c.push(t)},i.onError.bind(i),function(){s=!0,0===c.length&&(u.length>0?(i.onNext(!1),i.onCompleted()):o&&(i.onNext(!0),i.onCompleted()))});return new m(a,h)})},v.elementAt=function(t){return h(this,t,!1)},v.elementAtOrDefault=function(t,e){return h(this,t,!0,e)},v.single=function(t){return t?this.where(t).single():l(this,!1)},v.singleOrDefault=function(t,e){return t?this.where(t).singleOrDefault(null,e):l(this,!0,e)},v.first=function(t){return t?this.where(t).first():f(this,!1)},v.firstOrDefault=function(t,e){return t?this.where(t).firstOrDefault(null,e):f(this,!0,e)},v.last=function(t){return t?this.where(t).last():p(this,!1)},v.lastOrDefault=function(t,e){return t?this.where(t).lastOrDefault(null,e):p(this,!0,e)},v.find=function(t){return d(this,t,arguments[1],!1)},v.findIndex=function(t){return d(this,t,arguments[1],!0)},n}); -------------------------------------------------------------------------------- /resources/private/js/rx.binding.min.js: -------------------------------------------------------------------------------- 1 | (function(t,e){var n="object"==typeof exports&&exports,r=("object"==typeof module&&module&&module.exports==n&&module,"object"==typeof global&&global);r.global===r&&(window=r),"function"==typeof define&&define.amd?define(["rx","exports"],function(n,r){return t.Rx=e(t,r,n),t.Rx}):"object"==typeof module&&module&&module.exports===n?module.exports=e(t,module.exports,require("./rx")):t.Rx=e(t,{},t.Rx)})(this,function(t,e,n){function r(){if(this.isDisposed)throw Error(m)}var i=n.Observable,o=i.prototype,s=n.Internals.AnonymousObservable,u=n.Subject,c=n.AsyncSubject,a=n.Observer,h=n.Internals.ScheduledObserver,l=n.Disposable.create,f=n.Disposable.empty,p=n.CompositeDisposable,d=n.Scheduler.currentThread,b=n.Internals.inherits,v=n.Internals.addProperties,m="Object has been disposed";o.multicast=function(t,e){var n=this;return"function"==typeof t?new s(function(r){var i=n.multicast(t());return new p(e(i).subscribe(r),i.connect())}):new E(n,t)},o.publish=function(t){return t?this.multicast(function(){return new u},t):this.multicast(new u)},o.publishLast=function(t){return t?this.multicast(function(){return new c},t):this.multicast(new c)},o.publishValue=function(t,e){return 2===arguments.length?this.multicast(function(){return new w(e)},t):this.multicast(new w(t))},o.replay=function(t,e,n,r){return t?this.multicast(function(){return new g(e,n,r)},t):this.multicast(new g(e,n,r))};var y=function(t,e){this.subject=t,this.observer=e};y.prototype.dispose=function(){if(!this.subject.isDisposed&&null!==this.observer){var t=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(t,1),this.observer=null}};var w=n.BehaviorSubject=function(t){function e(t){var e;return r.call(this),this.isStopped?(e=this.exception,e?t.onError(e):t.onCompleted(),f):(this.observers.push(t),t.onNext(this.value),new y(this,t))}function n(n){t.call(this,e),this.value=n,this.observers=[],this.isDisposed=!1,this.isStopped=!1,this.exception=null}return b(n,t),v(n.prototype,a,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){if(r.call(this),!this.isStopped){var t=this.observers.slice(0);this.isStopped=!0;for(var e=0,n=t.length;n>e;e++)t[e].onCompleted();this.observers=[]}},onError:function(t){if(r.call(this),!this.isStopped){var e=this.observers.slice(0);this.isStopped=!0,this.exception=t;for(var n=0,i=e.length;i>n;n++)e[n].onError(t);this.observers=[]}},onNext:function(t){if(r.call(this),!this.isStopped){this.value=t;for(var e=this.observers.slice(0),n=0,i=e.length;i>n;n++)e[n].onNext(t)}},dispose:function(){this.isDisposed=!0,this.observers=null,this.value=null,this.exception=null}}),n}(i),g=n.ReplaySubject=function(t){function e(t){var e=new h(this.scheduler,t),n=new i(this,e);r.call(this),this._trim(this.scheduler.now()),this.observers.push(e);for(var o=this.q.length,s=0,u=this.q.length;u>s;s++)e.onNext(this.q[s].value);return this.hasError?(o++,e.onError(this.error)):this.isStopped&&(o++,e.onCompleted()),e.ensureActive(o),n}function n(n,r,i){this.bufferSize=null==n?Number.MAX_VALUE:n,this.window=null==r?Number.MAX_VALUE:r,this.scheduler=i||d,this.q=[],this.observers=[],this.isStopped=!1,this.isDisposed=!1,this.hasError=!1,this.error=null,t.call(this,e)}var i=function(t,e){this.subject=t,this.observer=e};return i.prototype.dispose=function(){if(this.observer.dispose(),!this.subject.isDisposed){var t=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(t,1)}},b(n,t),v(n.prototype,a,{hasObservers:function(){return this.observers.length>0},_trim:function(t){for(;this.q.length>this.bufferSize;)this.q.shift();for(;this.q.length>0&&t-this.q[0].interval>this.window;)this.q.shift()},onNext:function(t){var e;if(r.call(this),!this.isStopped){var n=this.scheduler.now();this.q.push({interval:n,value:t}),this._trim(n);for(var i=this.observers.slice(0),o=0,s=i.length;s>o;o++)e=i[o],e.onNext(t),e.ensureActive()}},onError:function(t){var e;if(r.call(this),!this.isStopped){this.isStopped=!0,this.error=t,this.hasError=!0;var n=this.scheduler.now();this._trim(n);for(var i=this.observers.slice(0),o=0,s=i.length;s>o;o++)e=i[o],e.onError(t),e.ensureActive();this.observers=[]}},onCompleted:function(){var t;if(r.call(this),!this.isStopped){this.isStopped=!0;var e=this.scheduler.now();this._trim(e);for(var n=this.observers.slice(0),i=0,o=n.length;o>i;i++)t=n[i],t.onCompleted(),t.ensureActive();this.observers=[]}},dispose:function(){this.isDisposed=!0,this.observers=null}}),n}(i),E=function(t){function e(e,n){function r(t){return i.subject.subscribe(t)}var i={subject:n,source:e.asObservable(),hasSubscription:!1,subscription:null};this.connect=function(){return i.hasSubscription||(i.hasSubscription=!0,i.subscription=new p(i.source.subscribe(i.subject),l(function(){i.hasSubscription=!1}))),i.subscription},t.call(this,r)}return b(e,t),e.prototype.connect=function(){return this.connect()},e.prototype.refCount=function(){var t=null,e=0,n=this;return new s(function(r){var i,o;return e++,i=1===e,o=n.subscribe(r),i&&(t=n.connect()),l(function(){o.dispose(),e--,0===e&&t.dispose()})})},e}(i);return n}); -------------------------------------------------------------------------------- /resources/private/js/rx.coincidence.min.js: -------------------------------------------------------------------------------- 1 | (function(t,e){var n="object"==typeof exports&&exports,r=("object"==typeof module&&module&&module.exports==n&&module,"object"==typeof global&&global);r.global===r&&(window=r),"function"==typeof define&&define.amd?define(["rx","exports"],function(n,r){return t.Rx=e(t,r,n),t.Rx}):"object"==typeof module&&module&&module.exports===n?module.exports=e(t,module.exports,require("./rx")):t.Rx=e(t,{},t.Rx)})(this,function(t,e,n,r){function i(){}function o(t,e){return t===e}function s(t){if(false&t)return 2===t;for(var e=Math.sqrt(t),n=3;e>=n;){if(0===t%n)return!1;n+=2}return!0}function u(t){var e,n,r;for(e=0;x.length>e;++e)if(n=x[e],n>=t)return n;for(r=1|t;x[x.length-1]>r;){if(s(r))return r;r+=2}return t}function c(){return{key:null,value:null,next:0,hashCode:0}}function a(t,e){return t.groupJoin(this,e,function(){return w()},function(t,e){return e})}function h(t){var e=this;return new g(function(n){var r=new m,i=new p,o=new d(i);return n.onNext(E(r,o)),i.add(e.subscribe(function(t){r.onNext(t)},function(t){r.onError(t),n.onError(t)},function(){r.onCompleted(),n.onCompleted()})),i.add(t.subscribe(function(){r.onCompleted(),r=new m,n.onNext(E(r,o))},function(t){r.onError(t),n.onError(t)},function(){r.onCompleted(),n.onCompleted()})),o})}function l(t){var e=this;return new g(function(n){var o,s=new v,u=new p(s),c=new d(u),a=new m;return n.onNext(E(a,c)),u.add(e.subscribe(function(t){a.onNext(t)},function(t){a.onError(t),n.onError(t)},function(){a.onCompleted(),n.onCompleted()})),o=function(){var e,u;try{u=t()}catch(h){return n.onError(h),r}e=new b,s.disposable(e),e.disposable(u.take(1).subscribe(i,function(t){a.onError(t),n.onError(t)},function(){a.onCompleted(),a=new m,n.onNext(E(a,c)),o()}))},o(),c})}var f=n.Observable,p=n.CompositeDisposable,d=n.RefCountDisposable,b=n.SingleAssignmentDisposable,v=n.SerialDisposable,m=n.Subject,y=f.prototype,w=f.empty,g=n.Internals.AnonymousObservable,E=(n.Observer.create,n.Internals.addRef),x=[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],C="no such key",D="duplicate key",A=function(){var t=0;return function(e){var n;if(null==e)throw Error(C);return e.getHashCode!==r?e.getHashCode():(n=17*t++,e.getHashCode=function(){return n},n)}}(),S=function(t,e){this._initialize(t),this.comparer=e||o,this.freeCount=0,this.size=0,this.freeList=-1};return S.prototype._initialize=function(t){var e,n=u(t);for(this.buckets=Array(n),this.entries=Array(n),e=0;n>e;e++)this.buckets[e]=-1,this.entries[e]=c();this.freeList=-1},S.prototype.count=function(){return this.size},S.prototype.add=function(t,e){return this._insert(t,e,!0)},S.prototype._insert=function(t,e,n){this.buckets||this._initialize(0);for(var i,o=2147483647&A(t),s=o%this.buckets.length,u=this.buckets[s];u>=0;u=this.entries[u].next)if(this.entries[u].hashCode===o&&this.comparer(this.entries[u].key,t)){if(n)throw D;return this.entries[u].value=e,r}this.freeCount>0?(i=this.freeList,this.freeList=this.entries[i].next,--this.freeCount):(this.size===this.entries.length&&(this._resize(),s=o%this.buckets.length),i=this.size,++this.size),this.entries[i].hashCode=o,this.entries[i].next=this.buckets[s],this.entries[i].key=t,this.entries[i].value=e,this.buckets[s]=i},S.prototype._resize=function(){var t=u(2*this.size),e=Array(t);for(r=0;e.length>r;++r)e[r]=-1;var n=Array(t);for(r=0;this.size>r;++r)n[r]=this.entries[r];for(var r=this.size;t>r;++r)n[r]=c();for(var i=0;this.size>i;++i){var o=n[i].hashCode%t;n[i].next=e[o],e[o]=i}this.buckets=e,this.entries=n},S.prototype.remove=function(t){if(this.buckets!==r)for(var e=2147483647&A(t),n=e%this.buckets.length,i=-1,o=this.buckets[n];o>=0;o=this.entries[o].next){if(this.entries[o].hashCode===e&&this.comparer(this.entries[o].key,t))return 0>i?this.buckets[n]=this.entries[o].next:this.entries[i].next=this.entries[o].next,this.entries[o].hashCode=-1,this.entries[o].next=this.freeList,this.entries[o].key=null,this.entries[o].value=null,this.freeList=o,++this.freeCount,!0;i=o}return!1},S.prototype.clear=function(){var t,e;if(!(0>=this.size)){for(t=0,e=this.buckets.length;e>t;++t)this.buckets[t]=-1;for(t=0;this.size>t;++t)this.entries[t]=c();this.freeList=-1,this.size=0}},S.prototype._findEntry=function(t){if(this.buckets!==r)for(var e=2147483647&A(t),n=this.buckets[e%this.buckets.length];n>=0;n=this.entries[n].next)if(this.entries[n].hashCode===e&&this.comparer(this.entries[n].key,t))return n;return-1},S.prototype.count=function(){return this.size-this.freeCount},S.prototype.tryGetEntry=function(t){var e=this._findEntry(t);return e>=0?{key:this.entries[e].key,value:this.entries[e].value}:r},S.prototype.getValues=function(){var t=0,e=[];if(this.entries!==r)for(var n=0;this.size>n;n++)this.entries[n].hashCode>=0&&(e[t++]=this.entries[n].value);return e},S.prototype.get=function(t){var e=this._findEntry(t);if(e>=0)return this.entries[e].value;throw Error(C)},S.prototype.set=function(t,e){this._insert(t,e,!1)},S.prototype.containskey=function(t){return this._findEntry(t)>=0},y.join=function(t,e,n,o){var s=this;return new g(function(u){var c=new p,a=!1,h=0,l=new S,f=!1,d=0,v=new S;return c.add(s.subscribe(function(t){var n,s,f,p,d=h++,m=new b;l.add(d,t),c.add(m),s=function(){return l.remove(d)&&0===l.count()&&a&&u.onCompleted(),c.remove(m)};try{n=e(t)}catch(y){return u.onError(y),r}m.disposable(n.take(1).subscribe(i,u.onError.bind(u),function(){s()})),p=v.getValues();for(var w=0;p.length>w;w++){try{f=o(t,p[w])}catch(g){return u.onError(g),r}u.onNext(f)}},u.onError.bind(u),function(){a=!0,(f||0===l.count())&&u.onCompleted()})),c.add(t.subscribe(function(t){var e,s,a,h,p=d++,m=new b;v.add(p,t),c.add(m),s=function(){return v.remove(p)&&0===v.count()&&f&&u.onCompleted(),c.remove(m)};try{e=n(t)}catch(y){return u.onError(y),r}m.disposable(e.take(1).subscribe(i,u.onError.bind(u),function(){s()})),h=l.getValues();for(var w=0;h.length>w;w++){try{a=o(h[w],t)}catch(y){return u.onError(y),r}u.onNext(a)}},u.onError.bind(u),function(){f=!0,(a||0===v.count())&&u.onCompleted()})),c})},y.groupJoin=function(t,e,n,o){var s=this;return new g(function(u){var c=new p,a=new d(c),h=0,l=new S,f=0,v=new S;return c.add(s.subscribe(function(t){var n,s,f,p,d,y,w=h++,g=new m;l.add(w,g);try{d=o(t,E(g,a))}catch(x){for(p=l.getValues(),f=0;p.length>f;f++)p[f].onError(x);return u.onError(x),r}for(u.onNext(d),y=v.getValues(),f=0;y.length>f;f++)g.onNext(y[f]);var C=new b;c.add(C),s=function(){l.remove(w)&&g.onCompleted(),c.remove(C)};try{n=e(t)}catch(x){for(p=l.getValues(),f=0;p.length>f;f++)p[f].onError(x);return u.onError(x),r}C.disposable(n.take(1).subscribe(i,function(t){p=l.getValues();for(var e=0,n=p.length;n>e;e++)p[e].onError(t);u.onError(t)},function(){s()}))},function(t){var e,n;for(n=l.getValues(),e=0;n.length>e;e++)n[e].onError(t);u.onError(t)},u.onCompleted.bind(u))),c.add(t.subscribe(function(t){var e,o,s,a=f++;v.add(a,t);var h=new b;c.add(h);var p=function(){v.remove(a),c.remove(h)};try{e=n(t)}catch(d){for(s=l.getValues(),o=0;s.length>o;o++)s[o].onError(d);return u.onError(d),r}for(h.disposable(e.take(1).subscribe(i,function(t){s=l.getValues();for(var e=0;s.length>e;e++)s[e].onError(t);u.onError(t)},function(){p()})),s=l.getValues(),o=0;s.length>o;o++)s[o].onNext(t)},function(t){var e,n;for(n=l.getValues(),e=0;n.length>e;e++)n[e].onError(t);u.onError(t)})),a})},y.buffer=function(t,e){return 1===arguments.length&&"function"!=typeof arguments[0]?h.call(this,t).selectMany(function(t){return t.toArray()}):"function"==typeof t?l(t).selectMany(function(t){return t.toArray()}):a(this,t,e).selectMany(function(t){return t.toArray()})},y.window=function(t,e){return 1===arguments.length&&"function"!=typeof arguments[0]?h.call(this,t):"function"==typeof t?l.call(this,t):a.call(this,t,e)},n}); -------------------------------------------------------------------------------- /resources/private/js/rx.html.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Microsoft Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | (function(d,k){var g="object"==typeof exports&&exports&&("object"==typeof d&&d&&d==d.global&&(window=d),exports);"function"===typeof define&&define.amd?define(["./rx","exports"],function(g,f){d.Rx=k(d,f,g);return d.Rx}):"object"==typeof module&&module&&module.exports==g?(g=k(d,module.exports,require("./rx")),module.exports=g.Rx):d.Rx=k(d,{},d.Rx)})(this,function(d,k){function g(a,c,b){if(a.addEventListener)return a.addEventListener(c,b,!1),l(function(){a.removeEventListener(c,b,!1)});if(a.attachEvent)return a.attachEvent("on"+ 17 | c,b),l(function(){a.detachEvent("on"+c,b)});a["on"+c]=b;return l(function(){a["on"+c]=null})}function q(a,c,b){var e=new n;if(a&&a.nodeName||a===d)e.add(g(a,c,b));else if(a&&a.length)for(var j=0,f=a.length;j=a||0===a||""===a)c.onNext(b),c.onCompleted();else c.onError(b)}};b.onerror=b.onabort=function(){c.onError(b)}; 21 | b.send(a.body||null)}catch(h){c.onError(h)}var m=new r(l(function(){4!==b.readyState&&(b.abort(),c.onError(b))}));return p(function(a){return new n(c.subscribe(a),m.getDisposable())})};h.post=function(a,c){return u({url:a,body:c,method:"POST",async:!0})};var w=h.get=function(a){return u({url:a,method:"GET",async:!0})};JSON&&JSON.parse&&(h.getJSON=function(a){return w(a).select(function(a){return JSON.parse(a.responseText)})});return f}); -------------------------------------------------------------------------------- /resources/private/js/rx.jquery.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Microsoft Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | (function(o,f){var b=o.Rx,l=b.Observable,p=l.prototype,e=b.AsyncSubject,i=l.create,m=l.createWithDisposable,n=Array.prototype.slice,b=f.fn;f.Deferred.prototype.toObservable=function(){var a=new e;this.done(function(){a.onNext(n.call(arguments));a.onCompleted()}).fail(function(){a.onError(n.call(arguments))});return a};p.toDeferred=function(){var a=f.Deferred();this.subscribe(function(d){a.resolve(d)},function(d){a.reject(d)});return a};f.Callbacks.prototype.toObservable=function(){var a=this;return i(function(d){var c= 17 | function(a){d.onNext(a)};a.add(c);return function(){a.remove(c)}})};b.onAsObservable=function(a,d,c){var b=this;return i(function(h){var j=function(a){h.onNext(a)};b.on(a,d,c,j);return function(){b.off(a,d,j)}})};b.bindAsObservable=function(a,d){var c=this;return i(function(b){var h=function(a){b.onNext(a)};c.bind(a,d,h);return function(){c.unbind(a,h)}})};b.delegateAsObservable=function(a,d,c){var b=this;return i(function(h){var j=function(a){h.onNext(a)};b.delegate(a,d,c,j);return function(){b.undelegate(a, 18 | d,j)}})};b.liveAsObservable=function(a,d){var b=this;return i(function(g){var h=function(a){g.onNext(a)};b.live(a,d,h);return function(){b.die(a,h)}})};b.changeAsObservable=function(a){return this.bindAsObservable("change",a)};b.clickAsObservable=function(a){return this.bindAsObservable("click",a)};b.dblclickAsObservable=function(a){return this.bindAsObservable("dblclick",a)};b.focusAsObservable=function(a){return this.bindAsObservable("focus",a)};b.focusinAsObservable=function(a){return this.bindAsObservable("focusin", 19 | a)};b.focusoutAsObservable=function(a){return this.bindAsObservable("focusout",a)};b.keydownAsObservable=function(a){return this.bindAsObservable("keydown",a)};b.keyupAsObservable=function(a){return this.bindAsObservable("keyup",a)};b.loadAsObservable=function(a){return this.bindAsObservable("load",a)};b.mousedownAsObservable=function(a){return this.bindAsObservable("mousedown",a)};b.mouseenterAsObservable=function(a){return this.bindAsObservable("mouseenter",a)};b.mouseleaveAsObservable=function(a){return this.bindAsObservable("mouseleave", 20 | a)};b.mousemoveAsObservable=function(a){return this.bindAsObservable("mousemove",a)};b.mouseoutAsObservable=function(a){return this.bindAsObservable("mouseout",a)};b.mouseoverAsObservable=function(a){return this.bindAsObservable("mouseover",a)};b.mouseupAsObservable=function(a){return this.bindAsObservable("mouseup",a)};b.resizeAsObservable=function(a){return this.bindAsObservable("resize",a)};b.scrollAsObservable=function(a){return this.bindAsObservable("scroll",a)};b.selectAsObservable=function(a){return this.bindAsObservable("select", 21 | a)};b.submitAsObservable=function(a){return this.bindAsObservable("submit",a)};b.unloadAsObservable=function(a){return this.bindAsObservable("unload",a)};b.oneAsObservable=function(a,d,b){var g=this;return m(function(h){var e=function(f){g.off(a,d,b,e);h.onNext(f);h.onCompleted()};g.on(a,d,b,e);return dispoableEmpty})};b.readyAsObservable=function(){var a=this;return m(function(d){a.ready(function(a){d.onNext(a)});return dispoableEmpty})};b.hideAsObservable=function(a,d){var b=new e;this.hide(a,d, 22 | function(){b.onNext(this);b.onCompleted()});return b};b.showAsObservable=function(a){var d=new e;this.show(a,function(){d.onNext(this);d.onCompleted()});return d};b.animateAsObservable=function(a,d,b){var g=new e;this.animate(a,d,b,function(){g.onNext(this);g.onCompleted()});return g};b.fadeInAsObservable=function(a,b){var c=new e;this.fadeIn(a,b,function(){c.onNext(this);c.onCompleted()});return c};b.fadeToAsObservable=function(a,b,c){var g=new e;this.fadeTo(a,b,c,function(){g.onNext(this);g.onCompleted()}); 23 | return g};b.fadeOutAsObservable=function(a,b){var c=new e;this.fadeOut(a,b,function(){c.onNext(this);c.onCompleted()});return c};b.fadeToggleAsObservable=function(a,b){var c=new e;this.fadeToggle(a,b,function(){c.onNext(this);c.onCompleted()});return c};b.slideDownAsObservable=function(a){var b=new e;this.slideDown(a,function(){b.onNext(this);b.onCompleted()});return b};b.slideUpAsObservable=function(a){var b=new e;this.slideUp(a,function(){b.onNext(this);b.onCompleted()});return b};b.slideToggleAsObservable= 24 | function(a){var b=new e;this.slideToggle(a,function(){b.onNext(this);b.onCompleted()});return b};b.toggleAsObservable=function(a,b){var c=new e;this.toggle(a,b,function(){c.onNext(this);c.onCompleted()});return c};var k=f.ajaxAsObservable=function(a){var b=new e,c={success:function(a,c,e){b.onNext({data:a,textStatus:c,jqXHR:e});b.onCompleted()},error:function(a,c,e){b.onError({jqXHR:a,textStatus:c,errorThrown:e})}};f.extend(!0,c,a);f.ajax(c);return b};f.getAsObservable=function(a,b,c){return k({url:a, 25 | dataType:c,data:b})};f.getJSONAsObservable=function(a,b){return k({url:a,dataType:"json",data:b})};f.getScriptAsObservable=function(a){return k({url:a,dataType:"script"})};f.postAsObservable=function(a,b,c){return k({url:a,dataType:c,data:b,type:"POST"})}})(this,jQuery); -------------------------------------------------------------------------------- /resources/private/js/rx.min.js: -------------------------------------------------------------------------------- 1 | /*Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | Microsoft Open Technologies would like to thank its contributors, a list. 3 | of whom are at http://aspnetwebstack.codeplex.com/wikipage?title=Contributors.. 4 | Licensed under the Apache License, Version 2.0 (the "License"); you. 5 | may not use this file except in compliance with the License. You may. 6 | obtain a copy of the License at. 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0. 9 | 10 | Unless required by applicable law or agreed to in writing, software. 11 | distributed under the License is distributed on an "AS IS" BASIS,. 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or. 13 | implied. See the License for the specific language governing permissions. 14 | and limitations under the License.. 15 | */ 16 | (function(e,t){function i(){}function s(e){return e}function o(){return(new Date).getTime()}function u(e,t){return e===t}function a(e,t){return e-t}function f(e){return e.toString()}function l(e){throw e}function d(){if(this.isDisposed)throw new Error(p)}function m(e,t){return e.length===1&&Array.isArray(e[t])?e[t]:v.call(e)}function E(e,t){var n=new Array(e);for(var r=0;r>>0;n>>0,n=new Array(t),r=Object(this);for(var i=0;i>>0;i>>0;if(r===0)return-1;var i=0;arguments.length>1&&(i=Number(arguments[1]),i!=i?i=0:i!=0&&i!=Infinity&&i!=-Infinity&&(i=(i>0||-1)*Math.floor(Math.abs(i))));if(i>=r)return-1;var s=i>=0?i:Math.max(r-Math.abs(i),0);for(;s=this.length||e<0)return;var t=e-1>>1;if(t<0||t===e)return;if(this.isHigherPriority(e,t)){var n=this.items[e];this.items[e]=this.items[t],this.items[t]=n,this.percolate(t)}},T.heapify=function(e){e===t&&(e=0);if(e>=this.length||e<0)return;var n=2*e+1,r=2*e+2,i=e;n0)throw new Error(H);return n(this,e)}function n(e,t,n){return this.scheduleWithRelativeAndState(e,t-this.now(),n)}return new P(o,e,t,n)}(),j=P.currentThread=function(){function t(){e=new x(4)}function n(e,t){return this.scheduleWithRelativeAndState(e,0,t)}function r(n,r,i){var s=this.now()+P.normalize(r),o=new D(this,n,i,s),u;if(!e){u=new t;try{e.enqueue(o),u.run()}finally{u.dispose()}}else e.enqueue(o);return o.disposable}function i(e,t,n){return this.scheduleWithRelativeAndState(e,t-this.now(),n)}var e;t.prototype.dispose=function(){e=null},t.prototype.run=function(){var t;while(e.length>0){t=e.dequeue();if(!t.isCancelled()){while(t.dueTime-P.now()>0);t.isCancelled()||t.invoke()}}};var s=new P(o,n,r,i);return s.scheduleRequired=function(){return e===null},s.ensureTrampoline=function(t){return e===null?this.schedule(t):t()},s}(),F=function(){function e(e,t){t(0,this._period);try{this._state=this._action(this._state)}catch(n){throw this._cancel.dispose(),n}}function t(e,t,n,r){this._scheduler=e,this._state=t,this._period=n,this._action=r}return t.prototype.start=function(){var t=new A;return this._cancel=t,t.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0,this._period,e.bind(this))),t},t}();r.VirtualTimeScheduler=function(){function e(){return this.toDateTimeOffset(this.clock)}function t(e,t){return this.scheduleAbsoluteWithState(e,this.clock,t)}function n(e,t,n){return this.scheduleRelativeWithState(e,this.toRelative(t),n)}function r(e,t,n){return this.scheduleRelativeWithState(e,this.toRelative(t-this.now()),n)}function i(e,t){return t(),L}function s(i,o){this.clock=i,this.comparer=o,this.isEnabled=!1,this.queue=new x(1024),s.super_.constructor.call(this,e,t,n,r)}return y(s,P),b(s.prototype,{schedulePeriodicWithState:function(e,t,n){var r=new F(this,e,t,n);return r.start()},scheduleRelativeWithState:function(e,t,n){var r=this.add(this.clock,t);return this.scheduleAbsoluteWithState(e,r,n)},scheduleRelative:function(e,t){return this.scheduleRelativeWithState(t,e,i)},start:function(){var e;if(!this.isEnabled){this.isEnabled=!0;do e=this.getNext(),e!==null?(this.comparer(e.dueTime,this.clock)>0&&(this.clock=e.dueTime),e.invoke()):this.isEnabled=!1;while(this.isEnabled)}},stop:function(){this.isEnabled=!1},advanceTo:function(e){var t,n=this.comparer(this.clock,e);if(this.comparer(this.clock,e)>0)throw new Error(h);if(n===0)return;if(!this.isEnabled){this.isEnabled=!0;do t=this.getNext(),t!==null&&this.comparer(t.dueTime,e)<=0?(this.comparer(t.dueTime,this.clock)>0&&(this.clock=t.dueTime),t.invoke()):this.isEnabled=!1;while(this.isEnabled);this.clock=e}},advanceBy:function(e){var t=this.add(this.clock,e),n=this.comparer(this.clock,t);if(n>0)throw new Error(h);if(n===0)return;return this.advanceTo(t)},sleep:function(e){var t=this.add(this.clock,e);if(this.comparer(this.clock,t)>=0)throw new Error(h);this.clock=t},getNext:function(){var e;while(this.queue.length>0){e=this.queue.peek();if(!e.isCancelled())return e;this.queue.dequeue()}return null},scheduleAbsolute:function(e,t){return this.scheduleAbsoluteWithState(t,e,i)},scheduleAbsoluteWithState:function(e,t,n){var r=this,i=function(e,t){return r.queue.remove(s),n(e,t)},s=new D(r,e,i,t,r.comparer);return r.queue.enqueue(s),s.disposable}}),s}(),r.HistoricalScheduler=function(){function e(t,n){var r=t==null?0:t,i=n||a;e.super_.constructor.call(this,r,i)}y(e,r.VirtualTimeScheduler);var t=e.prototype;return t.add=function(e,t){return e+t},t.toDateTimeOffset=function(e){return(new Date(e)).getTime()},t.toRelative=function(e){return e},e}();var I=P.timeout=function(){function u(e,t){var n=this,i=new A,o=r(function(){i.setDisposable(t(n,e))});return new N(i,k(function(){s(o)}))}function a(t,n,r){var i=this,s=P.normalize(n);if(s===0)return i.scheduleWithState(t,r);var o=new A,u=e.setTimeout(function(){o.setDisposable(r(i,t))},s);return new N(o,k(function(){e.clearTimeout(u)}))}function f(e,t,n){return this.scheduleWithRelativeAndState(e,t-this.now(),n)}var t=e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame,n=e.cancelAnimationFrame||e.webkitCancelAnimationFrame||e.mozCancelAnimationFrame||e.oCancelAnimationFrame||e.msCancelAnimationFrame,r,s;return typeof e.process!="undefined"&&typeof e.process.nextTick=="function"?(r=e.process.nextTick,s=i):typeof e.setImmediate=="function"?(r=e.setImmediate,s=e.clearImmediate):typeof t=="function"?(r=t,s=n):(r=function(t){return e.setTimeout(t,0)},s=e.clearTimeout),new P(o,u,a,f)}(),q=function(){function e(){return this._scheduler.now()}function t(e,t){return this._scheduler.scheduleWithState(e,this._wrap(t))}function n(e,t,n){return this._scheduler.scheduleWithRelativeAndState(e,t,this._wrap(n))}function r(e,t,n){return this._scheduler.scheduleWithAbsoluteAndState(e,t,this._wrap(n))}function i(s,o){this._scheduler=s,this._handler=o,this._recursiveOriginal=null,this._recursiveWrapper=null,i.super_.constructor.call(this,e,t,n,r)}return y(i,P),i.prototype._clone=function(e){return new i(e,this._handler)},i.prototype._wrap=function(e){var t=this;return function(n,r){try{return e(t._getRecursiveWrapper(n),r)}catch(i){if(!t._handler(i))throw i;return L}}},i.prototype._getRecursiveWrapper=function(e){if(!this._recursiveOriginal!==e){this._recursiveOriginal=e;var t=this._clone(e);t._recursiveOriginal=e,t._recursiveWrapper=t,this._recursiveWrapper=t}return this._recursiveWrapper},i.prototype.schedulePeriodicWithState=function(e,t,n){var r=this,i=!1,s=new A;return s.setDisposable(this._scheduler.schedulePeriodicWithState(e,t,function(e){if(i)return null;try{return n(e)}catch(t){i=!0;if(!r._handler(t))throw t;return s.dispose(),null}})),s},i}(),R=r.Notification=function(){function e(){}return b(e.prototype,{accept:function(e,t,n){return arguments.length>1||typeof e=="function"?this._accept(e,t,n):this._acceptObservable(e)},toObservable:function(e){var t=this;return e=e||B,new wt(function(n){return e.schedule(function(){t._acceptObservable(n),t.kind==="N"&&n.onCompleted()})})},hasValue:!1,equals:function(e){var t=e==null?"":e.toString();return this.toString()===t}}),e}(),U=R.createOnNext=function(){function e(e){this.value=e,this.hasValue=!0,this.kind="N"}return y(e,R),b(e.prototype,{_accept:function(e){return e(this.value)},_acceptObservable:function(e){return e.onNext(this.value)},toString:function(){return"OnNext("+this.value+")"}}),function(t){return new e(t)}}(),z=R.createOnError=function(){function e(e){this.exception=e,this.kind="E"}return y(e,R),b(e.prototype,{_accept:function(e,t){return t(this.exception)},_acceptObservable:function(e){return e.onError(this.exception)},toString:function(){return"OnError("+this.exception+")"}}),function(t){return new e(t)}}(),W=R.createOnCompleted=function(){function e(){this.kind="C"}return y(e,R),b(e.prototype,{_accept:function(e,t,n){return n()},_acceptObservable:function(e){return e.onCompleted()},toString:function(){return"OnCompleted()"}}),function(){return new e}}(),X=r.Internals.Enumerator=function(e,t,n){this.moveNext=e,this.getCurrent=t,this.dispose=n},V=X.create=function(e,t,n){var r=!1;return n||(n=i),new X(function(){if(r)return!1;var t=e();return t||(r=!0,n()),t},function(){return t()},function(){r||(n(),r=!0)})},$=r.Internals.Enumerable=function(){function e(e){this.getEnumerator=e}return e.prototype.concat=function(){var e=this;return new wt(function(t){var n=e.getEnumerator(),r=!1,i=new O,s=B.scheduleRecursive(function(e){var s,o,u=!1;if(!!r)return;try{u=n.moveNext(),u?s=n.getCurrent():n.dispose()}catch(a){o=a,n.dispose()}if(o){t.onError(o);return}if(!u){t.onCompleted();return}var f=new A;i.setDisposable(f),f.setDisposable(s.subscribe(t.onNext.bind(t),t.onError.bind(t),function(){e()}))});return new N(i,s,k(function(){r=!0,n.dispose()}))})},e.prototype.catchException=function(){var e=this;return new wt(function(t){var n=e.getEnumerator(),r=!1,i,s=new O,o=B.scheduleRecursive(function(e){var o,u,a;a=!1;if(!!r)return;try{a=n.moveNext(),a&&(o=n.getCurrent())}catch(f){u=f}if(u){t.onError(u);return}if(!a){i?t.onError(i):t.onCompleted();return}var l=new A;s.setDisposable(l),l.setDisposable(o.subscribe(t.onNext.bind(t),function(t){i=t,e()},t.onCompleted.bind(t)))});return new N(s,o,k(function(){r=!0}))})},e}(),J=$.repeat=function(e,n){return n===t&&(n=-1),new $(function(){var t,r=n;return V(function(){return r===0?!1:(r>0&&r--,t=e,!0)},function(){return t})})},K=$.forEach=function(e,t){return t||(t=s),new $(function(){var n,r=-1;return V(function(){return++r0&&(e=!this.isAcquired,this.isAcquired=!0),e&&this.disposable.setDisposable(this.scheduler.scheduleRecursive(function(e){var n;if(!(t.queue.length>0)){t.isAcquired=!1;return}n=t.queue.shift();try{n()}catch(r){throw t.queue=[],t.hasFaulted=!0,r}e()}))},e.prototype.dispose=function(){e.super_.dispose.call(this),this.disposable.dispose()},e}(),nt=function(){function e(){e.super_.constructor.apply(this,arguments)}return y(e,tt),e.prototype.next=function(t){e.super_.next.call(this,t),this.ensureActive()},e.prototype.error=function(t){e.super_.error.call(this,t),this.ensureActive()},e.prototype.completed=function(){e.super_.completed.call(this),this.ensureActive()},e}(),rt,it=r.Observable=function(){function e(e){this._subscribe=e}return rt=e.prototype,rt.finalValue=function(){var e=this;return new wt(function(t){var n=!1,r;return e.subscribe(function(e){n=!0,r=e},t.onError.bind(t),function(){n?(t.onNext(r),t.onCompleted()):t.onError(new Error(c))})})},rt.subscribe=function(e,t,n){var r;return arguments.length===0||arguments.length>1||typeof e=="function"?r=G(e,t,n):r=e,this._subscribe(r)},rt.toArray=function(){function e(e,t){return e.push(t),e.slice(0)}return this.scan([],e).startWith([]).finalValue()},e}();it.start=function(e,t,n){return st(e,t)()};var st=it.toAsync=function(e,t,n){return t||(t=I),function(){var r=v.call(arguments,0),i=new Nt;return t.schedule(function(){var t;try{t=e.apply(n,r)}catch(s){i.onError(s);return}i.onNext(t),i.onCompleted()}),i.asObservable()}};rt.observeOn=function(e){var t=this;return new wt(function(n){return t.subscribe(new nt(e,n))})},rt.subscribeOn=function(e){var t=this;return new wt(function(n){var r=new A,i=new O;return i.setDisposable(r),r.setDisposable(e.schedule(function(){i.setDisposable(new _(e,t.subscribe(n)))})),i})},it.create=function(e){return new wt(function(t){return k(e(t))})},it.createWithDisposable=function(e){return new wt(e)};var ot=it.defer=function(e){return new wt(function(t){var n;try{n=e()}catch(r){return ct(r).subscribe(t)}return n.subscribe(t)})},ut=it.empty=function(e){return e||(e=B),new wt(function(t){return e.schedule(function(){t.onCompleted()})})},at=it.fromArray=function(e,t){return t||(t=j),new wt(function(n){var r=0;return t.scheduleRecursive(function(t){r0?(e=o.shift(),u(e)):(r--,s&&r===0&&n.onCompleted())}))};return i.add(t.subscribe(function(t){r0})){try{u=s.map(function(e){return e.shift()}),i=n.apply(e,u)}catch(a){r.onError(a);return}r.onNext(i)}else o.filter(function(e,n){return n!==t}).every(function(e){return e})&&r.onCompleted()},f=new Array(i);for(var l=0;l0})},rt.dematerialize=function(){var e=this;return new wt(function(t){return e.subscribe(function(e){return e.accept(t)},t.onError.bind(t),t.onCompleted.bind(t))})},rt.distinctUntilChanged=function(e,t){var n=this;return e||(e=s),t||(t=u),new wt(function(r){var i=!1,s;return n.subscribe(function(n){var o=!1,u;try{u=e(n)}catch(a){r.onError(a);return}if(i)try{o=t(s,u)}catch(a){r.onError(a);return}if(!i||!o)i=!0,s=u,r.onNext(n)},r.onError.bind(r),r.onCompleted.bind(r))})},rt.doAction=function(e,t,n){var r=this,i;return typeof e=="function"?i=e:(i=e.onNext.bind(e),t=e.onError.bind(e),n=e.onCompleted.bind(e)),new wt(function(e){return r.subscribe(function(t){try{i(t)}catch(n){e.onError(n)}e.onNext(t)},function(n){if(!t)e.onError(n);else{try{t(n)}catch(r){e.onError(r)}e.onError(n)}},function(){if(!n)e.onCompleted();else{try{n()}catch(t){e.onError(t)}e.onCompleted()}})})},rt.finallyAction=function(e){var t=this;return new wt(function(n){var r=t.subscribe(n);return k(function(){try{r.dispose()}finally{e()}})})},rt.ignoreElements=function(){var e=this;return new wt(function(t){return e.subscribe(i,t.onError.bind(t),t.onCompleted.bind(t))})},rt.materialize=function(){var e=this;return new wt(function(t){return e.subscribe(function(e){t.onNext(U(e))},function(e){t.onNext(z(e)),t.onCompleted()},function(){t.onNext(W()),t.onCompleted()})})},rt.repeat=function(e){return J(this,e).concat()},rt.retry=function(e){return J(this,e).catchException()},rt.scan=function(){var e,t=!1,n;arguments.length===2?(e=arguments[0],n=arguments[1],t=!0):n=arguments[0];var r=this;return ot(function(){var i=!1,s;return r.select(function(r){return i?s=n(s,r):(s=t?n(e,r):r,i=!0),s})})},rt.skipLast=function(e){var t=this;return new wt(function(n){var r=[];return t.subscribe(function(t){r.push(t),r.length>e&&n.onNext(r.shift())},n.onError.bind(n),n.onCompleted.bind(n))})},rt.startWith=function(){var e,n,r=0;return arguments.length>0&&arguments[0]!=null&&arguments[0].now!==t?(n=arguments[0],r=1):n=B,e=v.call(arguments,r),K([at(e,n),this]).concat()},rt.takeLast=function(e,t){return this.takeLastBuffer(e).selectMany(function(e){return at(e,t)})},rt.takeLastBuffer=function(e){var t=this;return new wt(function(n){var r=[];return t.subscribe(function(t){r.push(t),r.length>e&&r.shift()},n.onError.bind(n),function(){n.onNext(r),n.onCompleted()})})},rt.windowWithCount=function(e,t){var n=this;if(e<=0)throw new Error(h);t==null&&(t=e);if(t<=0)throw new Error(h);return new wt(function(r){var i=new A,s=new M(i),o=0,u=[],a=function(){var e=new Tt;u.push(e),r.onNext(w(e,s))};return a(),i.setDisposable(n.subscribe(function(n){var r;for(var i=0,s=u.length;i=0&&f%t===0&&(r=u.shift(),r.onCompleted()),o++,o%t===0&&a()},function(e){while(u.length>0)u.shift().onError(e);r.onError(e)},function(){while(u.length>0)u.shift().onCompleted();r.onCompleted()})),s})},rt.defaultIfEmpty=function(e){var n=this;return e===t&&(e=null),new wt(function(t){var r=!1;return n.subscribe(function(e){r=!0,t.onNext(e)},t.onError.bind(t),function(){r||t.onNext(e),t.onCompleted()})})},rt.distinct=function(e,t){var n=this;return e||(e=s),t||(t=f),new wt(function(r){var i={};return n.subscribe(function(n){var s,o,u,a=!1;try{s=e(n),o=t(s)}catch(f){r.onError(f);return}for(u in i)if(o===u){a=!0;break}a||(i[o]=null,r.onNext(n))},r.onError.bind(r),r.onCompleted.bind(r))})},rt.groupBy=function(e,t,n){return this.groupByUntil(e,t,function(){return ft()},n)},rt.groupByUntil=function(e,t,n,r){var o=this;return t||(t=s),r||(r=f),new wt(function(s){var u={},a=new N,f=new M(a);return a.add(o.subscribe(function(o){var l,c,h,p,d,v,m,g,y,b,w;try{m=e(o),g=r(m)}catch(E){for(w in u)u[w].onError(E);s.onError(E);return}d=!1;try{b=u[g],b||(b=new Tt,u[g]=b,d=!0)}catch(E){for(w in u)u[w].onError(E);s.onError(E);return}if(d){v=new St(m,b,f),c=new St(m,b);try{l=n(c)}catch(E){for(w in u)u[w].onError(E);s.onError(E);return}s.onNext(v),y=new A,a.add(y),p=function(){g in u&&(delete u[g],b.onCompleted()),a.remove(y)},y.setDisposable(l.take(1).subscribe(i,function(e){for(w in u)u[w].onError(e);s.onError(e)},function(){p()}))}try{h=t(o)}catch(E){for(w in u)u[w].onError(E);s.onError(E);return}b.onNext(h)},function(e){for(var t in u)u[t].onError(e);s.onError(e)},function(){for(var e in u)u[e].onCompleted();s.onCompleted()})),f})},rt.select=rt.map=function(e){var t=this;return new wt(function(n){var r=0;return t.subscribe(function(t){var i;try{i=e(t,r++)}catch(s){n.onError(s);return}n.onNext(i)},n.onError.bind(n),n.onCompleted.bind(n))})},rt.selectMany=rt.flatMap=function(e,t){return t?this.selectMany(function(n){return e(n).select(function(e){return t(n,e)})}):typeof e=="function"?bt.call(this,e):bt.call(this,function(){return e})},rt.skip=function(e){if(e<0)throw new Error(h);var t=this;return new wt(function(n){var r=e;return t.subscribe(function(e){r<=0?n.onNext(e):r--},n.onError.bind(n),n.onCompleted.bind(n))})},rt.skipWhile=function(e){var t=this;return new wt(function(n){var r=0,i=!1;return t.subscribe(function(t){if(!i)try{i=!e(t,r++)}catch(s){n.onError(s);return}i&&n.onNext(t)},n.onError.bind(n),n.onCompleted.bind(n))})},rt.take=function(e,t){if(e<0)throw new Error(h);if(e===0)return ut(t);var n=this;return new wt(function(t){var r=e;return n.subscribe(function(e){r>0&&(r--,t.onNext(e),r===0&&t.onCompleted())},t.onError.bind(t),t.onCompleted.bind(t))})},rt.takeWhile=function(e){var t=this;return new wt(function(n){var r=0,i=!0;return t.subscribe(function(t){if(i){try{i=e(t,r++)}catch(s){n.onError(s);return}i?n.onNext(t):n.onCompleted()}},n.onError.bind(n),n.onCompleted.bind(n))})},rt.where=rt.filter=function(e){var t=this;return new wt(function(n){var r=0;return t.subscribe(function(t){var i;try{i=e(t,r++)}catch(s){n.onError(s);return}i&&n.onNext(t)},n.onError.bind(n),n.onCompleted.bind(n))})};var wt=r.Internals.AnonymousObservable=function(){function e(t){var n=function(e){var n=new Et(e);if(j.scheduleRequired())j.schedule(function(){try{n.disposable(t(n))}catch(e){if(!n.fail(e))throw e}});else try{n.disposable(t(n))}catch(r){if(!n.fail(r))throw r}return n};e.super_.constructor.call(this,n)}return y(e,it),e}(),Et=function(){function e(t){e.super_.constructor.call(this),this.observer=t,this.m=new A}return y(e,Y),e.prototype.next=function(e){var t=!1;try{this.observer.onNext(e),t=!0}finally{t||this.dispose()}},e.prototype.error=function(e){try{this.observer.onError(e)}finally{this.dispose()}},e.prototype.completed=function(){try{this.observer.onCompleted()}finally{this.dispose()}},e.prototype.disposable=function(e){return this.m.disposable(e)},e.prototype.dispose=function(){e.super_.dispose.call(this),this.m.dispose()},e}(),St=function(){function e(e){return this.underlyingObservable.subscribe(e)}function t(n,r,i){t.super_.constructor.call(this,e),this.key=n,this.underlyingObservable=i?new wt(function(e){return new N(i.getDisposable(),r.subscribe(e))}):r}return y(t,it),t}(),xt=function(e,t){this.subject=e,this.observer=t};xt.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 Tt=r.Subject=function(){function e(e){return d.call(this),this.isStopped?this.exception?(e.onError(this.exception),L):(e.onCompleted(),L):(this.observers.push(e),new xt(this,e))}function t(){t.super_.constructor.call(this,e),this.isDisposed=!1,this.isStopped=!1,this.observers=[]}return y(t,it),b(t.prototype,Q,{onCompleted:function(){d.call(this);if(!this.isStopped){var e=this.observers.slice(0);this.isStopped=!0;for(var t=0,n=e.length;tr;r++)n[r]=e();return n}function f(t,e){this.scheduler=t,this.disposable=e,this.isDisposed=!1}function p(t,e,n,r,i){this.scheduler=t,this.state=e,this.action=n,this.dueTime=r,this.comparer=i||s,this.disposable=new j}function d(t,n){return new De(function(r){var i=new j,o=new P;return o.setDisposable(i),i.setDisposable(t.subscribe(r.onNext.bind(r),function(t){var i,s;try{s=n(t)}catch(u){return r.onError(u),e}i=new j,o.setDisposable(i),i.setDisposable(s.subscribe(r))},r.onCompleted.bind(r))),o})}function b(t,n){var r=this;return new De(function(i){var o=0,s=t.length;return r.subscribe(function(r){if(s>o){var u,c=t[o++];try{u=n(r,c)}catch(a){return i.onError(a),e}i.onNext(u)}else i.onCompleted()},i.onError.bind(i),i.onCompleted.bind(i))})}function v(t){return this.select(t).mergeObservable()}var m="object"==typeof exports&&exports,y=("object"==typeof module&&module&&module.exports==m&&module,"object"==typeof global&&global);y.global===y&&(t=y);var w={Internals:{}},g="Sequence contains no elements.",E="Argument out of range",x="Object has been disposed",C=Array.prototype.slice;({}).hasOwnProperty;var D=this.inherits=w.Internals.inherits=function(t,e){function n(){this.constructor=t}n.prototype=e.prototype,t.prototype=new n},A=w.Internals.addProperties=function(t){for(var e=C.call(arguments,1),n=0,r=e.length;r>n;n++){var i=e[n];for(var o in i)t[o]=i[o]}},S=w.Internals.addRef=function(t,e){return new De(function(n){return new R(e.getDisposable(),t.subscribe(n))})},_=function(t,e){this.id=t,this.value=e};_.prototype.compareTo=function(t){var e=this.value.compareTo(t.value);return 0===e&&(e=this.id-t.id),e};var N=function(t){this.items=Array(t),this.length=0},W=N.prototype;W.isHigherPriority=function(t,e){return 0>this.items[t].compareTo(this.items[e])},W.percolate=function(t){if(!(t>=this.length||0>t)){var e=t-1>>1;if(!(0>e||e===t)&&this.isHigherPriority(t,e)){var n=this.items[t];this.items[t]=this.items[e],this.items[e]=n,this.percolate(e)}}},W.heapify=function(t){if(t===e&&(t=0),!(t>=this.length||0>t)){var n=2*t+1,r=2*t+2,i=t;if(this.length>n&&this.isHigherPriority(n,i)&&(i=n),this.length>r&&this.isHigherPriority(r,i)&&(i=r),i!==t){var o=this.items[t];this.items[t]=this.items[i],this.items[i]=o,this.heapify(i)}}},W.peek=function(){return this.items[0].value},W.removeAt=function(t){this.items[t]=this.items[--this.length],delete this.items[this.length],this.heapify()},W.dequeue=function(){var t=this.peek();return this.removeAt(0),t},W.enqueue=function(t){var e=this.length++;this.items[e]=new _(N.count++,t),this.percolate(e)},W.remove=function(t){for(var e=0;this.length>e;e++)if(this.items[e].value===t)return this.removeAt(e),!0;return!1},N.count=0;var R=w.CompositeDisposable=function(){this.disposables=h(arguments,0),this.isDisposed=!1,this.length=this.disposables.length},O=R.prototype;O.add=function(t){this.isDisposed?t.dispose():(this.disposables.push(t),this.length++)},O.remove=function(t){var e=!1;if(!this.isDisposed){var n=this.disposables.indexOf(t);-1!==n&&(e=!0,this.disposables.splice(n,1),this.length--,t.dispose())}return e},O.dispose=function(){if(!this.isDisposed){this.isDisposed=!0;var t=this.disposables.slice(0);this.disposables=[],this.length=0;for(var e=0,n=t.length;n>e;e++)t[e].dispose()}},O.clear=function(){var t=this.disposables.slice(0);this.disposables=[],this.length=0;for(var e=0,n=t.length;n>e;e++)t[e].dispose()},O.contains=function(t){return-1!==this.disposables.indexOf(t)},O.toArray=function(){return this.disposables.slice(0)};var k=w.Disposable=function(t){this.isDisposed=!1,this.action=t};k.prototype.dispose=function(){this.isDisposed||(this.action(),this.isDisposed=!0)};var q=k.create=function(t){return new k(t)},T=k.empty={dispose:n},j=w.SingleAssignmentDisposable=function(){this.isDisposed=!1,this.current=null},I=j.prototype;I.disposable=function(t){return t?this.setDisposable(t):this.getDisposable()},I.getDisposable=function(){return this.current},I.setDisposable=function(t){if(this.current)throw Error("Disposable has already been assigned");var e=this.isDisposed;e||(this.current=t),e&&t&&t.dispose()},I.dispose=function(){var t;this.isDisposed||(this.isDisposed=!0,t=this.current,this.current=null),t&&t.dispose()};var P=w.SerialDisposable=function(){this.isDisposed=!1,this.current=null};P.prototype.getDisposable=function(){return this.current},P.prototype.setDisposable=function(t){var e,n=this.isDisposed;n||(e=this.current,this.current=t),e&&e.dispose(),n&&t&&t.dispose()},P.prototype.disposable=function(t){return t?(this.setDisposable(t),e):this.getDisposable()},P.prototype.dispose=function(){var t;this.isDisposed||(this.isDisposed=!0,t=this.current,this.current=null),t&&t.dispose()};var M=w.RefCountDisposable=function(){function t(t){this.disposable=t,this.disposable.count++,this.isInnerDisposed=!1}function e(t){this.underlyingDisposable=t,this.isDisposed=!1,this.isPrimaryDisposed=!1,this.count=0}return t.prototype.dispose=function(){this.disposable.isDisposed||this.isInnerDisposed||(this.isInnerDisposed=!0,this.disposable.count--,0===this.disposable.count&&this.disposable.isPrimaryDisposed&&(this.disposable.isDisposed=!0,this.disposable.underlyingDisposable.dispose()))},e.prototype.dispose=function(){this.isDisposed||this.isPrimaryDisposed||(this.isPrimaryDisposed=!0,0===this.count&&(this.isDisposed=!0,this.underlyingDisposable.dispose()))},e.prototype.getDisposable=function(){return this.isDisposed?T:new t(this)},e}();f.prototype.dispose=function(){var t=this;this.scheduler.schedule(function(){t.isDisposed||(t.isDisposed=!0,t.disposable.dispose())})},p.prototype.invoke=function(){this.disposable.disposable(this.invokeCore())},p.prototype.compareTo=function(t){return this.comparer(this.dueTime,t.dueTime)},p.prototype.isCancelled=function(){return this.disposable.isDisposed},p.prototype.invokeCore=function(){return this.action(this.scheduler,this.state)};var L=w.Scheduler=function(){function e(t,e,n,r){this.now=t,this._schedule=e,this._scheduleRelative=n,this._scheduleAbsolute=r}function n(t,e){var n=e.first,r=e.second,i=new R,o=function(e){r(e,function(e){var n=!1,r=!1,s=t.scheduleWithState(e,function(t,e){return n?i.remove(s):r=!0,o(e),T});r||(i.add(s),n=!0)})};return o(n),i}function r(t,e,n){var r=e.first,i=e.second,o=new R,s=function(e){i(e,function(e,r){var i=!1,u=!1,c=t[n].call(t,e,r,function(t,e){return i?o.remove(c):u=!0,s(e),T});u||(o.add(c),i=!0)})};return s(r),o}function o(t,e){return e(),T}var s=e.prototype;return s.catchException=function(t){return new J(this,t)},s.schedulePeriodic=function(t,e){return this.schedulePeriodicWithState(null,t,function(){e()})},s.schedulePeriodicWithState=function(e,n,r){var i=e,o=t.setInterval(function(){i=r(i)},n);return q(function(){t.clearInterval(o)})},s.schedule=function(t){return this._schedule(t,o)},s.scheduleWithState=function(t,e){return this._schedule(t,e)},s.scheduleWithRelative=function(t,e){return this._scheduleRelative(e,t,o)},s.scheduleWithRelativeAndState=function(t,e,n){return this._scheduleRelative(t,e,n)},s.scheduleWithAbsolute=function(t,e){return this._scheduleAbsolute(e,t,o)},s.scheduleWithAbsoluteAndState=function(t,e,n){return this._scheduleAbsolute(t,e,n)},s.scheduleRecursive=function(t){return this.scheduleRecursiveWithState(t,function(t,e){t(function(){e(t)})})},s.scheduleRecursiveWithState=function(t,e){return this.scheduleWithState({first:t,second:e},function(t,e){return n(t,e)})},s.scheduleRecursiveWithRelative=function(t,e){return this.scheduleRecursiveWithRelativeAndState(e,t,function(t,e){t(function(n){e(t,n)})})},s.scheduleRecursiveWithRelativeAndState=function(t,e,n){return this._scheduleRelative({first:t,second:n},e,function(t,e){return r(t,e,"scheduleWithRelativeAndState")})},s.scheduleRecursiveWithAbsolute=function(t,e){return this.scheduleRecursiveWithAbsoluteAndState(e,t,function(t,e){t(function(n){e(t,n)})})},s.scheduleRecursiveWithAbsoluteAndState=function(t,e,n){return this._scheduleAbsolute({first:t,second:n},e,function(t,e){return r(t,e,"scheduleWithAbsoluteAndState")})},e.now=i,e.normalize=function(t){return 0>t&&(t=0),t},e}(),V="Scheduler is not allowed to block the thread",z=L.immediate=function(){function t(t,e){return e(this,t)}function e(t,e,n){if(e>0)throw Error(V);return n(this,t)}function n(t,e,n){return this.scheduleWithRelativeAndState(t,e-this.now(),n)}return new L(i,t,e,n)}(),B=L.currentThread=function(){function t(){o=new N(4)}function e(t,e){return this.scheduleWithRelativeAndState(t,0,e)}function n(e,n,r){var i,s=this.now()+L.normalize(n),u=new p(this,e,r,s);if(o)o.enqueue(u);else{i=new t;try{o.enqueue(u),i.run()}catch(c){throw c}finally{i.dispose()}}return u.disposable}function r(t,e,n){return this.scheduleWithRelativeAndState(t,e-this.now(),n)}var o;t.prototype.dispose=function(){o=null},t.prototype.run=function(){for(var t;o.length>0;)if(t=o.dequeue(),!t.isCancelled()){for(;t.dueTime-L.now()>0;);t.isCancelled()||t.invoke()}};var s=new L(i,e,n,r);return s.scheduleRequired=function(){return null===o},s.ensureTrampoline=function(t){return null===o?this.schedule(t):t()},s}(),F=function(){function t(t,e){e(0,this._period);try{this._state=this._action(this._state)}catch(n){throw this._cancel.dispose(),n}}function e(t,e,n,r){this._scheduler=t,this._state=e,this._period=n,this._action=r}return e.prototype.start=function(){var e=new j;return this._cancel=e,e.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0,this._period,t.bind(this))),e},e}();w.VirtualTimeScheduler=function(t){function n(){return this.toDateTimeOffset(this.clock)}function r(t,e){return this.scheduleAbsoluteWithState(t,this.clock,e)}function i(t,e,n){return this.scheduleRelativeWithState(t,this.toRelative(e),n)}function o(t,e,n){return this.scheduleRelativeWithState(t,this.toRelative(e-this.now()),n)}function s(t,e){return e(),T}function u(e,s){this.clock=e,this.comparer=s,this.isEnabled=!1,this.queue=new N(1024),t.call(this,n,r,i,o)}D(u,t);var c=u.prototype;return c.schedulePeriodicWithState=function(t,e,n){var r=new F(this,t,e,n);return r.start()},c.scheduleRelativeWithState=function(t,e,n){var r=this.add(this.clock,e);return this.scheduleAbsoluteWithState(t,r,n)},c.scheduleRelative=function(t,e){return this.scheduleRelativeWithState(e,t,s)},c.start=function(){var t;if(!this.isEnabled){this.isEnabled=!0;do t=this.getNext(),null!==t?(this.comparer(t.dueTime,this.clock)>0&&(this.clock=t.dueTime),t.invoke()):this.isEnabled=!1;while(this.isEnabled)}},c.stop=function(){this.isEnabled=!1},c.advanceTo=function(t){var e,n=this.comparer(this.clock,t);if(this.comparer(this.clock,t)>0)throw Error(E);if(0!==n&&!this.isEnabled){this.isEnabled=!0;do e=this.getNext(),null!==e&&0>=this.comparer(e.dueTime,t)?(this.comparer(e.dueTime,this.clock)>0&&(this.clock=e.dueTime),e.invoke()):this.isEnabled=!1;while(this.isEnabled);this.clock=t}},c.advanceBy=function(t){var n=this.add(this.clock,t),r=this.comparer(this.clock,n);if(r>0)throw Error(E);return 0!==r?this.advanceTo(n):e},c.sleep=function(t){var e=this.add(this.clock,t);if(this.comparer(this.clock,e)>=0)throw Error(E);this.clock=e},c.getNext=function(){for(var t;this.queue.length>0;){if(t=this.queue.peek(),!t.isCancelled())return t;this.queue.dequeue()}return null},c.scheduleAbsolute=function(t,e){return this.scheduleAbsoluteWithState(e,t,s)},c.scheduleAbsoluteWithState=function(t,e,n){var r=this,i=function(t,e){return r.queue.remove(o),n(t,e)},o=new p(r,t,i,e,r.comparer);return r.queue.enqueue(o),o.disposable},u}(L),w.HistoricalScheduler=function(t){function e(e,n){var r=null==e?0:e,i=n||s;t.call(this,r,i)}D(e,t);var n=e.prototype;return n.add=function(t,e){return t+e},n.toDateTimeOffset=function(t){return new Date(t).getTime()},n.toRelative=function(t){return t},e}(w.VirtualTimeScheduler);var H,U=n;(function(){function e(){if(!t.postMessage||t.importScripts)return!1;var e=!1,n=t.onmessage;return t.onmessage=function(){e=!0},t.postMessage("","*"),t.onmessage=n,e}function n(t){if("string"==typeof t.data&&t.data.substring(0,r.length)===r){var e=t.data.substring(r.length),n=i[e];n(),delete i[e]}}if("object"==typeof t.process&&"[object process]"===Object.prototype.toString.call(t.process))H=t.process.nextTick;else if("function"==typeof t.setImmediate)H=t.setImmediate,U=t.clearImmediate;else if(e()){var r="ms.rx.schedule"+Math.random(),i={},o=0;t.addEventListener?t.addEventListener("message",n,!1):t.attachEvent("onmessage",n,!1),H=function(e){var n=o++;i[n]=e,t.postMessage(r+n,"*")}}else if(t.MessageChannel){var s=new t.MessageChannel,u={},c=0;s.port1.onmessage=function(t){var e=t.data,n=u[e];n(),delete u[e]},H=function(t){var e=c++;u[e]=t,s.port2.postMessage(e)}}else"document"in t&&"onreadystatechange"in t.document.createElement("script")?H=function(e){var n=t.document.createElement("script");n.onreadystatechange=function(){e(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},t.document.documentElement.appendChild(n)}:(H=function(e){return t.setTimeout(e,0)},U=t.clearTimeout)})();var G=L.timeout=function(){function e(t,e){var n=this,r=new j,i=H(function(){r.isDisposed||r.setDisposable(e(n,t))});return new R(r,q(function(){U(i)}))}function n(e,n,r){var i=this,o=L.normalize(n);if(0===o)return i.scheduleWithState(e,r);var s=new j,u=t.setTimeout(function(){s.isDisposed||s.setDisposable(r(i,e))},o);return new R(s,q(function(){t.clearTimeout(u)}))}function r(t,e,n){return this.scheduleWithRelativeAndState(t,e-this.now(),n)}return new L(i,e,n,r)}(),J=function(t){function e(){return this._scheduler.now()}function n(t,e){return this._scheduler.scheduleWithState(t,this._wrap(e))}function r(t,e,n){return this._scheduler.scheduleWithRelativeAndState(t,e,this._wrap(n))}function i(t,e,n){return this._scheduler.scheduleWithAbsoluteAndState(t,e,this._wrap(n))}function o(o,s){this._scheduler=o,this._handler=s,this._recursiveOriginal=null,this._recursiveWrapper=null,t.call(this,e,n,r,i)}return D(o,t),o.prototype._clone=function(t){return new o(t,this._handler)},o.prototype._wrap=function(t){var e=this;return function(n,r){try{return t(e._getRecursiveWrapper(n),r)}catch(i){if(!e._handler(i))throw i;return T}}},o.prototype._getRecursiveWrapper=function(t){if(this._recursiveOriginal!==t){this._recursiveOriginal=t;var e=this._clone(t);e._recursiveOriginal=t,e._recursiveWrapper=e,this._recursiveWrapper=e}return this._recursiveWrapper},o.prototype.schedulePeriodicWithState=function(t,e,n){var r=this,i=!1,o=new j;return o.setDisposable(this._scheduler.schedulePeriodicWithState(t,e,function(t){if(i)return null;try{return n(t)}catch(e){if(i=!0,!r._handler(e))throw e;return o.dispose(),null}})),o},o}(L),K=w.Notification=function(){function t(t,e){this.hasValue=null==e?!1:e,this.kind=t}var e=t.prototype;return e.accept=function(t,e,n){return 1===arguments.length&&"object"==typeof t?this._acceptObservable(t):this._accept(t,e,n)},e.toObservable=function(t){var e=this;return t=t||z,new De(function(n){return t.schedule(function(){e._acceptObservable(n),"N"===e.kind&&n.onCompleted()})})},e.equals=function(t){var e=null==t?"":""+t;return""+this===e},t}(),Q=K.createOnNext=function(){function t(t){return t(this.value)}function e(t){return t.onNext(this.value)}function n(){return"OnNext("+this.value+")"}return function(r){var i=new K("N",!0);return i.value=r,i._accept=t.bind(i),i._acceptObservable=e.bind(i),i.toString=n.bind(i),i}}(),X=K.createOnError=function(){function t(t,e){return e(this.exception)}function e(t){return t.onError(this.exception)}function n(){return"OnError("+this.exception+")"}return function(r){var i=new K("E");return i.exception=r,i._accept=t.bind(i),i._acceptObservable=e.bind(i),i.toString=n.bind(i),i}}(),Y=K.createOnCompleted=function(){function t(t,e,n){return n()}function e(t){return t.onCompleted()}function n(){return"OnCompleted()"}return function(){var r=new K("C");return r._accept=t.bind(r),r._acceptObservable=e.bind(r),r.toString=n.bind(r),r}}(),Z=w.Internals.Enumerator=function(t,e,n){this.moveNext=t,this.getCurrent=e,this.dispose=n},$=Z.create=function(t,e,r){var i=!1;return r||(r=n),new Z(function(){if(i)return!1;var e=t();return e||(i=!0,r()),e},function(){return e()},function(){i||(r(),i=!0)})},te=w.Internals.Enumerable=function(){function t(t){this.getEnumerator=t}return t.prototype.concat=function(){var t=this;return new De(function(n){var r=t.getEnumerator(),i=!1,o=new P,s=z.scheduleRecursive(function(t){var s,u,c=!1;if(!i){try{c=r.moveNext(),c?s=r.getCurrent():r.dispose()}catch(a){u=a,r.dispose()}if(u)return n.onError(u),e;if(!c)return n.onCompleted(),e;var h=new j;o.setDisposable(h),h.setDisposable(s.subscribe(n.onNext.bind(n),n.onError.bind(n),function(){t()}))}});return new R(o,s,q(function(){i=!0,r.dispose()}))})},t.prototype.catchException=function(){var t=this;return new De(function(n){var r,i=t.getEnumerator(),o=!1,s=new P,u=z.scheduleRecursive(function(t){var u,c,a;if(a=!1,!o){try{a=i.moveNext(),a&&(u=i.getCurrent())}catch(h){c=h}if(c)return n.onError(c),e;if(!a)return r?n.onError(r):n.onCompleted(),e;var l=new j;s.setDisposable(l),l.setDisposable(u.subscribe(n.onNext.bind(n),function(e){r=e,t()},n.onCompleted.bind(n)))}});return new R(s,u,q(function(){o=!0}))})},t}(),ee=te.repeat=function(t,n){return n===e&&(n=-1),new te(function(){var e,r=n;return $(function(){return 0===r?!1:(r>0&&r--,e=t,!0)},function(){return e})})},ne=te.forEach=function(t,e){return e||(e=r),new te(function(){var n,r=-1;return $(function(){return++r0&&(t=!this.isAcquired,this.isAcquired=!0),t&&this.disposable.setDisposable(this.scheduler.scheduleRecursive(function(t){var r;if(!(n.queue.length>0))return n.isAcquired=!1,e;r=n.queue.shift();try{r()}catch(i){throw n.queue=[],n.hasFaulted=!0,i}t()}))},n.prototype.dispose=function(){t.prototype.dispose.call(this),this.disposable.dispose()},n}(se),he=function(t){function e(){t.apply(this,arguments)}return D(e,t),e.prototype.next=function(e){t.prototype.next.call(this,e),this.ensureActive()},e.prototype.error=function(e){t.prototype.error.call(this,e),this.ensureActive()},e.prototype.completed=function(){t.prototype.completed.call(this),this.ensureActive()},e}(ae),le=w.Observable=function(){function t(t){this._subscribe=t}return oe=t.prototype,oe.finalValue=function(){var t=this;return new De(function(e){var n,r=!1;return t.subscribe(function(t){r=!0,n=t},e.onError.bind(e),function(){r?(e.onNext(n),e.onCompleted()):e.onError(Error(g))})})},oe.subscribe=oe.forEach=function(t,e,n){var r;return r="object"==typeof t?t:ie(t,e,n),this._subscribe(r)},oe.toArray=function(){function t(t,e){var n=t.slice(0);return n.push(e),n}return this.scan([],t).startWith([]).finalValue()},t}();le.start=function(t,e){return fe(t,e)()};var fe=le.toAsync=function(t,n,r){return n||(n=G),function(){var i=C.call(arguments,0),o=new We;return n.schedule(function(){var n;try{n=t.apply(r,i)}catch(s){return o.onError(s),e}o.onNext(n),o.onCompleted()}),o.asObservable()}};oe.observeOn=function(t){var e=this;return new De(function(n){return e.subscribe(new he(t,n))})},oe.subscribeOn=function(t){var e=this;return new De(function(n){var r=new j,i=new P;return i.setDisposable(r),r.setDisposable(t.schedule(function(){i.setDisposable(new f(t,e.subscribe(n)))})),i})},le.create=function(t){return new De(function(e){return q(t(e))})},le.createWithDisposable=function(t){return new De(t)};var pe=le.defer=function(t){return new De(function(e){var n;try{n=t()}catch(r){return ye(r).subscribe(e)}return n.subscribe(e)})},de=le.empty=function(t){return t||(t=z),new De(function(e){return t.schedule(function(){e.onCompleted()})})},be=le.fromArray=function(t,e){return e||(e=B),new De(function(n){var r=0;return e.scheduleRecursive(function(e){t.length>r?(n.onNext(t[r++]),e()):n.onCompleted()})})};le.generate=function(t,n,r,i,o){return o||(o=B),new De(function(s){var u=!0,c=t;return o.scheduleRecursive(function(t){var o,a;try{u?u=!1:c=r(c),o=n(c),o&&(a=i(c))}catch(h){return s.onError(h),e}o?(s.onNext(a),t()):s.onCompleted()})})};var ve=le.never=function(){return new De(function(){return T})};le.range=function(t,e,n){return n||(n=B),new De(function(r){return n.scheduleRecursiveWithState(0,function(n,i){e>n?(r.onNext(t+n),i(n+1)):r.onCompleted()})})},le.repeat=function(t,e,n){return n||(n=B),null==e&&(e=-1),me(t,n).repeat(e)};var me=le.returnValue=function(t,e){return e||(e=z),new De(function(n){return e.schedule(function(){n.onNext(t),n.onCompleted()})})},ye=le.throwException=function(t,e){return e||(e=z),new De(function(n){return e.schedule(function(){n.onError(t)})})};le.using=function(t,e){return new De(function(n){var r,i,o=T;try{r=t(),r&&(o=r),i=e(r)}catch(s){return new R(ye(s).subscribe(n),o)}return new R(i.subscribe(n),o)})},oe.amb=function(t){var e=this;return new De(function(n){function r(){o||(o=s,a.dispose())}function i(){o||(o=u,c.dispose())}var o,s="L",u="R",c=new j,a=new j;return c.setDisposable(e.subscribe(function(t){r(),o===s&&n.onNext(t)},function(t){r(),o===s&&n.onError(t)},function(){r(),o===s&&n.onCompleted()})),a.setDisposable(t.subscribe(function(t){i(),o===u&&n.onNext(t)},function(t){i(),o===u&&n.onError(t)},function(){i(),o===u&&n.onCompleted()})),new R(c,a)})},le.amb=function(){function t(t,e){return t.amb(e)}for(var e=ve(),n=h(arguments,0),r=0,i=n.length;i>r;r++)e=t(e,n[r]);return e},oe.catchException=function(t){return"function"==typeof t?d(this,t):we([this,t])};var we=le.catchException=function(){var t=h(arguments,0);return ne(t).catchException()};oe.combineLatest=function(){var t=C.call(arguments);return Array.isArray(t[0])?t[0].unshift(this):t.unshift(this),ge.apply(this,t)};var ge=le.combineLatest=function(){var t=C.call(arguments),n=t.pop();return Array.isArray(t[0])&&(t=t[0]),new De(function(r){function i(t){var i;if(c[t]=!0,a||(a=c.every(function(t){return t}))){try{i=n.apply(null,f)}catch(o){return r.onError(o),e}r.onNext(i)}else h.filter(function(e,n){return n!==t}).every(function(t){return t})&&r.onCompleted()}function o(t){h[t]=!0,h.every(function(t){return t})&&r.onCompleted()}for(var s=function(){return!1},u=t.length,c=l(u,s),a=!1,h=l(u,s),f=Array(u),p=Array(u),d=0;u>d;d++)(function(e){p[e]=new j,p[e].setDisposable(t[e].subscribe(function(t){f[e]=t,i(e)},r.onError.bind(r),function(){o(e)}))})(d);return new R(p)})};oe.concat=function(){var t=C.call(arguments,0);return t.unshift(this),Ee.apply(this,t)};var Ee=le.concat=function(){var t=h(arguments,0);return ne(t).concat()};oe.concatObservable=oe.concatAll=function(){return this.merge(1)},oe.merge=function(t){if("number"!=typeof t)return xe(this,t);var e=this;return new De(function(n){var r=0,i=new R,o=!1,s=[],u=function(t){var e=new j;i.add(e),e.setDisposable(t.subscribe(n.onNext.bind(n),n.onError.bind(n),function(){var t;i.remove(e),s.length>0?(t=s.shift(),u(t)):(r--,o&&0===r&&n.onCompleted())}))};return i.add(e.subscribe(function(e){t>r?(r++,u(e)):s.push(e)},n.onError.bind(n),function(){o=!0,0===r&&n.onCompleted()})),i})};var xe=le.merge=function(){var t,e;return arguments[0]?arguments[0].now?(t=arguments[0],e=C.call(arguments,1)):(t=z,e=C.call(arguments,0)):(t=z,e=C.call(arguments,1)),Array.isArray(e[0])&&(e=e[0]),be(e,t).mergeObservable()};oe.mergeObservable=oe.mergeAll=function(){var t=this;return new De(function(e){var n=new R,r=!1,i=new j;return n.add(i),i.setDisposable(t.subscribe(function(t){var i=new j;n.add(i),i.setDisposable(t.subscribe(function(t){e.onNext(t)},e.onError.bind(e),function(){n.remove(i),r&&1===n.length&&e.onCompleted()}))},e.onError.bind(e),function(){r=!0,1===n.length&&e.onCompleted()})),n})},oe.onErrorResumeNext=function(t){if(!t)throw Error("Second observable is required");return Ce([this,t])};var Ce=le.onErrorResumeNext=function(){var t=h(arguments,0);return new De(function(e){var n=0,r=new P,i=z.scheduleRecursive(function(i){var o,s;t.length>n?(o=t[n++],s=new j,r.setDisposable(s),s.setDisposable(o.subscribe(e.onNext.bind(e),function(){i()},function(){i()}))):e.onCompleted()});return new R(r,i)})};oe.skipUntil=function(t){var e=this;return new De(function(n){var r=!1,i=new R(e.subscribe(function(t){r&&n.onNext(t)},n.onError.bind(n),function(){r&&n.onCompleted()})),o=new j;return i.add(o),o.setDisposable(t.subscribe(function(){r=!0,o.dispose()},n.onError.bind(n),function(){o.dispose()})),i})},oe.switchLatest=function(){var t=this;return new De(function(e){var n=!1,r=new P,i=!1,o=0,s=t.subscribe(function(t){var s=new j,u=++o;n=!0,r.setDisposable(s),s.setDisposable(t.subscribe(function(t){o===u&&e.onNext(t)},function(t){o===u&&e.onError(t)},function(){o===u&&(n=!1,i&&e.onCompleted())}))},e.onError.bind(e),function(){i=!0,n||e.onCompleted()});return new R(s,r)})},oe.takeUntil=function(t){var e=this;return new De(function(r){return new R(e.subscribe(r),t.subscribe(r.onCompleted.bind(r),r.onError.bind(r),n))})},oe.zip=function(){if(Array.isArray(arguments[0]))return b.apply(this,arguments);var t=this,n=C.call(arguments),i=n.pop();return n.unshift(t),new De(function(o){function s(t){a[t]=!0,a.every(function(t){return t})&&o.onCompleted()}for(var u=n.length,c=l(u,function(){return[]}),a=l(u,function(){return!1}),h=function(n){var s,u;if(c.every(function(t){return t.length>0})){try{u=c.map(function(t){return t.shift()}),s=i.apply(t,u)}catch(h){return o.onError(h),e}o.onNext(s)}else a.filter(function(t,e){return e!==n}).every(r)&&o.onCompleted()},f=Array(u),p=0;u>p;p++)(function(t){f[t]=new j,f[t].setDisposable(n[t].subscribe(function(e){c[t].push(e),h(t)},o.onError.bind(o),function(){s(t)}))})(p);return new R(f)})},le.zip=function(){var t=C.call(arguments,0),e=t.shift();return e.zip.apply(e,t)},le.zipArray=function(){var t=C.call(arguments);return new De(function(n){function i(t){if(u.every(function(t){return t.length>0})){var i=u.map(function(t){return t.shift()});n.onNext(i)}else if(c.filter(function(e,n){return n!==t}).every(r))return n.onCompleted(),e}function o(t){return c[t]=!0,c.every(r)?(n.onCompleted(),e):e}for(var s=t.length,u=l(s,function(){return[]}),c=l(s,function(){return!1}),a=Array(s),h=0;s>h;h++)(function(e){a[e]=new j,a[e].setDisposable(t[e].subscribe(function(t){u[e].push(t),i(e)},n.onError.bind(n),function(){o(e)}))})(h);var f=new R(a);return f.add(q(function(){for(var t=0,e=u.length;e>t;t++)u[t]=[]})),f})},oe.asObservable=function(){var t=this;return new De(function(e){return t.subscribe(e)})},oe.bufferWithCount=function(t,n){return n===e&&(n=t),this.windowWithCount(t,n).selectMany(function(t){return t.toArray()}).where(function(t){return t.length>0})},oe.dematerialize=function(){var t=this;return new De(function(e){return t.subscribe(function(t){return t.accept(e)},e.onError.bind(e),e.onCompleted.bind(e))})},oe.distinctUntilChanged=function(t,n){var i=this;return t||(t=r),n||(n=o),new De(function(r){var o,s=!1;return i.subscribe(function(i){var u,c=!1;try{u=t(i)}catch(a){return r.onError(a),e}if(s)try{c=n(o,u)}catch(a){return r.onError(a),e}s&&c||(s=!0,o=u,r.onNext(i))},r.onError.bind(r),r.onCompleted.bind(r))})},oe.doAction=function(t,e,n){var r,i=this;return"function"==typeof t?r=t:(r=t.onNext.bind(t),e=t.onError.bind(t),n=t.onCompleted.bind(t)),new De(function(t){return i.subscribe(function(e){try{r(e)}catch(n){t.onError(n)}t.onNext(e)},function(n){if(e){try{e(n)}catch(r){t.onError(r)}t.onError(n)}else t.onError(n)},function(){if(n){try{n()}catch(e){t.onError(e)}t.onCompleted()}else t.onCompleted()})})},oe.finallyAction=function(t){var e=this;return new De(function(n){var r=e.subscribe(n);return q(function(){try{r.dispose()}catch(e){throw e}finally{t()}})})},oe.ignoreElements=function(){var t=this;return new De(function(e){return t.subscribe(n,e.onError.bind(e),e.onCompleted.bind(e))})},oe.materialize=function(){var t=this;return new De(function(e){return t.subscribe(function(t){e.onNext(Q(t))},function(t){e.onNext(X(t)),e.onCompleted()},function(){e.onNext(Y()),e.onCompleted()})})},oe.repeat=function(t){return ee(this,t).concat()},oe.retry=function(t){return ee(this,t).catchException()},oe.scan=function(){var t,e,n=!1;2===arguments.length?(t=arguments[0],e=arguments[1],n=!0):e=arguments[0];var r=this;return pe(function(){var i,o=!1;return r.select(function(r){return o?i=e(i,r):(i=n?e(t,r):r,o=!0),i})})},oe.skipLast=function(t){var e=this;return new De(function(n){var r=[];return e.subscribe(function(e){r.push(e),r.length>t&&n.onNext(r.shift())},n.onError.bind(n),n.onCompleted.bind(n))})},oe.startWith=function(){var t,e,n=0;return arguments.length&&"now"in Object(arguments[0])?(e=arguments[0],n=1):e=z,t=C.call(arguments,n),ne([be(t,e),this]).concat()},oe.takeLast=function(t,e){return this.takeLastBuffer(t).selectMany(function(t){return be(t,e)})},oe.takeLastBuffer=function(t){var e=this;return new De(function(n){var r=[];return e.subscribe(function(e){r.push(e),r.length>t&&r.shift()},n.onError.bind(n),function(){n.onNext(r),n.onCompleted()})})},oe.windowWithCount=function(t,e){var n=this;if(0>=t)throw Error(E);if(null==e&&(e=t),0>=e)throw Error(E);return new De(function(r){var i=new j,o=new M(i),s=0,u=[],c=function(){var t=new Ne;u.push(t),r.onNext(S(t,o))};return c(),i.setDisposable(n.subscribe(function(n){for(var r,i=0,o=u.length;o>i;i++)u[i].onNext(n);var a=s-t+1;a>=0&&0===a%e&&(r=u.shift(),r.onCompleted()),s++,0===s%e&&c() 2 | },function(t){for(;u.length>0;)u.shift().onError(t);r.onError(t)},function(){for(;u.length>0;)u.shift().onCompleted();r.onCompleted()})),o})},oe.defaultIfEmpty=function(t){var n=this;return t===e&&(t=null),new De(function(e){var r=!1;return n.subscribe(function(t){r=!0,e.onNext(t)},e.onError.bind(e),function(){r||e.onNext(t),e.onCompleted()})})},oe.distinct=function(t,n){var i=this;return t||(t=r),n||(n=u),new De(function(r){var o={};return i.subscribe(function(i){var s,u,c,a=!1;try{s=t(i),u=n(s)}catch(h){return r.onError(h),e}for(c in o)if(u===c){a=!0;break}a||(o[u]=null,r.onNext(i))},r.onError.bind(r),r.onCompleted.bind(r))})},oe.groupBy=function(t,e,n){return this.groupByUntil(t,e,function(){return ve()},n)},oe.groupByUntil=function(t,i,o,s){var c=this;return i||(i=r),s||(s=u),new De(function(r){var u={},a=new R,h=new M(a);return a.add(c.subscribe(function(c){var l,f,p,d,b,v,m,y,w,g;try{v=t(c),m=s(v)}catch(E){for(g in u)u[g].onError(E);return r.onError(E),e}d=!1;try{w=u[m],w||(w=new Ne,u[m]=w,d=!0)}catch(E){for(g in u)u[g].onError(E);return r.onError(E),e}if(d){b=new Se(v,w,h),f=new Se(v,w);try{l=o(f)}catch(E){for(g in u)u[g].onError(E);return r.onError(E),e}r.onNext(b),y=new j,a.add(y);var x=function(){m in u&&(delete u[m],w.onCompleted()),a.remove(y)};y.setDisposable(l.take(1).subscribe(n,function(t){for(g in u)u[g].onError(t);r.onError(t)},function(){x()}))}try{p=i(c)}catch(E){for(g in u)u[g].onError(E);return r.onError(E),e}w.onNext(p)},function(t){for(var e in u)u[e].onError(t);r.onError(t)},function(){for(var t in u)u[t].onCompleted();r.onCompleted()})),h})},oe.select=function(t,n){var r=this;return new De(function(i){var o=0;return r.subscribe(function(s){var u;try{u=t.call(n,s,o++,r)}catch(c){return i.onError(c),e}i.onNext(u)},i.onError.bind(i),i.onCompleted.bind(i))})},oe.map=oe.select,oe.selectMany=oe.flatMap=function(t,e){return e?this.selectMany(function(n){return t(n).select(function(t){return e(n,t)})}):"function"==typeof t?v.call(this,t):v.call(this,function(){return t})},oe.skip=function(t){if(0>t)throw Error(E);var e=this;return new De(function(n){var r=t;return e.subscribe(function(t){0>=r?n.onNext(t):r--},n.onError.bind(n),n.onCompleted.bind(n))})},oe.skipWhile=function(t){var n=this;return new De(function(r){var i=0,o=!1;return n.subscribe(function(n){if(!o)try{o=!t(n,i++)}catch(s){return r.onError(s),e}o&&r.onNext(n)},r.onError.bind(r),r.onCompleted.bind(r))})},oe.take=function(t,e){if(0>t)throw Error(E);if(0===t)return de(e);var n=this;return new De(function(e){var r=t;return n.subscribe(function(t){r>0&&(r--,e.onNext(t),0===r&&e.onCompleted())},e.onError.bind(e),e.onCompleted.bind(e))})},oe.takeWhile=function(t){var n=this;return new De(function(r){var i=0,o=!0;return n.subscribe(function(n){if(o){try{o=t(n,i++)}catch(s){return r.onError(s),e}o?r.onNext(n):r.onCompleted()}},r.onError.bind(r),r.onCompleted.bind(r))})},oe.where=function(t,n){var r=this;return new De(function(i){var o=0;return r.subscribe(function(s){var u;try{u=t.call(n,s,o++,r)}catch(c){return i.onError(c),e}u&&i.onNext(s)},i.onError.bind(i),i.onCompleted.bind(i))})},oe.filter=oe.where;var De=w.Internals.AnonymousObservable=function(t){function n(r){function i(t){var e=new Ae(t);if(B.scheduleRequired())B.schedule(function(){try{e.disposable(r(e))}catch(t){if(!e.fail(t))throw t}});else try{e.disposable(r(e))}catch(n){if(!e.fail(n))throw n}return e}return this instanceof n?(t.call(this,i),e):new n(r)}return D(n,t),n}(le),Ae=function(t){function e(e){t.call(this),this.observer=e,this.m=new j}D(e,t);var n=e.prototype;return n.next=function(t){var e=!1;try{this.observer.onNext(t),e=!0}catch(n){throw n}finally{e||this.dispose()}},n.error=function(t){try{this.observer.onError(t)}catch(e){throw e}finally{this.dispose()}},n.completed=function(){try{this.observer.onCompleted()}catch(t){throw t}finally{this.dispose()}},n.disposable=function(t){return this.m.disposable(t)},n.dispose=function(){t.prototype.dispose.call(this),this.m.dispose()},e}(se),Se=function(t){function e(t){return this.underlyingObservable.subscribe(t)}function n(n,r,i){t.call(this,e),this.key=n,this.underlyingObservable=i?new De(function(t){return new R(i.getDisposable(),r.subscribe(t))}):r}return D(n,t),n}(le),_e=function(t,e){this.subject=t,this.observer=e};_e.prototype.dispose=function(){if(!this.subject.isDisposed&&null!==this.observer){var t=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(t,1),this.observer=null}};var Ne=w.Subject=function(t){function e(t){return a.call(this),this.isStopped?this.exception?(t.onError(this.exception),T):(t.onCompleted(),T):(this.observers.push(t),new _e(this,t))}function n(){t.call(this,e),this.isDisposed=!1,this.isStopped=!1,this.observers=[]}return D(n,t),A(n.prototype,re,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){if(a.call(this),!this.isStopped){var t=this.observers.slice(0);this.isStopped=!0;for(var e=0,n=t.length;n>e;e++)t[e].onCompleted();this.observers=[]}},onError:function(t){if(a.call(this),!this.isStopped){var e=this.observers.slice(0);this.isStopped=!0,this.exception=t;for(var n=0,r=e.length;r>n;n++)e[n].onError(t);this.observers=[]}},onNext:function(t){if(a.call(this),!this.isStopped)for(var e=this.observers.slice(0),n=0,r=e.length;r>n;n++)e[n].onNext(t)},dispose:function(){this.isDisposed=!0,this.observers=null}}),n.create=function(t,e){return new Re(t,e)},n}(le),We=w.AsyncSubject=function(t){function e(t){if(a.call(this),!this.isStopped)return this.observers.push(t),new _e(this,t);var e=this.exception,n=this.hasValue,r=this.value;return e?t.onError(e):n?(t.onNext(r),t.onCompleted()):t.onCompleted(),T}function n(){t.call(this,e),this.isDisposed=!1,this.isStopped=!1,this.value=null,this.hasValue=!1,this.observers=[],this.exception=null}return D(n,t),A(n.prototype,re,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){var t,e,n;if(a.call(this),!this.isStopped){var r=this.observers.slice(0);this.isStopped=!0;var i=this.value,o=this.hasValue;if(o)for(e=0,n=r.length;n>e;e++)t=r[e],t.onNext(i),t.onCompleted();else for(e=0,n=r.length;n>e;e++)r[e].onCompleted();this.observers=[]}},onError:function(t){if(a.call(this),!this.isStopped){var e=this.observers.slice(0);this.isStopped=!0,this.exception=t;for(var n=0,r=e.length;r>n;n++)e[n].onError(t);this.observers=[]}},onNext:function(t){a.call(this),this.isStopped||(this.value=t,this.hasValue=!0)},dispose:function(){this.isDisposed=!0,this.observers=null,this.exception=null,this.value=null}}),n}(le),Re=function(t){function e(t){return this.observable.subscribe(t)}function n(n,r){t.call(this,e),this.observer=n,this.observable=r}return D(n,t),A(n.prototype,re,{onCompleted:function(){this.observer.onCompleted()},onError:function(t){this.observer.onError(t)},onNext:function(t){this.observer.onNext(t)}}),n}(le);return"function"==typeof define&&"object"==typeof define.amd&&define.amd?(t.Rx=w,define(function(){return w})):(m?"object"==typeof module&&module&&module.exports==m?module.exports=w:m=w:t.Rx=w,e)})(this); -------------------------------------------------------------------------------- /resources/private/js/rx.time.min.js: -------------------------------------------------------------------------------- 1 | /*Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | Microsoft Open Technologies would like to thank its contributors, a list. 3 | of whom are at http://aspnetwebstack.codeplex.com/wikipage?title=Contributors.. 4 | Licensed under the Apache License, Version 2.0 (the "License"); you. 5 | may not use this file except in compliance with the License. You may. 6 | obtain a copy of the License at. 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0. 9 | 10 | Unless required by applicable law or agreed to in writing, software. 11 | distributed under the License is distributed on an "AS IS" BASIS,. 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or. 13 | implied. See the License for the specific language governing permissions. 14 | and limitations under the License.. 15 | */ 16 | (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 w(e,t){return new o(function(n){return t.scheduleWithAbsolute(e,function(){n.onNext(0),n.onCompleted()})})}function E(e,t,n){var r=b(t);return new o(function(t){var i=0,s=e;return n.scheduleRecursiveWithAbsolute(s,function(e){var o;r>0&&(o=n.now(),s+=r,s<=o&&(s=o+r)),t.onNext(i++),e(s)})})}function S(e,t){var n=b(e);return new o(function(e){return t.scheduleWithRelative(n,function(){e.onNext(0),e.onCompleted()})})}function x(e,t,n){return e===t?new o(function(e){return n.schedulePeriodicWithState(0,t,function(t){return e.onNext(t),t+1})}):u(function(){return E(n.now()+e,t,n)})}function C(e,t){var n=this;return new o(function(r){var i=!1,s=new p,o=null,u=[],a=!1,f;return f=n.materialize().timestamp(t).subscribe(function(n){var f,l;n.value.kind==="E"?(u=[],u.push(n),o=n.value.exception,l=!a):(u.push({value:n.value,timestamp:n.timestamp+e}),l=!i,i=!0),l&&(o!==null?r.onError(o):(f=new h,s.disposable(f),f.disposable(t.scheduleRecursiveWithRelative(e,function(e){var n,s,f,l;if(o!==null)return;a=!0;do f=null,u.length>0&&u[0].timestamp-t.now()<=0&&(f=u.shift().value),f!==null&&f.accept(r);while(f!==null);l=!1,s=0,u.length>0?(l=!0,s=Math.max(0,u[0].timestamp-t.now())):i=!1,n=o,a=!1,n!==null?r.onError(n):l&&e(s)}))))}),new d(f,s)})}function k(e,t){var n=this;return u(function(){var r=e-t.now();return C.call(n,r,t)})}function L(e,t){return new o(function(n){function o(){s&&(s=!1,n.onNext(i)),r&&n.onCompleted()}var r,i,s;return new d(e.subscribe(function(e){s=!0,i=e},n.onError.bind(n),function(){r=!0}),t.subscribe(o,n.onError.bind(n),o))})}var i=n.Observable,s=i.prototype,o=n.Internals.AnonymousObservable,u=i.defer,a=i.empty,f=i.throwException,l=i.fromArray,c=n.Scheduler.timeout,h=n.SingleAssignmentDisposable,p=n.SerialDisposable,d=n.CompositeDisposable,v=n.RefCountDisposable,m=n.Subject,g=n.Internals.BinaryObserver,y=n.Internals.addRef,b=n.Scheduler.normalize,T=i.interval=function(e,t){return t||(t=c),x(e,e,t)},N=i.timer=function(e,t,n){var i;return n||(n=c),t!==r&&typeof t=="number"?i=t:t!==r&&typeof t=="object"&&(n=t),e instanceof Date&&i===r?w(e.getTime(),n):e instanceof Date&&i!==r?(i=t,E(e.getTime(),i,n)):i===r?S(e,n):x(e,i,n)};return s.delay=function(e,t){return t||(t=c),e instanceof Date?k.call(this,e.getTime(),t):C.call(this,e,t)},s.throttle=function(e,t){t||(t=c);var n=this;return new o(function(r){var i=new p,s=!1,o=0,u,a=null;return u=n.subscribe(function(n){var u,f;s=!0,a=n,o++,u=o,f=new h,i.disposable(f),f.disposable(t.scheduleWithRelative(e,function(){s&&o===u&&r.onNext(a),s=!1}))},function(e){i.dispose(),r.onError(e),s=!1,o++},function(){i.dispose(),s&&r.onNext(a),r.onCompleted(),s=!1,o++}),new d(u,i)})},s.windowWithTime=function(e,t,n){var i=this,s;return t===r&&(s=e),n===r&&(n=c),typeof t=="number"?s=t:typeof t=="object"&&(s=e,n=t),new o(function(t){var r,o,u=s,a=e,f=[],l,c=new p,g=0;return o=new d(c),l=new v(o),r=function(){var e,i,o,p,d;o=new h,c.disposable(o),i=!1,e=!1,a===u?(i=!0,e=!0):a0&&s-i[0].interval>=e)r.onNext(i.shift().value)},r.onError.bind(r),function(){var n=t.now();while(i.length>0&&n-i[0].interval>=e)r.onNext(i.shift().value);r.onCompleted()})})},s.takeLastWithTime=function(e,t,n){return this.takeLastBufferWithTime(e,t).selectMany(function(e){return l(e,n)})},s.takeLastBufferWithTime=function(e,t){var n=this;return t||(t=c),new o(function(r){var i=[];return n.subscribe(function(n){var r=t.now();i.push({interval:r,value:n});while(i.length>0&&r-i[0].interval>=e)i.shift()},r.onError.bind(r),function(){var n=t.now(),s=[];while(i.length>0){var o=i.shift();n-o.interval<=e&&s.push(o.value)}r.onNext(s),r.onCompleted()})})},s.takeWithTime=function(e,t){var n=this;return t||(t=c),new o(function(r){var i=t.scheduleWithRelative(e,function(){r.onCompleted()});return new d(i,n.subscribe(r))})},s.skipWithTime=function(e,t){var n=this;return t||(t=c),new o(function(r){var i=!1,s=t.scheduleWithRelative(e,function(){i=!0}),o=n.subscribe(function(e){i&&r.onNext(e)},r.onError.bind(r),r.onCompleted.bind(r));return new d(s,o)})},s.skipUntilWithTime=function(e,t){t||(t=c);var n=this;return new o(function(r){var i=!1,s=t.scheduleWithAbsolute(e,function(){i=!0}),o=n.subscribe(function(e){i&&r.onNext(e)},r.onError.bind(r),r.onCompleted.bind(r));return new d(s,o)})},s.takeUntilWithTime=function(e,t){t||(t=c);var n=this;return new o(function(r){return new d(t.scheduleWithAbsolute(e,function(){r.onCompleted()}),n.subscribe(r))})},n}); -------------------------------------------------------------------------------- /resources/private/unit-test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is just a dummy HTML file with which to load the unit tests. 4 | This file could be changed to include HTML for the tests to use 5 | during their operation. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /runners/phantomjs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env phantomjs 2 | 3 | var page = require("webpage").create(), 4 | sys = require("system"); 5 | 6 | page.onConsoleMessage = function(msg) { 7 | console.log(msg); 8 | }; 9 | 10 | page.onCallback = function(msg) { 11 | if (msg.cmd === "write") { 12 | sys.stdout.write(msg.data); 13 | sys.stdout.flush(); 14 | } else if (msg.cmd === "quit") { 15 | phantom.exit(msg.data); 16 | } 17 | }; 18 | 19 | page.onLoadFinished = function() { 20 | 21 | var scripts = sys.args.slice(1); 22 | scripts.forEach(function(script){ 23 | console.log("Injecting " + script); 24 | page.injectJs(script); 25 | }); 26 | page.evaluate(function() { 27 | error.environment.in_repl = false; 28 | cljs.core.string_print = function(s) { 29 | window.callPhantom({cmd: "write", data: s}); 30 | }; 31 | error.test.run_tests(); 32 | }); 33 | }; 34 | 35 | page.open("about:blank"); 36 | -------------------------------------------------------------------------------- /src-cljs/rx_cljs/observable.cljs: -------------------------------------------------------------------------------- 1 | (ns rx-cljs.observable 2 | (:refer-clojure :exclude [map reduce take])) 3 | 4 | 5 | ;; creating 6 | (defn create [f] 7 | (.create js/Rx.Observable f)) 8 | 9 | (defn return-value [v] 10 | (.returnValue js/Rx.Observable v)) 11 | 12 | (defn from-array [coll] 13 | (.fromArray js/Rx.Observable (clj->js coll))) 14 | 15 | (defn interval [ms] 16 | (.interval js/Rx.Observable ms)) 17 | 18 | 19 | ;; observables 20 | (defn start-with [observable n] 21 | (.startWith observable n)) 22 | 23 | (defn take [observable n] 24 | (.take observable n)) 25 | 26 | (defn map [observable f] 27 | (.map observable f)) 28 | 29 | (defn reduce [observable f] 30 | (.reduce observable f)) 31 | 32 | (defn skip [observable n] 33 | (.skip observable n)) 34 | 35 | (defn zip [observable other f] 36 | (.zip observable other f)) 37 | 38 | (defn select-many [observable sel] 39 | (.selectMany observable sel)) 40 | 41 | (defn subscribe [observable f] 42 | (.subscribe observable f)) 43 | 44 | (defn buffer-with-count [observable n] 45 | (.bufferWithCount observable n)) 46 | 47 | ;; connectables 48 | (defn publish [observable] 49 | (.publish observable)) 50 | 51 | (defn connect [observable] 52 | (.connect observable)) 53 | 54 | (defn ref-count [observable] 55 | (.refCount observable)) 56 | 57 | ;; subscriptions 58 | (defn dispose [token] 59 | (.dispose token)) 60 | 61 | ;; observers 62 | (defn on-next [observer v] 63 | (.onNext observer v)) 64 | 65 | (defn on-completed [observer] 66 | (.onCompleted observer)) -------------------------------------------------------------------------------- /test-cljs/rx_cljs/observable_test.cljs: -------------------------------------------------------------------------------- 1 | (ns rx-cljs.observable-test 2 | (:require-macros [error.macros :refer [test is]]) 3 | (:require [error.test] 4 | [rx-cljs.observable :as o])) 5 | 6 | (test "creating observables from a function spec" 7 | (-> (o/create (fn [observer] 8 | (o/on-next observer 50) 9 | (o/on-completed observer) 10 | (fn [] "no-op"))) 11 | (o/subscribe (fn [v] 12 | (is (= 50 v)) 13 | (done))))) 14 | 15 | (test "creating observables from single values" 16 | (-> (o/return-value 50) 17 | (o/subscribe (fn [v] 18 | (is (= 50 v)) 19 | (done))))) 20 | 21 | (test "creating observables from colls" 22 | (let [result (atom [])] 23 | (-> (o/from-array [4 6 8]) 24 | (o/subscribe (fn [v] 25 | (swap! result #(conj % v))))) 26 | (is (= [4 6 8] @result)) 27 | (done))) 28 | 29 | (test "taking" 30 | (let [result (atom [])] 31 | (-> (o/from-array [4 6 8]) 32 | (o/take 2) 33 | (o/subscribe (fn [v] 34 | (swap! result #(conj % v))))) 35 | (is (= [4 6] @result)) 36 | (done))) 37 | 38 | (test "mapping" 39 | (-> (o/return-value 50) 40 | (o/map (fn [v] (* 2 v))) 41 | (o/subscribe (fn [v] 42 | (is (= 100 v)) 43 | (done))))) 44 | 45 | (test "reducing" 46 | (-> (o/from-array [4 6 8]) 47 | (o/map (fn [v] (* 2 v))) 48 | (o/reduce +) 49 | (o/subscribe (fn [v] 50 | (is (= 36 v)) 51 | (done))))) 52 | 53 | (test "skipping" 54 | (-> (o/from-array [4 6 8]) 55 | (o/skip 1) 56 | (o/reduce +) 57 | (o/subscribe (fn [v] 58 | (is (= 14 v)) 59 | (done))))) 60 | 61 | (test "zipping" 62 | (let [obs-1 (o/from-array [1 2 3]) 63 | obs-2 (o/from-array [4 5 6]) 64 | result (atom [])] 65 | (-> (o/zip obs-1 obs-2 (fn [v1 v2] [v1 v2])) 66 | (o/subscribe (fn [v] 67 | (swap! result #(conj % v))))) 68 | (is (= [[1 4] [2 5] [3 6]] @result)) 69 | (done))) 70 | 71 | (test "composing" 72 | (let [project-range (fn [n] 73 | (o/return-value (range n))) 74 | result (atom [])] 75 | 76 | (-> (o/from-array [4 6 8]) 77 | (o/select-many project-range) 78 | (o/subscribe (fn [v] 79 | (swap! result #(conj % v))))) 80 | (is (= ['(0 1 2 3) '(0 1 2 3 4 5) '(0 1 2 3 4 5 6 7)] 81 | @result)) 82 | (done))) 83 | 84 | 85 | (test "interval" 86 | (let [n 10 87 | result (atom [])] 88 | (-> (o/interval 1) 89 | (o/take (inc n)) 90 | (o/subscribe (fn [v] 91 | (if (< (count @result) n) 92 | (swap! result #(conj % v)) 93 | (do (is (= [0 1 2 3 4 5 6 7 8 9] @result)) 94 | (done)))))))) 95 | 96 | (test "publishing a connectable observable" 97 | (let [obs (-> (o/from-array [4 6 8]) 98 | (o/map (fn [v] (* 2 v))) 99 | (o/reduce +) 100 | o/publish)] 101 | (o/subscribe obs (fn [v] 102 | (is (= 36 v)) 103 | (done))) 104 | (o/connect obs))) 105 | 106 | (test "ref-count" 107 | (let [obs (-> (o/from-array [4 6 8]) 108 | (o/map (fn [v] (* 2 v))) 109 | (o/reduce +) 110 | o/publish 111 | o/ref-count)] 112 | (o/subscribe obs (fn [v] 113 | (is (= 36 v)) 114 | (done))))) 115 | 116 | (test "disposing subscriptions" 117 | (let [token (-> (o/interval 200) 118 | (o/subscribe (fn [_] )))] 119 | (is (not (true? (.-isStopped token)))) 120 | (o/dispose token) 121 | (is (true? (.-isStopped token))) 122 | (done))) 123 | 124 | (test "buffers" 125 | (-> (o/from-array (range 10)) 126 | (o/buffer-with-count 2) 127 | (o/subscribe (fn [v] 128 | (is (= [0 1] (js->clj v))) 129 | (done))))) 130 | --------------------------------------------------------------------------------