Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit b279b57

Browse files
author
Jacob Wenger
committed
Merge pull request #560 from firebase/kato-rename
Rename $FirebaseArray and $FirebaseObject
2 parents 0408ccc + a34080c commit b279b57

File tree

10 files changed

+121
-93
lines changed

10 files changed

+121
-93
lines changed

src/FirebaseArray.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
(function() {
22
'use strict';
33
/**
4-
* Creates and maintains a synchronized list of data. This constructor should not be
5-
* manually invoked. Instead, one should create a $firebase object and call $asArray
6-
* on it: <code>$firebase( firebaseRef ).$asArray()</code>;
4+
* Creates and maintains a synchronized list of data. This is a pseudo-read-only array. One should
5+
* not call splice(), push(), pop(), et al directly on this array, but should instead use the
6+
* $remove and $add methods.
77
*
8-
* Internally, the $firebase object depends on this class to provide 5 $$ methods, which it invokes
9-
* to notify the array whenever a change has been made at the server:
8+
* It is acceptable to .sort() this array, but it is important to use this in conjunction with
9+
* $watch(), so that it will be re-sorted any time the server data changes. Examples of this are
10+
* included in the $watch documentation.
11+
*
12+
* Internally, the $firebase object depends on this class to provide several $$ (i.e. protected)
13+
* methods, which it invokes to notify the array whenever a change has been made at the server:
1014
* $$added - called whenever a child_added event occurs
1115
* $$updated - called whenever a child_changed event occurs
1216
* $$moved - called whenever a child_moved event occurs
@@ -22,10 +26,10 @@
2226
*
2327
* Instead of directly modifying this class, one should generally use the $extend
2428
* method to add or change how methods behave. $extend modifies the prototype of
25-
* the array class by returning a clone of $FirebaseArray.
29+
* the array class by returning a clone of $firebaseArray.
2630
*
2731
* <pre><code>
28-
* var ExtendedArray = $FirebaseArray.$extend({
32+
* var ExtendedArray = $firebaseArray.$extend({
2933
* // add a new method to the prototype
3034
* foo: function() { return 'bar'; },
3135
*
@@ -43,7 +47,7 @@
4347
* var list = new ExtendedArray(ref);
4448
* </code></pre>
4549
*/
46-
angular.module('firebase').factory('$FirebaseArray', ["$log", "$firebaseUtils",
50+
angular.module('firebase').factory('$firebaseArray', ["$log", "$firebaseUtils",
4751
function($log, $firebaseUtils) {
4852
/**
4953
* This constructor should probably never be called manually. It is used internally by
@@ -54,14 +58,17 @@
5458
* @constructor
5559
*/
5660
function FirebaseArray(ref) {
61+
if( !(this instanceof FirebaseArray) ) {
62+
return new FirebaseArray(ref);
63+
}
5764
var self = this;
5865
this._observers = [];
5966
this.$list = [];
6067
this._ref = ref;
6168
this._sync = new ArraySyncManager(this);
6269

6370
$firebaseUtils.assertValidRef(ref, 'Must pass a valid Firebase reference ' +
64-
'to $FirebaseArray (not a string or URL)');
71+
'to $firebaseArray (not a string or URL)');
6572

6673
// indexCache is a weak hashmap (a lazy list) of keys to array indices,
6774
// items are not guaranteed to stay up to date in this list (since the data
@@ -532,7 +539,7 @@
532539
*/
533540
_assertNotDestroyed: function(method) {
534541
if( this._isDestroyed ) {
535-
throw new Error('Cannot call ' + method + ' method on a destroyed $FirebaseArray object');
542+
throw new Error('Cannot call ' + method + ' method on a destroyed $firebaseArray object');
536543
}
537544
}
538545
};
@@ -548,7 +555,7 @@
548555
* methods to add onto the prototype.
549556
*
550557
* <pre><code>
551-
* var ExtendedArray = $FirebaseArray.$extend({
558+
* var ExtendedArray = $firebaseArray.$extend({
552559
* // add a method onto the prototype that sums all items in the array
553560
* getSum: function() {
554561
* var ct = 0;
@@ -557,7 +564,7 @@
557564
* }
558565
* });
559566
*
560-
* // use our new factory in place of $FirebaseArray
567+
* // use our new factory in place of $firebaseArray
561568
* var list = new ExtendedArray(ref);
562569
* </code></pre>
563570
*
@@ -672,4 +679,14 @@
672679
return FirebaseArray;
673680
}
674681
]);
682+
683+
/** @deprecated */
684+
angular.module('firebase').factory('$FirebaseArray', ['$log', '$firebaseArray',
685+
function($log, $firebaseArray) {
686+
return function() {
687+
$log.warn('$FirebaseArray has been renamed. Use $firebaseArray instead.');
688+
return $firebaseArray.apply(null, arguments);
689+
};
690+
}
691+
]);
675692
})();

src/FirebaseObject.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* method to add or change how methods behave:
1515
*
1616
* <pre><code>
17-
* var ExtendedObject = $FirebaseObject.$extend({
17+
* var ExtendedObject = $firebaseObject.$extend({
1818
* // add a new method to the prototype
1919
* foo: function() { return 'bar'; },
2020
* });
2121
*
2222
* var obj = new ExtendedObject(ref);
2323
* </code></pre>
2424
*/
25-
angular.module('firebase').factory('$FirebaseObject', [
25+
angular.module('firebase').factory('$firebaseObject', [
2626
'$parse', '$firebaseUtils', '$log',
2727
function($parse, $firebaseUtils, $log) {
2828
/**
@@ -33,6 +33,9 @@
3333
* @constructor
3434
*/
3535
function FirebaseObject(ref) {
36+
if( !(this instanceof FirebaseObject) ) {
37+
return new FirebaseObject(ref);
38+
}
3639
// These are private config props and functions used internally
3740
// they are collected here to reduce clutter in console.log and forEach
3841
this.$$conf = {
@@ -266,14 +269,14 @@
266269
* `objectFactory` parameter:
267270
*
268271
* <pre><code>
269-
* var MyFactory = $FirebaseObject.$extend({
272+
* var MyFactory = $firebaseObject.$extend({
270273
* // add a method onto the prototype that prints a greeting
271274
* getGreeting: function() {
272275
* return 'Hello ' + this.first_name + ' ' + this.last_name + '!';
273276
* }
274277
* });
275278
*
276-
* // use our new factory in place of $FirebaseObject
279+
* // use our new factory in place of $firebaseObject
277280
* var obj = $firebase(ref, {objectFactory: MyFactory}).$asObject();
278281
* </code></pre>
279282
*
@@ -412,7 +415,7 @@
412415
ref.on('value', applyUpdate, error);
413416
ref.once('value', function(snap) {
414417
if (angular.isArray(snap.val())) {
415-
$log.warn('Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/web/guide/understanding-data.html#section-arrays-in-firebase for more information. Also note that you probably wanted $FirebaseArray and not $FirebaseObject.');
418+
$log.warn('Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/web/guide/understanding-data.html#section-arrays-in-firebase for more information. Also note that you probably wanted $firebaseArray and not $firebaseObject.');
416419
}
417420

418421
initComplete(null);
@@ -454,4 +457,14 @@
454457
return FirebaseObject;
455458
}
456459
]);
460+
461+
/** @deprecated */
462+
angular.module('firebase').factory('$FirebaseObject', ['$log', '$firebaseObject',
463+
function($log, $firebaseObject) {
464+
return function() {
465+
$log.warn('$FirebaseObject has been renamed. Use $firebaseObject instead.');
466+
return $firebaseObject.apply(null, arguments);
467+
};
468+
}
469+
]);
457470
})();

src/firebase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/** @deprecated */
77
.factory("$firebase", function() {
88
return function() {
9-
throw new Error('$firebase has been removed. You may instantiate $FirebaseArray and $FirebaseObject ' +
9+
throw new Error('$firebase has been removed. You may instantiate $firebaseArray and $firebaseObject ' +
1010
'directly now. For simple write operations, just use the Firebase ref directly. ' +
1111
'See the AngularFire 1.0.0 changelog for details: https://www.firebase.com/docs/web/libraries/angular/changelog.html');
1212
};

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
'use strict';
33

44
angular.module('firebase')
5-
.factory('$firebaseConfig', ["$FirebaseArray", "$FirebaseObject", "$injector",
6-
function($FirebaseArray, $FirebaseObject, $injector) {
5+
.factory('$firebaseConfig', ["$firebaseArray", "$firebaseObject", "$injector",
6+
function($firebaseArray, $firebaseObject, $injector) {
77
return function(configOpts) {
88
// make a copy we can modify
99
var opts = angular.extend({}, configOpts);
@@ -16,8 +16,8 @@
1616
}
1717
// extend defaults and return
1818
return angular.extend({
19-
arrayFactory: $FirebaseArray,
20-
objectFactory: $FirebaseObject
19+
arrayFactory: $firebaseArray,
20+
objectFactory: $firebaseObject
2121
}, opts);
2222
};
2323
}

tests/protractor/chat/chat.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
var app = angular.module('chat', ['firebase']);
2-
app.controller('ChatCtrl', function Chat($scope, $FirebaseObject, $FirebaseArray) {
2+
app.controller('ChatCtrl', function Chat($scope, $firebaseObject, $firebaseArray) {
33
// Get a reference to the Firebase
44
var chatFirebaseRef = new Firebase('https://angularFireTests.firebaseio-demo.com/chat');
55
var messagesFirebaseRef = chatFirebaseRef.child("messages").limitToLast(2);
66

7-
// Get AngularFire sync objects
8-
97
// Get the chat data as an object
10-
$scope.chat = new $FirebaseObject(chatFirebaseRef);
8+
$scope.chat = $firebaseObject(chatFirebaseRef);
119

1210
// Get the chat messages as an array
13-
$scope.messages = new $FirebaseArray(messagesFirebaseRef);
11+
$scope.messages = $firebaseArray(messagesFirebaseRef);
1412

1513
// Verify that $inst() works
16-
verify($scope.chat.$ref() === chatFirebaseRef, "Something is wrong with $FirebaseObject.$inst().");
17-
verify($scope.messages.$ref() === messagesFirebaseRef, "Something is wrong with $FirebaseArray.$inst().");
14+
verify($scope.chat.$ref() === chatFirebaseRef, "Something is wrong with $firebaseObject.$ref().");
15+
verify($scope.messages.$ref() === messagesFirebaseRef, "Something is wrong with $firebaseArray.$ref().");
1816

1917
// Initialize $scope variables
2018
$scope.message = "";

tests/protractor/priority/priority.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var app = angular.module('priority', ['firebase']);
2-
app.controller('PriorityCtrl', function Chat($scope, $FirebaseArray, $FirebaseObject) {
2+
app.controller('PriorityCtrl', function Chat($scope, $firebaseArray, $firebaseObject) {
33
// Get a reference to the Firebase
44
var messagesFirebaseRef = new Firebase('https://angularFireTests.firebaseio-demo.com/priority');
55

66
// Get the chat messages as an array
7-
$scope.messages = new $FirebaseArray(messagesFirebaseRef);
7+
$scope.messages = $firebaseArray(messagesFirebaseRef);
88

99
// Verify that $inst() works
10-
verify($scope.messages.$ref() === messagesFirebaseRef, 'Something is wrong with $FirebaseArray.$ref().');
10+
verify($scope.messages.$ref() === messagesFirebaseRef, 'Something is wrong with $firebaseArray.$ref().');
1111

1212
// Initialize $scope variables
1313
$scope.message = '';
@@ -27,17 +27,17 @@ app.controller('PriorityCtrl', function Chat($scope, $FirebaseArray, $FirebaseOb
2727
from: $scope.username,
2828
content: $scope.message
2929
}).then(function (ref) {
30-
var newItem = new $FirebaseObject(ref);
30+
var newItem = $firebaseObject(ref);
3131

3232
newItem.$loaded().then(function (data) {
33-
verify(newItem === data, '$FirebaseObject.$loaded() does not return correct value.');
33+
verify(newItem === data, '$firebaseObject.$loaded() does not return correct value.');
3434

3535
// Update the message's priority
3636
newItem.$priority = priority;
3737
newItem.$save();
3838
});
3939
}, function (error) {
40-
verify(false, 'Something is wrong with $FirebaseArray.$add().');
40+
verify(false, 'Something is wrong with $firebaseArray.$add().');
4141
});
4242

4343
// Reset the message input

tests/protractor/tictactoe/tictactoe.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
var app = angular.module('tictactoe', ['firebase']);
2-
app.controller('TicTacToeCtrl', function Chat($scope, $FirebaseObject) {
2+
app.controller('TicTacToeCtrl', function Chat($scope, $firebaseObject) {
33
// Get a reference to the Firebase
44
var boardFirebaseRef = new Firebase('https://angularFireTests.firebaseio-demo.com/tictactoe');
55

66
// Get the board as an AngularFire object
7-
$scope.boardObject = new $FirebaseObject(boardFirebaseRef);
7+
$scope.boardObject = $firebaseObject(boardFirebaseRef);
88

99
// Create a 3-way binding to Firebase
1010
$scope.boardObject.$bindTo($scope, 'board');
1111

1212
// Verify that $inst() works
13-
verify($scope.boardObject.$ref() === boardFirebaseRef, 'Something is wrong with $FirebaseObject.$ref().');
13+
verify($scope.boardObject.$ref() === boardFirebaseRef, 'Something is wrong with $firebaseObject.$ref().');
1414

1515
// Initialize $scope variables
1616
$scope.whoseTurn = 'X';

tests/protractor/todo/todo.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var app = angular.module('todo', ['firebase']);
2-
app. controller('TodoCtrl', function Todo($scope, $FirebaseArray) {
2+
app. controller('TodoCtrl', function Todo($scope, $firebaseArray) {
33
// Get a reference to the Firebase
44
var todosFirebaseRef = new Firebase('https://angularFireTests.firebaseio-demo.com/todo');
55

66
// Get the todos as an array
7-
$scope.todos = new $FirebaseArray(todosFirebaseRef);
7+
$scope.todos = $firebaseArray(todosFirebaseRef);
88

99
// Verify that $ref() works
10-
verify($scope.todos.$ref() === todosFirebaseRef, "Something is wrong with $FirebaseArray.$ref().");
10+
verify($scope.todos.$ref() === todosFirebaseRef, "Something is wrong with $firebaseArray.$ref().");
1111

1212
/* Clears the todos Firebase reference */
1313
$scope.clearRef = function () {
@@ -35,7 +35,7 @@ app. controller('TodoCtrl', function Todo($scope, $FirebaseArray) {
3535
/* Removes the todo item with the inputted ID */
3636
$scope.removeTodo = function(id) {
3737
// Verify that $indexFor() and $keyAt() work
38-
verify($scope.todos.$indexFor($scope.todos.$keyAt(id)) === id, "Something is wrong with $FirebaseArray.$indexFor() or FirebaseArray.$keyAt().");
38+
verify($scope.todos.$indexFor($scope.todos.$keyAt(id)) === id, "Something is wrong with $firebaseArray.$indexFor() or FirebaseArray.$keyAt().");
3939

4040
$scope.todos.$remove(id);
4141
};

0 commit comments

Comments
 (0)