Skip to content

Commit

Permalink
Add method $getRef to $firebase objects, fixes FirebaseExtended#252
Browse files Browse the repository at this point in the history
  • Loading branch information
anantn committed Feb 26, 2014
1 parent 9eacd1d commit 32f9d96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 10 additions & 7 deletions angularfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@
if (input) {
if (!input.$getIndex || typeof input.$getIndex != "function") {
// input is not an angularFire instance
if( angular.isArray(input) ) {
// if input is an array, copy it
if (angular.isArray(input)) {
// If input is an array, copy it
sorted = input.slice(0);
}
else if( angular.isObject(input) ) {
} else if (angular.isObject(input)) {
// If input is an object, map it to an array
angular.forEach(input, function(prop) {
sorted.push(prop);
});
}
}
else {
} else {
// input is an angularFire instance
var index = input.$getIndex();
if (index.length > 0) {
Expand Down Expand Up @@ -140,7 +138,7 @@
var self = this;
var object = {};

// Set the $id val equal to the firebase reference's name() function.
// Set the $id val equal to the Firebase reference's name() function.
object.$id = self._fRef.ref().name();

// Establish a 3-way data binding (implicit sync) with the specified
Expand Down Expand Up @@ -391,6 +389,11 @@
return angular.copy(self._index);
};

// Return the reference used by this object.
object.$getRef = function() {
return self._fRef.ref();
};

self._object = object;
self._getInitialValue();

Expand Down
2 changes: 1 addition & 1 deletion angularfire.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/e2e/test_chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ casper.then(function() {
}, "Testing if $add, $set, $save and $remove return a promise");
});

casper.then(function() {
this.test.assertEval(function() {
if (_scope.messages.$getRef().toString() != _url) return false;
if (!(_scope.messages.$getRef() instanceof Firebase)) return false;
return true;
}, "Testing if $getRef returns valid Firebase reference");
});

casper.then(function() {
this.test.assertEval(function() {
var empty = function() {};
Expand Down

0 comments on commit 32f9d96

Please sign in to comment.