UNPKG

rx-angular

Version:
3 lines 6.82 kB
/* Copyright (c) Microsoft. All rights reserved. See License.txt in the project root for license information.*/ !function(a,b){var c={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},a=c[typeof window]&&window||this,d=c[typeof exports]&&exports&&!exports.nodeType&&exports,e=c[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,c[typeof global]&&global);!f||f.global!==f&&f.window!==f||(a=f),"function"==typeof define&&define.amd?define(["rx","angular","exports"],function(c,d,e){return a.Rx=b(a,e,c,d),a.Rx}):"object"==typeof module&&module&&module.exports==d?module.exports=b(a,module.exports,require("rx"),require("angular")):a.Rx=b(a,{},a.Rx,a.angular)}(this,function(a,b,c,d,e){function f(a){return function(){try{return a.apply(this,arguments)}catch(b){return i.e=b,i}}}function g(a){if(!d.isFunction(a))throw new TypeError("fn must be a function");return f(a)}function h(){}var i={e:{}},j=d.module("rx",[]);j.factory("rx",["$window",function(a){a.Rx||(a.Rx=c);var b=function(a){function b(b,c,d){this._self=b,this._name=c,this._fn=d,a.call(this)}function e(a,b){this._self=a,this._name=b,this.isDisposed=!1}return c.internals.inherits(b,a),b.prototype.subscribeCore=function(a){var b=this._fn;return this._self[this._name]=function(){for(var c=arguments.length,e=new Array(c),f=0;c>f;f++)e[f]=arguments[f];if(d.isFunction(b)){var h=g(b).apply(this,e);if(h===i)return a.onError(h.e);a.onNext(h)}else 1===e.length?a.onNext(e[0]):a.onNext(e)},new e(this._self,this._name)},e.prototype.dispose=function(){this.isDisposed||(this.isDisposed=!0,delete this._self[this._name])},b}(c.ObservableBase);return c.createObservableFunction=function(a,c,d){return new b(a,c,d).publish().refCount()},a.Rx}]),j.factory("observeOnScope",["rx",function(a){var b=function(b){function c(a,c,d){this._scope=a,this._expr=c,this._eq=d,b.call(this)}function d(a){return function(b,c){a.onNext({oldValue:c,newValue:b})}}function e(a){this._fn=a,this.isDisposed=!1}return a.internals.inherits(c,b),c.prototype.subscribeCore=function(a){return new e(this._scope.$watch(this._expr,d(a),this._eq))},e.prototype.dispose=function(){this.isDisposed||(this._fn(),this.isDisposed=!0)},c}(a.ObservableBase);return function(a,c,d){return new b(a,c,d)}}]),c.Observable.prototype.safeApply=function(a,b,c,e){return b=d.isFunction(b)?b:h,c=d.isFunction(c)?c:h,e=d.isFunction(e)?e:h,this.takeWhile(function(){return!a.$$destroyed}).tap(function(c){a.$$phase||a.$root.$$phase?b(c):a.$apply(function(){b(c)})},function(b){a.$$phase||a.$root.$$phase?c(b):a.$apply(function(){c(b)})},function(){a.$$phase||a.$root.$$phase?e():a.$apply(function(){e()})})},j.config(["$provide",function(a){a.decorator("$rootScope",["$delegate","rx",function(a,b){return Object.defineProperties(a.constructor.prototype,{$toObservable:{value:function(a,c){var d=this;return b.Observable.create(function(e){function f(a,b){e.onNext({oldValue:b,newValue:a})}var g=b.Disposable.create(d.$watch(a,f,c));return d.$on("$destroy",function(){g.dispose()}),g}).publish().refCount()},enumerable:!1,configurable:!0,writable:!0},$toObservableCollection:{value:function(a){var c=this;return b.Observable.create(function(d){function e(a,b){d.onNext({oldValue:b,newValue:a})}var f=b.Disposable.create(c.$watchCollection(a,e));return c.$on("$destroy",function(){f.dispose()}),f}).publish().refCount()},enumerable:!1,configurable:!0,writable:!0},$toObservableGroup:{value:function(a){var c=this;return b.Observable.create(function(d){function e(a,b){d.onNext({oldValue:b,newValue:a})}var f=b.Disposable.create(c.$watchGroup(a,e));return c.$on("$destroy",function(){f.dispose()}),f}).publish().refCount()},enumerable:!1,configurable:!0,writable:!0},$eventToObservable:{value:function(a,c){var e=this;return b.Observable.create(function(f){function h(){for(var a=arguments.length,b=new Array(a),e=0;a>e;e++)b[e]=arguments[e];if(d.isFunction(c)){var h=g(c).apply(null,b);if(h===i)return f.onError(h.e);f.onNext(h)}else 1===b.length?f.onNext(b[0]):f.onNext(b)}var j=b.Disposable.create(e.$on(a,h));return e.$on("$destroy",function(){j.dispose()}),j}).publish().refCount()},enumerable:!1,configurable:!0,writable:!0},$createObservableFunction:{value:function(a,c){return b.createObservableFunction(this,a,c)},enumerable:!1,configurable:!0,writable:!0},$digestObservables:{value:function(a){var c=this;return b.Observable.pairs(a).flatMap(function(a){return a[1].digest(c,a[0]).map(function(b){return{observable:a[1],expression:a[0],value:b}})}).publish().refCount()},enumerable:!1,configurable:!0,writable:!0}}),a}])}]),j.run(["$parse",function(a){var b=function(b){function e(a,c,d){this.source=a,this.$scope=c,this.prop=d,b.call(this)}return c.internals.inherits(e,b),e.prototype.subscribeCore=function(b){var e=a(this.prop).assign;if(!e)return b.onError(new Error("Property or expression is not assignable."));var f=new c.SingleAssignmentDisposable;return f.setDisposable(this.source.subscribe(new d(b,this.$scope,e))),this.$scope.$on("$destroy",function(){f.dispose()}),f},e}(c.ObservableBase),d=function(a){function b(b,c,d){this.o=b,this.$scope=c,this.propSetter=d,a.call(this)}return c.internals.inherits(b,a),b.prototype.next=function(a){if(this.$scope.$$phase)this.propSetter(this.$scope,a);else{var b=this;this.$scope.$apply(function(){b.propSetter(b.$scope,a)})}this.o.onNext(a)},b.prototype.error=function(a){this.o.onError(a)},b.prototype.completed=function(){this.o.onCompleted()},b}(c.internals.AbstractObserver);c.Observable.prototype.digest=function(a,c){return new b(this,a,c)}}]);c.ScopeScheduler=function(a){function b(b){this.$scope=b,a.call(this)}return c.internals.inherits(b,a),b.prototype.schedule=function(a,b){if(this.$scope.$$destroyed)return c.Disposable.empty;var d=new c.SingleAssignmentDisposable,e=this.$scope;e.$$phase||e.$root.$$phase?d.setDisposable(c.Disposable._fixup(a(b))):e.$apply.call(e,function(){d.setDisposable(c.Disposable._fixup(a(b)))})},b.prototype._scheduleFuture=function(a,b,d){if(this.$scope.$$destroyed)return c.Disposable.empty;var e=new c.SingleAssignmentDisposable,f=this.$scope,g=setTimeout(function(){return f.$$destroyed||e.isDisposed?clearTimeout(g):void(f.$$phase||f.$root.$$phase?e.setDisposable(c.Disposable._fixup(a(d))):f.$apply.call(f,function(){e.setDisposable(c.Disposable._fixup(a(d)))}))},b);return new c.BinaryDisposable(e,c.Disposable.create(function(){clearTimeout(g)}))},b.prototype.schedulePeriodic=function(a,b,d){if(this.$scope.$$destroyed)return c.Disposable.empty;b=c.Scheduler.normalize(b);var e=this.$scope,f=a,g=setInterval(function(){return e.$$destroyed?clearInterval(g):void(e.$$phase||e.$root.$$phase?f=d(f):e.$apply.call(e,function(){f=d(f)}))},b);return c.Disposable.create(function(){clearInterval(g)})},b}(c.Scheduler);return c}); //# sourceMappingURL=rx.angular.map