-
-
Save codepreneur/f27eee96613bac825421 to your computer and use it in GitHub Desktop.
Revisions
-
Greg Soltis revised this gist
May 16, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ return function() { query.off(eventType, listener); } }).publish().refCount(); }; })(); -
Greg Soltis created this gist
May 14, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ (function () { var makeCallback = function(eventType, observer) { if (eventType === 'value') { return function(snap) { observer.onNext(snap); }; } else { return function(snap, prevName) { // Wrap into an object, since we can only pass one argument through. observer.onNext({snapshot: snap, prevName: prevName}); } } }; Firebase.prototype.__proto__.observe = function(eventType) { var query = this; return Rx.Observable.create(function(observer) { var listener = query.on(eventType, makeCallback(eventType, observer), function(error) { observer.onError(error); }); return function() { query.off(eventType, listener); } }); }; })(); /** * Usage: * * var source = new Firebase("https://<your firebase>.firebaseio.com").observe('<event type>'); * console.log(source instanceof Rx.Observable); * source.subscribe(function(changeData) { * // If event type is 'value', changeData is a DataSnapshot * // Otherwise, changeData is {snapshot: DataSnapshot, prevName: optional string of previous child location} * }); * */