rx-angular
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "rx-angular", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "rx.angular.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -5,3 +5,3 @@ ;(function (undefined) { | ||
.controller('AppCtrl', function($scope, $http, rx) { | ||
function searchWikipedia (term) { | ||
@@ -20,3 +20,3 @@ var deferred = $http({ | ||
.fromPromise(deferred) | ||
.map(function(response){ return response.data[1]; }); | ||
.map(function(response){ return response.data[1]; }); | ||
} | ||
@@ -29,7 +29,7 @@ | ||
The following code deals with: | ||
Creates a "click" function which is an observable sequence instead of just a function. | ||
Creates a "submit" function which is an observable sequence instead of just a function. | ||
*/ | ||
$scope.$createObservableFunction('click') | ||
.map(function () { return $scope.search; }) | ||
$scope.$createObservableFunction('submit') | ||
.map(function (term) { return term; }) | ||
.flatMapLatest(searchWikipedia) | ||
@@ -36,0 +36,0 @@ .subscribe(function(results) { |
@@ -5,10 +5,14 @@ ;(function (undefined) { | ||
.controller('AppCtrl', function($scope, observeOnScope) { | ||
observeOnScope($scope, 'name').subscribe(function(change) { | ||
$scope.observedChange = change; | ||
$scope.newValue = change.newValue; | ||
$scope.oldValue = change.oldValue; | ||
}); | ||
observeOnScope($scope, 'name') | ||
.map(function(data){ | ||
return data; | ||
}) | ||
.subscribe(function(change) { | ||
$scope.observedChange = change; | ||
$scope.newValue = change.newValue; | ||
$scope.oldValue = change.oldValue; | ||
}); | ||
}); | ||
}.call(this)); |
@@ -25,10 +25,13 @@ module.exports = function (grunt) { | ||
src: [ | ||
'src/license.js', | ||
'src/intro.js', | ||
'src/module.js', | ||
'src/factory.js', | ||
'src/observeonscope.js', | ||
'src/safeApply.js', | ||
'src/$rootScopeExtensions.js', | ||
'src/outro.js' | ||
'src/license.js', | ||
'src/basicheader.js', | ||
'src/intro.js', | ||
'src/module.js', | ||
'src/factory.js', | ||
'src/observeonscope.js', | ||
'src/safeApply.js', | ||
'src/$rootScopeExtensions.js', | ||
'src/observableRuntimeExtensions.js', | ||
'src/scopescheduler.js', | ||
'src/outro.js' | ||
], | ||
@@ -57,21 +60,21 @@ dest: 'rx.angular.js' | ||
grunt.util.spawn({ | ||
cmd: ".nuget/nuget.exe", | ||
args: [ | ||
//specify the .nuspec file | ||
"pack", | ||
"nuget/RxJS-Bridges-Angular/RxJS-Bridges-Angular.nuspec", | ||
cmd: ".nuget/nuget.exe", | ||
args: [ | ||
//specify the .nuspec file | ||
"pack", | ||
"nuget/RxJS-Bridges-Angular/RxJS-Bridges-Angular.nuspec", | ||
//specify where we want the package to be created | ||
"-OutputDirectory", | ||
"nuget", | ||
//specify where we want the package to be created | ||
"-OutputDirectory", | ||
"nuget", | ||
//override the version with whatever is currently defined in package.json | ||
"-Version", | ||
grunt.config.get("pkg").version | ||
] | ||
//override the version with whatever is currently defined in package.json | ||
"-Version", | ||
grunt.config.get("pkg").version | ||
] | ||
}, function (error, result) { | ||
if (error) { | ||
grunt.log.error(error); | ||
grunt.log.error(error); | ||
} else { | ||
grunt.log.write(result); | ||
grunt.log.write(result); | ||
} | ||
@@ -78,0 +81,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Library for bridging between RxJS and AngularJS.", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"homepage": "https://github.com/Reactive-Extensions/rx.angular.js", | ||
@@ -8,0 +8,0 @@ "author": { |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. | ||
;(function (undefined) { | ||
var Rx = window.Rx, | ||
observable = Rx.Observable, | ||
observableProto = observable.prototype, | ||
observableCreate = observable.create, | ||
disposableCreate = Rx.Disposable.create, | ||
SingleAssignmentDisposable = Rx.SingleAssignmentDisposable, | ||
CompositeDisposable = Rx.CompositeDisposable, | ||
Scheduler = Rx.Scheduler, | ||
noop = Rx.helpers.noop; | ||
var objectTypes = { | ||
'boolean': false, | ||
'function': true, | ||
'object': true, | ||
'number': false, | ||
'string': false, | ||
'undefined': false | ||
}; | ||
// Utilities | ||
var toString = Object.prototype.toString, | ||
slice = Array.prototype.slice; | ||
var root = (objectTypes[typeof window] && window) || this; | ||
function isFunction (fn) { | ||
return toString.call(fn) === '[object Function]'; | ||
} | ||
;(function (root, factory) { | ||
var freeExports = typeof exports == 'object' && exports && | ||
(typeof root == 'object' && root && root == root.global && (window = root), exports); | ||
/** Detect free variable `exports` */ | ||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports; | ||
// Because of build optimizers | ||
if (typeof define === 'function' && define.amd) { | ||
define(['rx', 'angular', 'exports'], function (Rx, angular, exports) { | ||
root.Rx = factory(root, exports, Rx, jQuery); | ||
return root.Rx; | ||
}); | ||
} else if (typeof module == 'object' && module && module.exports == freeExports) { | ||
module.exports = factory(root, module.exports, require('rx'), require('angular')); | ||
} else { | ||
root.Rx = factory(root, {}, root.Rx, angular); | ||
} | ||
}(this, function (global, exp, Rx, angular, undefined) { | ||
/** Detect free variable `module` */ | ||
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; | ||
/** | ||
* @ngdoc overview | ||
* @name rx | ||
* | ||
* @description | ||
* The `rx` module contains essential components for reactive extension bindings | ||
* for Angular apps. | ||
* | ||
* Installation of this module is just a cli command away: | ||
* | ||
* <pre> | ||
* bower install rx-angular | ||
* <pre> | ||
* | ||
* Simply declare it as dependency of your app like this: | ||
* | ||
* <pre> | ||
* var app = angular.module('myApp', ['rx']); | ||
* </pre> | ||
*/ | ||
var rxModule = angular.module('rx', []); | ||
/** Detect the popular CommonJS extension `module.exports` */ | ||
var moduleExports = freeModule && freeModule.exports === freeExports && freeExports; | ||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */ | ||
var freeGlobal = objectTypes[typeof global] && global; | ||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) { | ||
root = freeGlobal; | ||
/** | ||
* @ngdoc service | ||
* @name rx.rx | ||
* | ||
* @requires $window | ||
* | ||
* @description | ||
* Factory service that exposes the global `Rx` object to the Angular world. | ||
*/ | ||
rxModule.factory('rx', function($window) { | ||
if(!$window.Rx) { | ||
throw new Error("Rx is not defined!"); | ||
} | ||
return $window.Rx; | ||
}); | ||
// Headers | ||
var Rx = window.Rx, | ||
observable = Rx.Observable, | ||
observableProto = observable.prototype, | ||
observableCreate = observable.create; | ||
/** | ||
* @ngdoc service | ||
* @name rx.observeOnSope | ||
* | ||
* @requires rx.rx | ||
* | ||
* @description | ||
* An observer function that returns a function for a given `scope`, | ||
* `watchExpression` and `objectEquality` object. The returned function | ||
* delegates to an Angular watcher. | ||
* | ||
* @param {object} scope Scope object. | ||
* @param {(string|object)} watchExpression Watch expression. | ||
* @param {boolean} objectEquality Object to compare for object equality. | ||
* | ||
* @return {function} Factory function that creates obersables. | ||
*/ | ||
rxModule.factory('observeOnScope', function(rx) { | ||
return function(scope, watchExpression, objectEquality) { | ||
return rx.Observable.create(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
// Utilities | ||
var toString = {}.toString, | ||
slice = Array.prototype.slice; | ||
// Returns function which disconnects the $watch expression | ||
return scope.$watch(watchExpression, listener, objectEquality); | ||
}); | ||
}; | ||
}); | ||
function isFunction (fn) { | ||
return toString.call(fn) === '[object Function]'; | ||
} | ||
function noop () {} | ||
observableProto.safeApply = function($scope, fn){ | ||
fn = isFunction(fn) ? fn : noop; | ||
/** | ||
* @ngdoc overview | ||
* @name rx | ||
* | ||
* @description | ||
* The `rx` module contains essential components for reactive extension bindings | ||
* for Angular apps. | ||
* | ||
* Installation of this module is just a cli command away: | ||
* | ||
* <pre> | ||
* bower install rx-angular | ||
* <pre> | ||
* | ||
* Simply declare it as dependency of your app like this: | ||
* | ||
* <pre> | ||
* var app = angular.module('myApp', ['rx']); | ||
* </pre> | ||
*/ | ||
var rxModule = angular.module('rx', []); | ||
/** | ||
* @ngdoc service | ||
* @name rx.rx | ||
* | ||
* @requires $window | ||
* | ||
* @description | ||
* Factory service that exposes the global `Rx` object to the Angular world. | ||
*/ | ||
rxModule.factory('rx', function($window) { | ||
if(!$window.Rx) { | ||
throw new Error("Rx is not defined!"); | ||
} | ||
return $window.Rx; | ||
return this.doAction(function(data){ | ||
($scope.$$phase || $scope.$root.$$phase) ? fn(data) : $scope.$apply(function(){ | ||
fn(data); | ||
}); | ||
}); | ||
}; | ||
rxModule.config(['$provide', function($provide) { | ||
/** | ||
* @ngdoc service | ||
* @name rx.$rootScope | ||
* | ||
* @requires $delegate | ||
* | ||
* @description | ||
* `$rootScope` decorator that extends the existing `$rootScope` service | ||
* with additional methods. These methods are Rx related methods, such as | ||
* methods to create observables or observable functions. | ||
*/ | ||
$provide.decorator('$rootScope', ['$delegate', function($delegate) { | ||
/** | ||
* @ngdoc service | ||
* @name rx.observeOnSope | ||
* | ||
* @requires rx.rx | ||
* | ||
* @description | ||
* An observer function that returns a function for a given `scope`, | ||
* `watchExpression` and `objectEquality` object. The returned function | ||
* delegates to an Angular watcher. | ||
* | ||
* @param {object} scope Scope object. | ||
* @param {(string|object)} watchExpression Watch expression. | ||
* @param {boolean} objectEquality Object to compare for object equality. | ||
* | ||
* @return {function} Factory function that creates obersables. | ||
*/ | ||
rxModule.factory('observeOnScope', function(rx) { | ||
return function(scope, watchExpression, objectEquality) { | ||
return rx.Observable.create(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
Object.defineProperties($delegate.constructor.prototype, { | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$toObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$toObservable#value | ||
* | ||
* @description | ||
* Creates an observable from a watchExpression. | ||
* | ||
* @param {(function|string)} watchExpression A watch expression. | ||
* @param {boolean} objectEquality Compare object for equality. | ||
* | ||
* @return {object} Observable. | ||
*/ | ||
value: function(watchExpression, objectEquality) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
// Returns function which disconnects the $watch expression | ||
return scope.$watch(watchExpression, listener, objectEquality); | ||
// Returns function which disconnects the $watch expression | ||
var disposable = Rx.Disposable.create(scope.$watch(watchExpression, listener, objectEquality)); | ||
scope.$on('$destroy', function(){ | ||
disposable.isDisposed || disposable.dispose(); | ||
}); | ||
return disposable; | ||
}); | ||
}; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$eventToObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$eventToObservable#value | ||
* | ||
* @description | ||
* Creates an Observable from an event which is fired on the local $scope. | ||
* Expects an event name as the only input parameter. | ||
* | ||
* @param {string} event name | ||
* | ||
* @return {object} Observable object. | ||
*/ | ||
value: function(eventName) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
function listener () { | ||
observer.onNext({ | ||
'event': arguments[0], | ||
'additionalArguments': slice.call(arguments, 1) | ||
}); | ||
} | ||
observableProto.safeApply = function($scope, fn){ | ||
// Returns function which disconnects from the event binding | ||
var disposable = disposableCreate(scope.$on(eventName, listener)); | ||
fn = isFunction(fn) ? fn : noop; | ||
scope.$on('$destroy', function(){ | ||
disposable.isDisposed || disposable.dispose(); | ||
}); | ||
return this.doAction(function(data){ | ||
($scope.$$phase || $scope.$root.$$phase) ? fn(data) : $scope.$apply(function(){ | ||
fn(data); | ||
return disposable; | ||
}); | ||
}); | ||
}; | ||
rxModule.config(['$provide', function($provide) { | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc service | ||
* @name rx.$rootScope | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction | ||
* | ||
* @requires $delegate | ||
* | ||
* @description | ||
* `$rootScope` decorator that extends the existing `$rootScope` service | ||
* with additional methods. These methods are Rx related methods, such as | ||
* methods to create observables or observable functions. | ||
* Provides a method to create obsersables from functions. | ||
*/ | ||
$provide.decorator('$rootScope', ['$delegate', function($delegate) { | ||
'$createObservableFunction': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$createObservableFunction#value | ||
* | ||
* @description | ||
* Creates an observable from a given function. | ||
* | ||
* @param {string} functionName A function name to observe. | ||
* @param {function} listener A listener function that gets executed. | ||
* | ||
* @return {function} Remove listener function. | ||
*/ | ||
value: function(functionName, listener) { | ||
var scope = this; | ||
Object.defineProperties($delegate.constructor.prototype, { | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$toObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$toObservable#value | ||
* | ||
* @description | ||
* Creates an observable from a watchExpression. | ||
* | ||
* @param {(function|string)} watchExpression A watch expression. | ||
* @param {boolean} objectEquality Compare object for equality. | ||
* | ||
* @return {object} Observable. | ||
*/ | ||
value: function(watchExpression, objectEquality) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
return observableCreate(function (observer) { | ||
scope[functionName] = function () { | ||
if (listener) { | ||
observer.onNext(listener.apply(this, arguments)); | ||
} else if (arguments.length === 1) { | ||
observer.onNext(arguments[0]); | ||
} else { | ||
observer.onNext(arguments); | ||
} | ||
}; | ||
// Returns function which disconnects the $watch expression | ||
var unbind = scope.$watch(watchExpression, listener, objectEquality); | ||
return function () { | ||
// Remove our listener function from the scope. | ||
delete scope[functionName]; | ||
}; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$digestObservables#value | ||
* | ||
* @description | ||
* Digests the specified observables when they produce new values. | ||
* The scope variable specified by the observable's key | ||
* is set to the new value. | ||
* | ||
* @param {object} obj A map where keys are scope properties | ||
* and values are observables. | ||
* | ||
* @return {boolean} Reference to obj. | ||
*/ | ||
'$digestObservables': { | ||
value: function(observables) { | ||
var scope = this; | ||
return angular.map(observables, function(observable, key) { | ||
return observable.digest(scope, key); | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.digestObservables#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
} | ||
}); | ||
var disposable = Rx.Disposable.create(unbind); | ||
return $delegate; | ||
}]); | ||
}]); | ||
scope.$on('$destroy', function(){ | ||
disposable.dispose(); | ||
}); | ||
rxModule.run(['$parse', function($parse) { | ||
return disposable; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$eventToObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$eventToObservable#value | ||
* | ||
* @description | ||
* Creates an Observable from an event which is fired on the local $scope. | ||
* Expects an event name as the only input parameter. | ||
* | ||
* @param {string} event name | ||
* | ||
* @return {object} Observable object. | ||
*/ | ||
value: function(eventName) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
function listener () { | ||
var data = { | ||
'event': arguments[0], | ||
'additionalArguments': slice.call(arguments, 1) | ||
}; | ||
observableProto.digest = function($scope, prop) { | ||
var source = this; | ||
return new AnonymousObservable(function (observer) { | ||
var propSetter = $parse(prop).assign; | ||
observer.onNext(data); | ||
} | ||
var m = new SingleAssignmentDisposable(); | ||
// Returns function which disconnects from the event binding | ||
var unbind = scope.$on(eventName, listener); | ||
m.setDisposable(source.subscribe( | ||
function (e) { | ||
if (!$scope.$$phase) { | ||
$scope.$apply(propSetter($scope, e)); | ||
} | ||
else { | ||
propSetter($scope, e); | ||
} | ||
}, | ||
observer.onError.bind(observer), | ||
observer.onCompleted.bind(observer) | ||
)); | ||
var disposable = Rx.Disposable.create(unbind); | ||
$scope.on('$destroy', function () { | ||
!m.isDisposed && m.dispose(); | ||
}); | ||
scope.$on('$destroy', function(){ | ||
disposable.dispose(); | ||
}); | ||
return m; | ||
}); | ||
}; | ||
}]); | ||
var now = Date.now || (+new Date()); | ||
return disposable; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction | ||
* | ||
* @description | ||
* Provides a method to create obsersables from functions. | ||
*/ | ||
'$createObservableFunction': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$createObservableFunction#value | ||
* | ||
* @description | ||
* Creates an observable from a given function. | ||
* | ||
* @param {string} functionName A function name to observe. | ||
* @param {function} listener A listener function that gets executed. | ||
* | ||
* @return {function} Remove listener function. | ||
*/ | ||
value: function(functionName, listener) { | ||
var scope = this; | ||
var ScopeScheduler = Rx.ScopeScheduler = (function () { | ||
return observableCreate(function (observer) { | ||
scope[functionName] = function () { | ||
if (listener) { | ||
observer.onNext(listener.apply(this, arguments)); | ||
} else if (arguments.length === 1) { | ||
observer.onNext(arguments[0]); | ||
} else { | ||
observer.onNext(arguments); | ||
} | ||
}; | ||
function scheduleNow(state, action) { | ||
var scheduler = this, | ||
disposable = new SingleAssignmentDisposable(); | ||
return function () { | ||
// Remove our listener function from the scope. | ||
delete scope[functionName]; | ||
}; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
} | ||
}); | ||
safeApply(disposable, scheduler, action, state); | ||
return $delegate; | ||
}]); | ||
}]); | ||
return disposable; | ||
} | ||
}.call(this)); | ||
function scheduleRelative(state, dueTime, action) { | ||
var scheduler = this, | ||
dt = Rx.Scheduler.normalize(dueTime); | ||
if (dt === 0) { | ||
return scheduler.scheduleWithState(state, action); | ||
} | ||
var disposable = new SingleAssignmentDisposable(); | ||
var id = setTimeout(function () { | ||
safeApply(disposable, scheduler, action, state); | ||
}, dt); | ||
return new CompositeDisposable(disposable, disposableCreate(function () { | ||
clearTimeout(id); | ||
})); | ||
} | ||
function safeApply(disposable, scheduler, action, state) { | ||
function fn() { | ||
!disposable.isDisposed && disposable.setDisposable(action(scheduler, state)); | ||
} | ||
(scheduler._scope.$$phase || scheduler._scope.$root.$$phase) | ||
? fn() | ||
: scheduler._scope.$apply(function () { fn(); }); | ||
} | ||
function scheduleAbsolute(state, dueTime, action) { | ||
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action); | ||
} | ||
return function (scope) { | ||
var scheduler = new Scheduler(now, scheduleNow, scheduleRelative, scheduleAbsolute); | ||
scheduler._scope = scope; | ||
return scheduler; | ||
} | ||
}()); | ||
return Rx; | ||
})); |
@@ -1,1 +0,1 @@ | ||
(function(){function a(a){return"[object Function]"===l.call(a)}function b(){}var c={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},d=c[typeof window]&&window||this,e=c[typeof exports]&&exports&&!exports.nodeType&&exports,f=c[typeof module]&&module&&!module.nodeType&&module,g=(f&&f.exports===e&&e,c[typeof global]&&global);!g||g.global!==g&&g.window!==g||(d=g);var h=window.Rx,i=h.Observable,j=i.prototype,k=i.create,l={}.toString,m=Array.prototype.slice,n=angular.module("rx",[]);n.factory("rx",function(a){if(!a.Rx)throw new Error("Rx is not defined!");return a.Rx}),n.factory("observeOnScope",function(a){return function(b,c,d){return a.Observable.create(function(a){function e(b,c){a.onNext({oldValue:c,newValue:b})}return b.$watch(c,e,d)})}}),j.safeApply=function(c,d){return d=a(d)?d:b,this.doAction(function(a){c.$$phase||c.$root.$$phase?d(a):c.$apply(function(){d(a)})})},n.config(["$provide",function(a){a.decorator("$rootScope",["$delegate",function(a){return Object.defineProperties(a.constructor.prototype,{$toObservable:{value:function(a,b){var c=this;return k(function(d){function e(a,b){d.onNext({oldValue:b,newValue:a})}var f=c.$watch(a,e,b),g=h.Disposable.create(f);return c.$on("$destroy",function(){g.dispose()}),g})},enumerable:!1},$eventToObservable:{value:function(a){var b=this;return k(function(c){function d(){var a={event:arguments[0],additionalArguments:m.call(arguments,1)};c.onNext(a)}var e=b.$on(a,d),f=h.Disposable.create(e);return b.$on("$destroy",function(){f.dispose()}),f})},enumerable:!1},$createObservableFunction:{value:function(a,b){var c=this;return k(function(d){return c[a]=function(){d.onNext(b?b.apply(this,arguments):1===arguments.length?arguments[0]:arguments)},function(){delete c[a]}})},enumerable:!1}}),a}])}])}).call(this); | ||
function isFunction(a){return"[object Function]"===toString.call(a)}var Rx=window.Rx,observable=Rx.Observable,observableProto=observable.prototype,observableCreate=observable.create,disposableCreate=Rx.Disposable.create,SingleAssignmentDisposable=Rx.SingleAssignmentDisposable,CompositeDisposable=Rx.CompositeDisposable,Scheduler=Rx.Scheduler,noop=Rx.helpers.noop,toString=Object.prototype.toString,slice=Array.prototype.slice;!function(a,b){var c="object"==typeof exports&&exports&&("object"==typeof a&&a&&a==a.global&&(window=a),exports);"function"==typeof define&&define.amd?define(["rx","angular","exports"],function(c,d,e){return a.Rx=b(a,e,c,jQuery),a.Rx}):"object"==typeof module&&module&&module.exports==c?module.exports=b(a,module.exports,require("rx"),require("angular")):a.Rx=b(a,{},a.Rx,angular)}(this,function(a,b,c,d){var e=d.module("rx",[]);e.factory("rx",function(a){if(!a.Rx)throw new Error("Rx is not defined!");return a.Rx}),e.factory("observeOnScope",function(a){return function(b,c,d){return a.Observable.create(function(a){function e(b,c){a.onNext({oldValue:c,newValue:b})}return b.$watch(c,e,d)})}}),observableProto.safeApply=function(a,b){return b=isFunction(b)?b:noop,this.doAction(function(c){a.$$phase||a.$root.$$phase?b(c):a.$apply(function(){b(c)})})},e.config(["$provide",function(a){a.decorator("$rootScope",["$delegate",function(a){return Object.defineProperties(a.constructor.prototype,{$toObservable:{value:function(a,b){var d=this;return observableCreate(function(e){function f(a,b){e.onNext({oldValue:b,newValue:a})}var g=c.Disposable.create(d.$watch(a,f,b));return d.$on("$destroy",function(){g.isDisposed||g.dispose()}),g})},enumerable:!1},$eventToObservable:{value:function(a){var b=this;return observableCreate(function(c){function d(){c.onNext({event:arguments[0],additionalArguments:slice.call(arguments,1)})}var e=disposableCreate(b.$on(a,d));return b.$on("$destroy",function(){e.isDisposed||e.dispose()}),e})},enumerable:!1},$createObservableFunction:{value:function(a,b){var c=this;return observableCreate(function(d){return c[a]=function(){d.onNext(b?b.apply(this,arguments):1===arguments.length?arguments[0]:arguments)},function(){delete c[a]}})},enumerable:!1},$digestObservables:{value:function(a){var b=this;return d.map(a,function(a,c){return a.digest(b,c)})},enumerable:!1}}),a}])}]),e.run(["$parse",function(a){observableProto.digest=function(b,c){var d=this;return new AnonymousObservable(function(e){var f=a(c).assign,g=new SingleAssignmentDisposable;return g.setDisposable(d.subscribe(function(a){b.$$phase?f(b,a):b.$apply(f(b,a))},e.onError.bind(e),e.onCompleted.bind(e))),b.on("$destroy",function(){!g.isDisposed&&g.dispose()}),g})}}]);{var f=Date.now||+new Date;c.ScopeScheduler=function(){function a(a,b){var c=this,e=new SingleAssignmentDisposable;return d(e,c,b,a),e}function b(a,b,e){var f=this,g=c.Scheduler.normalize(b);if(0===g)return f.scheduleWithState(a,e);var h=new SingleAssignmentDisposable,i=setTimeout(function(){d(h,f,e,a)},g);return new CompositeDisposable(h,disposableCreate(function(){clearTimeout(i)}))}function d(a,b,c,d){function e(){!a.isDisposed&&a.setDisposable(c(b,d))}b._scope.$$phase||b._scope.$root.$$phase?e():b._scope.$apply(function(){e()})}function e(a,b,c){return this.scheduleWithRelativeAndState(a,b-this.now(),c)}return function(c){var d=new Scheduler(f,a,b,e);return d._scope=c,d}}()}return c}); |
@@ -1,171 +0,195 @@ | ||
rxModule.config(['$provide', function($provide) { | ||
rxModule.config(['$provide', function($provide) { | ||
/** | ||
* @ngdoc service | ||
* @name rx.$rootScope | ||
* | ||
* @requires $delegate | ||
* | ||
* @description | ||
* `$rootScope` decorator that extends the existing `$rootScope` service | ||
* with additional methods. These methods are Rx related methods, such as | ||
* methods to create observables or observable functions. | ||
*/ | ||
$provide.decorator('$rootScope', ['$delegate', function($delegate) { | ||
Object.defineProperties($delegate.constructor.prototype, { | ||
/** | ||
* @ngdoc service | ||
* @name rx.$rootScope | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable | ||
* | ||
* @requires $delegate | ||
* | ||
* @description | ||
* `$rootScope` decorator that extends the existing `$rootScope` service | ||
* with additional methods. These methods are Rx related methods, such as | ||
* methods to create observables or observable functions. | ||
* Provides a method to create observable methods. | ||
*/ | ||
$provide.decorator('$rootScope', ['$delegate', function($delegate) { | ||
'$toObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$toObservable#value | ||
* | ||
* @description | ||
* Creates an observable from a watchExpression. | ||
* | ||
* @param {(function|string)} watchExpression A watch expression. | ||
* @param {boolean} objectEquality Compare object for equality. | ||
* | ||
* @return {object} Observable. | ||
*/ | ||
value: function(watchExpression, objectEquality) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
Object.defineProperties($delegate.constructor.prototype, { | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$toObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$toObservable#value | ||
* | ||
* @description | ||
* Creates an observable from a watchExpression. | ||
* | ||
* @param {(function|string)} watchExpression A watch expression. | ||
* @param {boolean} objectEquality Compare object for equality. | ||
* | ||
* @return {object} Observable. | ||
*/ | ||
value: function(watchExpression, objectEquality) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
// Returns function which disconnects the $watch expression | ||
var disposable = Rx.Disposable.create(scope.$watch(watchExpression, listener, objectEquality)); | ||
// Returns function which disconnects the $watch expression | ||
var unbind = scope.$watch(watchExpression, listener, objectEquality); | ||
scope.$on('$destroy', function(){ | ||
disposable.isDisposed || disposable.dispose(); | ||
}); | ||
var disposable = Rx.Disposable.create(unbind); | ||
return disposable; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$eventToObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$eventToObservable#value | ||
* | ||
* @description | ||
* Creates an Observable from an event which is fired on the local $scope. | ||
* Expects an event name as the only input parameter. | ||
* | ||
* @param {string} event name | ||
* | ||
* @return {object} Observable object. | ||
*/ | ||
value: function(eventName) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
function listener () { | ||
observer.onNext({ | ||
'event': arguments[0], | ||
'additionalArguments': slice.call(arguments, 1) | ||
}); | ||
} | ||
scope.$on('$destroy', function(){ | ||
disposable.dispose(); | ||
}); | ||
// Returns function which disconnects from the event binding | ||
var disposable = disposableCreate(scope.$on(eventName, listener)); | ||
return disposable; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$toObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable | ||
* | ||
* @description | ||
* Provides a method to create observable methods. | ||
*/ | ||
'$eventToObservable': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$eventToObservable#value | ||
* | ||
* @description | ||
* Creates an Observable from an event which is fired on the local $scope. | ||
* Expects an event name as the only input parameter. | ||
* | ||
* @param {string} event name | ||
* | ||
* @return {object} Observable object. | ||
*/ | ||
value: function(eventName) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
function listener () { | ||
var data = { | ||
'event': arguments[0], | ||
'additionalArguments': slice.call(arguments, 1) | ||
}; | ||
scope.$on('$destroy', function(){ | ||
disposable.isDisposed || disposable.dispose(); | ||
}); | ||
observer.onNext(data); | ||
} | ||
return disposable; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction | ||
* | ||
* @description | ||
* Provides a method to create obsersables from functions. | ||
*/ | ||
'$createObservableFunction': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$createObservableFunction#value | ||
* | ||
* @description | ||
* Creates an observable from a given function. | ||
* | ||
* @param {string} functionName A function name to observe. | ||
* @param {function} listener A listener function that gets executed. | ||
* | ||
* @return {function} Remove listener function. | ||
*/ | ||
value: function(functionName, listener) { | ||
var scope = this; | ||
// Returns function which disconnects from the event binding | ||
var unbind = scope.$on(eventName, listener); | ||
return observableCreate(function (observer) { | ||
scope[functionName] = function () { | ||
if (listener) { | ||
observer.onNext(listener.apply(this, arguments)); | ||
} else if (arguments.length === 1) { | ||
observer.onNext(arguments[0]); | ||
} else { | ||
observer.onNext(arguments); | ||
} | ||
}; | ||
var disposable = Rx.Disposable.create(unbind); | ||
scope.$on('$destroy', function(){ | ||
disposable.dispose(); | ||
}); | ||
return disposable; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$eventToObservable#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction | ||
* | ||
* @description | ||
* Provides a method to create obsersables from functions. | ||
*/ | ||
'$createObservableFunction': { | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$createObservableFunction#value | ||
* | ||
* @description | ||
* Creates an observable from a given function. | ||
* | ||
* @param {string} functionName A function name to observe. | ||
* @param {function} listener A listener function that gets executed. | ||
* | ||
* @return {function} Remove listener function. | ||
*/ | ||
value: function(functionName, listener) { | ||
var scope = this; | ||
return observableCreate(function (observer) { | ||
scope[functionName] = function () { | ||
if (listener) { | ||
observer.onNext(listener.apply(this, arguments)); | ||
} else if (arguments.length === 1) { | ||
observer.onNext(arguments[0]); | ||
} else { | ||
observer.onNext(arguments); | ||
} | ||
}; | ||
return function () { | ||
// Remove our listener function from the scope. | ||
delete scope[functionName]; | ||
}; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
} | ||
return function () { | ||
// Remove our listener function from the scope. | ||
delete scope[functionName]; | ||
}; | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
}, | ||
/** | ||
* @ngdoc function | ||
* @name rx.$rootScope.$digestObservables#value | ||
* | ||
* @description | ||
* Digests the specified observables when they produce new values. | ||
* The scope variable specified by the observable's key | ||
* is set to the new value. | ||
* | ||
* @param {object} obj A map where keys are scope properties | ||
* and values are observables. | ||
* | ||
* @return {boolean} Reference to obj. | ||
*/ | ||
'$digestObservables': { | ||
value: function(observables) { | ||
var scope = this; | ||
return angular.map(observables, function(observable, key) { | ||
return observable.digest(scope, key); | ||
}); | ||
}, | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.digestObservables#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
} | ||
}); | ||
return $delegate; | ||
}]); | ||
return $delegate; | ||
}]); | ||
}]); |
@@ -1,15 +0,15 @@ | ||
/** | ||
* @ngdoc service | ||
* @name rx.rx | ||
* | ||
* @requires $window | ||
* | ||
* @description | ||
* Factory service that exposes the global `Rx` object to the Angular world. | ||
*/ | ||
rxModule.factory('rx', function($window) { | ||
if(!$window.Rx) { | ||
throw new Error("Rx is not defined!"); | ||
} | ||
return $window.Rx; | ||
}); | ||
/** | ||
* @ngdoc service | ||
* @name rx.rx | ||
* | ||
* @requires $window | ||
* | ||
* @description | ||
* Factory service that exposes the global `Rx` object to the Angular world. | ||
*/ | ||
rxModule.factory('rx', function($window) { | ||
if(!$window.Rx) { | ||
throw new Error("Rx is not defined!"); | ||
} | ||
return $window.Rx; | ||
}); |
@@ -1,44 +0,16 @@ | ||
;(function (undefined) { | ||
;(function (root, factory) { | ||
var freeExports = typeof exports == 'object' && exports && | ||
(typeof root == 'object' && root && root == root.global && (window = root), exports); | ||
var objectTypes = { | ||
'boolean': false, | ||
'function': true, | ||
'object': true, | ||
'number': false, | ||
'string': false, | ||
'undefined': false | ||
}; | ||
var root = (objectTypes[typeof window] && window) || this; | ||
/** Detect free variable `exports` */ | ||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports; | ||
/** Detect free variable `module` */ | ||
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; | ||
/** Detect the popular CommonJS extension `module.exports` */ | ||
var moduleExports = freeModule && freeModule.exports === freeExports && freeExports; | ||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */ | ||
var freeGlobal = objectTypes[typeof global] && global; | ||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) { | ||
root = freeGlobal; | ||
} | ||
// Headers | ||
var Rx = window.Rx, | ||
observable = Rx.Observable, | ||
observableProto = observable.prototype, | ||
observableCreate = observable.create; | ||
// Utilities | ||
var toString = {}.toString, | ||
slice = Array.prototype.slice; | ||
function isFunction (fn) { | ||
return toString.call(fn) === '[object Function]'; | ||
} | ||
function noop () {} | ||
// Because of build optimizers | ||
if (typeof define === 'function' && define.amd) { | ||
define(['rx', 'angular', 'exports'], function (Rx, angular, exports) { | ||
root.Rx = factory(root, exports, Rx, jQuery); | ||
return root.Rx; | ||
}); | ||
} else if (typeof module == 'object' && module && module.exports == freeExports) { | ||
module.exports = factory(root, module.exports, require('rx'), require('angular')); | ||
} else { | ||
root.Rx = factory(root, {}, root.Rx, angular); | ||
} | ||
}(this, function (global, exp, Rx, angular, undefined) { |
@@ -1,21 +0,21 @@ | ||
/** | ||
* @ngdoc overview | ||
* @name rx | ||
* | ||
* @description | ||
* The `rx` module contains essential components for reactive extension bindings | ||
* for Angular apps. | ||
* | ||
* Installation of this module is just a cli command away: | ||
* | ||
* <pre> | ||
* bower install rx-angular | ||
* <pre> | ||
* | ||
* Simply declare it as dependency of your app like this: | ||
* | ||
* <pre> | ||
* var app = angular.module('myApp', ['rx']); | ||
* </pre> | ||
*/ | ||
var rxModule = angular.module('rx', []); | ||
/** | ||
* @ngdoc overview | ||
* @name rx | ||
* | ||
* @description | ||
* The `rx` module contains essential components for reactive extension bindings | ||
* for Angular apps. | ||
* | ||
* Installation of this module is just a cli command away: | ||
* | ||
* <pre> | ||
* bower install rx-angular | ||
* <pre> | ||
* | ||
* Simply declare it as dependency of your app like this: | ||
* | ||
* <pre> | ||
* var app = angular.module('myApp', ['rx']); | ||
* </pre> | ||
*/ | ||
var rxModule = angular.module('rx', []); |
/** | ||
* @ngdoc service | ||
* @name rx.observeOnSope | ||
* | ||
* @requires rx.rx | ||
* | ||
* @description | ||
* An observer function that returns a function for a given `scope`, | ||
* `watchExpression` and `objectEquality` object. The returned function | ||
* delegates to an Angular watcher. | ||
* | ||
* @param {object} scope Scope object. | ||
* @param {(string|object)} watchExpression Watch expression. | ||
* @param {boolean} objectEquality Object to compare for object equality. | ||
* | ||
* @return {function} Factory function that creates obersables. | ||
*/ | ||
rxModule.factory('observeOnScope', function(rx) { | ||
return function(scope, watchExpression, objectEquality) { | ||
return rx.Observable.create(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
* @ngdoc service | ||
* @name rx.observeOnSope | ||
* | ||
* @requires rx.rx | ||
* | ||
* @description | ||
* An observer function that returns a function for a given `scope`, | ||
* `watchExpression` and `objectEquality` object. The returned function | ||
* delegates to an Angular watcher. | ||
* | ||
* @param {object} scope Scope object. | ||
* @param {(string|object)} watchExpression Watch expression. | ||
* @param {boolean} objectEquality Object to compare for object equality. | ||
* | ||
* @return {function} Factory function that creates obersables. | ||
*/ | ||
rxModule.factory('observeOnScope', function(rx) { | ||
return function(scope, watchExpression, objectEquality) { | ||
return rx.Observable.create(function (observer) { | ||
// Create function to handle old and new Value | ||
function listener (newValue, oldValue) { | ||
observer.onNext({ oldValue: oldValue, newValue: newValue }); | ||
} | ||
// Returns function which disconnects the $watch expression | ||
return scope.$watch(watchExpression, listener, objectEquality); | ||
}); | ||
}; | ||
}); | ||
// Returns function which disconnects the $watch expression | ||
return scope.$watch(watchExpression, listener, objectEquality); | ||
}); | ||
}; | ||
}); |
@@ -1,1 +0,2 @@ | ||
}.call(this)); | ||
return Rx; | ||
})); |
@@ -1,10 +0,10 @@ | ||
observableProto.safeApply = function($scope, fn){ | ||
observableProto.safeApply = function($scope, fn){ | ||
fn = isFunction(fn) ? fn : noop; | ||
fn = isFunction(fn) ? fn : noop; | ||
return this.doAction(function(data){ | ||
($scope.$$phase || $scope.$root.$$phase) ? fn(data) : $scope.$apply(function(){ | ||
fn(data); | ||
}); | ||
}); | ||
}; | ||
return this.doAction(function(data){ | ||
($scope.$$phase || $scope.$root.$$phase) ? fn(data) : $scope.$apply(function(){ | ||
fn(data); | ||
}); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
887907
45
1115
2