|
5 | 5 | * manually invoked. Instead, one should create a $firebase object and call $asArray |
6 | 6 | * on it: <code>$firebase( firebaseRef ).$asArray()</code>; |
7 | 7 | * |
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 |
9 | 9 | * to notify the array whenever a change has been made at the server: |
10 | 10 | * $$added - called whenever a child_added event occurs |
11 | 11 | * $$updated - called whenever a child_changed event occurs |
|
15 | 15 | * $$process - called immediately after $$added/$$updated/$$moved/$$removed |
16 | 16 | * to splice/manipulate the array and invokes $$notify |
17 | 17 | * |
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: |
19 | 19 | * $$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) |
20 | 21 | * |
21 | 22 | * Instead of directly modifying this class, one should generally use the $extendFactory |
22 | 23 | * method to add or change how methods behave. $extendFactory modifies the prototype of |
|
169 | 170 | */ |
170 | 171 | $keyAt: function(indexOrItem) { |
171 | 172 | var item = this._resolveItem(indexOrItem); |
172 | | - return this._getKey(item); |
| 173 | + return this.$$getKey(item); |
173 | 174 | }, |
174 | 175 |
|
175 | 176 | /** |
|
186 | 187 | // evaluate whether our key is cached and, if so, whether it is up to date |
187 | 188 | if( !cache.hasOwnProperty(key) || self.$keyAt(cache[key]) !== key ) { |
188 | 189 | // 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; }); |
190 | 191 | if( pos !== -1 ) { |
191 | 192 | cache[key] = pos; |
192 | 193 | } |
|
364 | 365 | * @returns {string||null} |
365 | 366 | * @private |
366 | 367 | */ |
367 | | - _getKey: function(rec) { //todo rename this to $$getId |
| 368 | + $$getKey: function(rec) { |
368 | 369 | return angular.isObject(rec)? rec.$id : null; |
369 | 370 | }, |
370 | 371 |
|
|
379 | 380 | * @private |
380 | 381 | */ |
381 | 382 | $$process: function(event, rec, prevChild) { |
382 | | - var key = this._getKey(rec); |
| 383 | + var key = this.$$getKey(rec); |
383 | 384 | var changed = false; |
384 | 385 | var curPos; |
385 | 386 | switch(event) { |
|
448 | 449 | if( i === 0 ) { i = this.$list.length; } |
449 | 450 | } |
450 | 451 | this.$list.splice(i, 0, rec); |
451 | | - this._indexCache[this._getKey(rec)] = i; |
| 452 | + this._indexCache[this.$$getKey(rec)] = i; |
452 | 453 | return i; |
453 | 454 | }, |
454 | 455 |
|
|
487 | 488 | // a $id or even a $id that is in the array, it must be an actual record |
488 | 489 | // the fastest way to determine this is to use $getRecord (to avoid iterating all recs) |
489 | 490 | // and compare the two |
490 | | - var key = this._getKey(indexOrItem); |
| 491 | + var key = this.$$getKey(indexOrItem); |
491 | 492 | var rec = this.$getRecord(key); |
492 | 493 | return rec === indexOrItem? rec : null; |
493 | 494 | } |
|
0 commit comments