55 * manually invoked. Instead, one should create a $firebase object and call $asArray
66 * on it: <code>$firebase( firebaseRef ).$asArray()</code>;
77 *
8- * Internally, the $firebase object depends on this class to provide 5 methods, which it invokes
8+ * Internally, the $firebase object depends on this class to provide 5 $$ methods, which it invokes
99 * to notify the array whenever a change has been made at the server:
1010 * $$added - called whenever a child_added event occurs
1111 * $$updated - called whenever a child_changed event occurs
1515 * $$process - called immediately after $$added/$$updated/$$moved/$$removed
1616 * to splice/manipulate the array and invokes $$notify
1717 *
18- * Additionally, there is one more method of interest to devs extending this class:
18+ * Additionally, these methods may be of interest to devs extending this class:
1919 * $$notify - triggers notifications to any $watch listeners, called by $$process
20+ * $$getKey - determines how to look up a record's key (returns $id by default)
2021 *
2122 * Instead of directly modifying this class, one should generally use the $extendFactory
2223 * method to add or change how methods behave. $extendFactory modifies the prototype of
3435 *
3536 * // change how records are updated
3637 * $$updated: function(snap) {
37- * return this.$getRecord(snap.name ()).update(snap);
38+ * return this.$getRecord(snap.key ()).update(snap);
3839 * }
3940 * });
4041 * </code></pre>
169170 */
170171 $keyAt : function ( indexOrItem ) {
171172 var item = this . _resolveItem ( indexOrItem ) ;
172- return this . _getKey ( item ) ;
173+ return this . $$getKey ( item ) ;
173174 } ,
174175
175176 /**
186187 // evaluate whether our key is cached and, if so, whether it is up to date
187188 if ( ! cache . hasOwnProperty ( key ) || self . $keyAt ( cache [ key ] ) !== key ) {
188189 // update the hashmap
189- var pos = self . $list . findIndex ( function ( rec ) { return self . _getKey ( rec ) === key ; } ) ;
190+ var pos = self . $list . findIndex ( function ( rec ) { return self . $$getKey ( rec ) === key ; } ) ;
190191 if ( pos !== - 1 ) {
191192 cache [ key ] = pos ;
192193 }
364365 * @returns {string||null }
365366 * @private
366367 */
367- _getKey : function ( rec ) { //todo rename this to $$getId
368+ $$getKey : function ( rec ) {
368369 return angular . isObject ( rec ) ? rec . $id : null ;
369370 } ,
370371
371372 /**
372373 * Handles placement of recs in the array, sending notifications,
373374 * and other internals. Called by the $firebase synchronization process
374- * after $$added, $$updated, $$moved, and $$removed
375+ * after $$added, $$updated, $$moved, and $$removed.
375376 *
376377 * @param {string } event one of child_added, child_removed, child_moved, or child_changed
377378 * @param {object } rec
378379 * @param {string } [prevChild]
379380 * @private
380381 */
381382 $$process : function ( event , rec , prevChild ) {
382- var key = this . _getKey ( rec ) ;
383+ var key = this . $$getKey ( rec ) ;
383384 var changed = false ;
384385 var curPos ;
385386 switch ( event ) {
398399 changed = true ;
399400 break ;
400401 default :
401- throw new Error ( 'Invalid event type ' + event ) ;
402+ throw new Error ( 'Invalid event type: ' + event ) ;
402403 }
403404 if ( angular . isDefined ( curPos ) ) {
404405 // add it to the array
448449 if ( i === 0 ) { i = this . $list . length ; }
449450 }
450451 this . $list . splice ( i , 0 , rec ) ;
451- this . _indexCache [ this . _getKey ( rec ) ] = i ;
452+ this . _indexCache [ this . $$getKey ( rec ) ] = i ;
452453 return i ;
453454 } ,
454455
487488 // a $id or even a $id that is in the array, it must be an actual record
488489 // the fastest way to determine this is to use $getRecord (to avoid iterating all recs)
489490 // and compare the two
490- var key = this . _getKey ( indexOrItem ) ;
491+ var key = this . $$getKey ( indexOrItem ) ;
491492 var rec = this . $getRecord ( key ) ;
492493 return rec === indexOrItem ? rec : null ;
493494 }
548549 return FirebaseArray ;
549550 }
550551 ] ) ;
551- } ) ( ) ;
552+ } ) ( ) ;
0 commit comments