rx-angular
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "rx-angular", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "rx.angular.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -0,3 +1,11 @@ | ||
<a name="v0.0.3"></a> | ||
### v0.0.3 (2014-06-06) | ||
#### Features | ||
* **$rootScopeExtensions:** adds `$eventToObservable` function ([cc6aca69](https://github.com/Reactive-Extensions/rx.angular.js/commit/cc6aca69a8eada2f8c57ee66beb6e8f8ab58615d), closes [#16](https://github.com/Reactive-Extensions/rx.angular.js/issues/16)) | ||
<a name="v0.0.2"></a> | ||
### v0.0.2 (2013-12-30) | ||
@@ -23,3 +23,4 @@ ;(function (undefined) { | ||
.fromPromise(deferred) | ||
.select(function(response){ | ||
.retry(10) // Retry 10 times then give up | ||
.map(function(response){ | ||
return response.data[1]; | ||
@@ -60,2 +61,2 @@ }); | ||
}.call(this)); | ||
}.call(this)); |
@@ -5,3 +5,3 @@ { | ||
"description": "Library for bridging between RxJS and AngularJS.", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/Reactive-Extensions/rx.angular.js", | ||
@@ -8,0 +8,0 @@ "author": { |
@@ -0,1 +1,5 @@ | ||
[![Build Status](https://travis-ci.org/Reactive-Extensions/rx.angular.js.png)](https://travis-ci.org/Reactive-Extensions/rx.angular.js) | ||
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/) | ||
[![NPM version](https://badge.fury.io/js/rx-angular.png)](http://badge.fury.io/js/rx-angular) | ||
# rx.angular.js - Reactive Extensions Bindings for AngularJS | ||
@@ -86,3 +90,3 @@ | ||
You can find the documentation [here](https://github.com/Reactive-Extensions/rx.angular.js/tree/master/doc) as well as examples [here](https://github.com/Reactive-Extensions/rx.angular.js/tree/master/examples) and plenty of [unit tests](https://github.com/Reactive-Extensions/rx.angular.js/tree/master/tests). | ||
You can find the documentation [here](https://github.com/Reactive-Extensions/rx.angular.js/tree/master/docs) as well as examples [here](https://github.com/Reactive-Extensions/rx.angular.js/tree/master/examples) and plenty of [unit tests](https://github.com/Reactive-Extensions/rx.angular.js/tree/master/tests). | ||
@@ -135,2 +139,2 @@ ## Getting Started | ||
implied. See the License for the specific language governing permissions | ||
and limitations under the License. | ||
and limitations under the License. |
@@ -37,3 +37,5 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. | ||
// Utilities | ||
var toString = {}.toString; | ||
var toString = {}.toString, | ||
slice = Array.prototype.slice; | ||
function isFunction (fn) { | ||
@@ -44,5 +46,35 @@ return toString.call(fn) === '[object Function]'; | ||
var rxModule = angular.module('rx', []); | ||
rxModule.factory('rx', function($window) { | ||
/** | ||
* @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) { | ||
@@ -54,2 +86,19 @@ throw new Error("Rx is not defined!"); | ||
/** | ||
* @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) { | ||
@@ -62,3 +111,3 @@ return function(scope, watchExpression, objectEquality) { | ||
} | ||
// Returns function which disconnects the $watch expression | ||
@@ -81,6 +130,36 @@ return scope.$watch(watchExpression, listener, objectEquality); | ||
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 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) { | ||
@@ -93,3 +172,3 @@ var scope = this; | ||
} | ||
// Returns function which disconnects the $watch expression | ||
@@ -107,5 +186,84 @@ var unbind = scope.$watch(watchExpression, listener, objectEquality); | ||
}, | ||
/** | ||
* @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) | ||
}; | ||
observer.onNext(data); | ||
} | ||
// Returns function which disconnects from the event binding | ||
var unbind = scope.$on(eventName, listener); | ||
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) { | ||
@@ -131,3 +289,10 @@ var scope = this; | ||
}, | ||
enumerable: false | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
} | ||
@@ -134,0 +299,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
(function(){function a(a){return"[object Function]"===k.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=Rx.Observable,i=h.prototype,j=h.create,k={}.toString,l=angular.module("rx",[]);l.factory("rx",function(a){if(!a.Rx)throw new Error("Rx is not defined!");return a.Rx}),l.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)})}}),i.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)})})},l.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 j(function(d){function e(a,b){d.onNext({oldValue:b,newValue:a})}var f=c.$watch(a,e,b),g=Rx.Disposable.create(f);return c.$on("$destroy",function(){g.dispose()}),g})},enumerable:!1},$createObservableFunction:{value:function(a,b){var c=this;return j(function(d){return c[a]=function(){b?d.onNext(b.apply(this,arguments)):1===arguments.length?d.onNext(arguments[0]):d.onNext(arguments)},function(){delete c[a]}})},enumerable:!1}}),a}])}])}).call(this); | ||
(function(){function a(a){return"[object Function]"===k.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=Rx.Observable,i=h.prototype,j=h.create,k={}.toString,l=Array.prototype.slice,m=angular.module("rx",[]);m.factory("rx",function(a){if(!a.Rx)throw new Error("Rx is not defined!");return a.Rx}),m.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)})}}),i.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)})})},m.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 j(function(d){function e(a,b){d.onNext({oldValue:b,newValue:a})}var f=c.$watch(a,e,b),g=Rx.Disposable.create(f);return c.$on("$destroy",function(){g.dispose()}),g})},enumerable:!1},$eventToObservable:{value:function(a){var b=this;return j(function(c){function d(){var a={event:arguments[0],additionalArguments:l.call(arguments,1)};c.onNext(a)}var e=b.$on(a,d),f=Rx.Disposable.create(e);return b.$on("$destroy",function(){f.dispose()}),f})},enumerable:!1},$createObservableFunction:{value:function(a,b){var c=this;return j(function(d){return c[a]=function(){b?d.onNext(b.apply(this,arguments)):1===arguments.length?d.onNext(arguments[0]):d.onNext(arguments)},function(){delete c[a]}})},enumerable:!1}}),a}])}])}).call(this); |
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 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) { | ||
@@ -13,3 +43,3 @@ var scope = this; | ||
} | ||
// Returns function which disconnects the $watch expression | ||
@@ -27,5 +57,84 @@ var unbind = scope.$watch(watchExpression, listener, objectEquality); | ||
}, | ||
/** | ||
* @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) | ||
}; | ||
observer.onNext(data); | ||
} | ||
// Returns function which disconnects from the event binding | ||
var unbind = scope.$on(eventName, listener); | ||
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) { | ||
@@ -51,3 +160,10 @@ var scope = this; | ||
}, | ||
enumerable: false | ||
/** | ||
* @ngdoc property | ||
* @name rx.$rootScope.$createObservableFunction#enumerable | ||
* | ||
* @description | ||
* Enumerable flag. | ||
*/ | ||
enumerable: false | ||
} | ||
@@ -54,0 +170,0 @@ }); |
@@ -1,2 +0,11 @@ | ||
rxModule.factory('rx', function($window) { | ||
/** | ||
* @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) { | ||
@@ -3,0 +12,0 @@ throw new Error("Rx is not defined!"); |
@@ -35,3 +35,5 @@ ;(function (undefined) { | ||
// Utilities | ||
var toString = {}.toString; | ||
var toString = {}.toString, | ||
slice = Array.prototype.slice; | ||
function isFunction (fn) { | ||
@@ -41,1 +43,2 @@ return toString.call(fn) === '[object Function]'; | ||
function noop () {} | ||
@@ -1,1 +0,21 @@ | ||
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', []); |
@@ -0,1 +1,18 @@ | ||
/** | ||
* @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) { | ||
@@ -8,3 +25,3 @@ return function(scope, watchExpression, objectEquality) { | ||
} | ||
// Returns function which disconnects the $watch expression | ||
@@ -11,0 +28,0 @@ return scope.$watch(watchExpression, listener, objectEquality); |
Sorry, the diff of this file is not supported yet
858362
718
139