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

Commit 2fbedcb

Browse files
committed
FirebaseArray.js: Clean docs in FirebaseArray to reflect new structure
priority.js: Fix syntax error in clearRef method
1 parent dc9ea99 commit 2fbedcb

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

src/FirebaseArray.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*
88
* 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:
10-
* $$added - called whenever a child_added event occurs, returns the new record, or null to cancel
11-
* $$updated - called whenever a child_changed event occurs, returns true if updates were applied
12-
* $$moved - called whenever a child_moved event occurs, returns true if move should be applied
13-
* $$removed - called whenever a child_removed event occurs, returns true if remove should be applied
10+
* $$added - called whenever a child_added event occurs
11+
* $$updated - called whenever a child_changed event occurs
12+
* $$moved - called whenever a child_moved event occurs
13+
* $$removed - called whenever a child_removed event occurs
1414
* $$error - called when listeners are canceled due to a security error
1515
* $$process - called immediately after $$added/$$updated/$$moved/$$removed
1616
* (assuming that these methods do not abort by returning false or null)
@@ -286,8 +286,10 @@
286286
},
287287

288288
/**
289-
* Called by $firebase to inform the array when a new item has been added at the server.
290-
* This method must exist on any array factory used by $firebase.
289+
* Called to inform the array when a new item has been added at the server.
290+
* This method should return the record (an object) that will be passed into $$process
291+
* along with the add event. Alternately, the record will be skipped if this method returns
292+
* a falsey value.
291293
*
292294
* @param {object} snap a Firebase snapshot
293295
* @param {string} prevChild
@@ -313,25 +315,31 @@
313315
},
314316

315317
/**
316-
* Called by $firebase whenever an item is removed at the server.
318+
* Called whenever an item is removed at the server.
317319
* This method does not physically remove the objects, but instead
318320
* returns a boolean indicating whether it should be removed (and
319321
* taking any other desired actions before the remove completes).
320322
*
321323
* @param {object} snap a Firebase snapshot
322324
* @return {boolean} true if item should be removed
325+
* @protected
323326
*/
324327
$$removed: function(snap) {
325328
return this.$indexFor($firebaseUtils.getKey(snap)) > -1;
326329
},
327330

328331
/**
329-
* Called by $firebase whenever an item is changed at the server.
332+
* Called whenever an item is changed at the server.
330333
* This method should apply the changes, including changes to data
331334
* and to $priority, and then return true if any changes were made.
332335
*
336+
* If this method returns false, then $$process will not be invoked,
337+
* which means that $$notify will not take place and no $watch events
338+
* will be triggered.
339+
*
333340
* @param {object} snap a Firebase snapshot
334341
* @return {boolean} true if any data changed
342+
* @protected
335343
*/
336344
$$updated: function(snap) {
337345
var changed = false;
@@ -345,13 +353,18 @@
345353
},
346354

347355
/**
348-
* Called by $firebase whenever an item changes order (moves) on the server.
356+
* Called whenever an item changes order (moves) on the server.
349357
* This method should set $priority to the updated value and return true if
350358
* the record should actually be moved. It should not actually apply the move
351359
* operation.
352360
*
361+
* If this method returns false, then the record will not be moved in the array
362+
* and no $watch listeners will be notified. (When true, $$process is invoked
363+
* which invokes $$notify)
364+
*
353365
* @param {object} snap a Firebase snapshot
354366
* @param {string} prevChild
367+
* @protected
355368
*/
356369
$$moved: function(snap/*, prevChild*/) {
357370
var rec = this.$getRecord($firebaseUtils.getKey(snap));
@@ -365,7 +378,9 @@
365378
/**
366379
* Called whenever a security error or other problem causes the listeners to become
367380
* invalid. This is generally an unrecoverable error.
381+
*
368382
* @param {Object} err which will have a `code` property and possibly a `message`
383+
* @protected
369384
*/
370385
$$error: function(err) {
371386
$log.error(err);
@@ -376,21 +391,21 @@
376391
* Returns ID for a given record
377392
* @param {object} rec
378393
* @returns {string||null}
379-
* @private
394+
* @protected
380395
*/
381396
$$getKey: function(rec) {
382397
return angular.isObject(rec)? rec.$id : null;
383398
},
384399

385400
/**
386401
* Handles placement of recs in the array, sending notifications,
387-
* and other internals. Called by the $firebase synchronization process
388-
* after $$added, $$updated, $$moved, and $$removed.
402+
* and other internals. Called by the synchronization process
403+
* after $$added, $$updated, $$moved, and $$removed return a truthy value.
389404
*
390405
* @param {string} event one of child_added, child_removed, child_moved, or child_changed
391406
* @param {object} rec
392407
* @param {string} [prevChild]
393-
* @private
408+
* @protected
394409
*/
395410
$$process: function(event, rec, prevChild) {
396411
var key = this.$$getKey(rec);
@@ -426,12 +441,13 @@
426441
},
427442

428443
/**
429-
* Used to trigger notifications for listeners registered using $watch
444+
* Used to trigger notifications for listeners registered using $watch. This method is
445+
* typically invoked internally by the $$process method.
430446
*
431447
* @param {string} event
432448
* @param {string} key
433449
* @param {string} [prevChild]
434-
* @private
450+
* @protected
435451
*/
436452
$$notify: function(event, key, prevChild) {
437453
var eventData = {event: event, key: key};
@@ -522,7 +538,7 @@
522538
};
523539

524540
/**
525-
* This method allows FirebaseArray to be copied into a new factory. Methods passed into this
541+
* This method allows FirebaseArray to be inherited by child classes. Methods passed into this
526542
* function will be added onto the array's prototype. They can override existing methods as
527543
* well.
528544
*
@@ -531,10 +547,8 @@
531547
* FirebaseArray. It's also possible to do both, passing a class to inherit and additional
532548
* methods to add onto the prototype.
533549
*
534-
* Once a factory is obtained by this method, it can be passed into $firebase as the
535-
* `arrayFactory` parameter:
536-
* <pre><code>
537-
* var MyFactory = $FirebaseArray.$extendFactory({
550+
* <pre><code>
551+
* var ExtendedArray = $FirebaseArray.$extend({
538552
* // add a method onto the prototype that sums all items in the array
539553
* getSum: function() {
540554
* var ct = 0;
@@ -544,12 +558,13 @@
544558
* });
545559
*
546560
* // use our new factory in place of $FirebaseArray
547-
* var list = $firebase(ref, {arrayFactory: MyFactory}).$asArray();
561+
* var list = new ExtendedArray(ref);
548562
* </code></pre>
549563
*
550564
* @param {Function} [ChildClass] a child class which should inherit FirebaseArray
551565
* @param {Object} [methods] a list of functions to add onto the prototype
552-
* @returns {Function} a new factory suitable for use with $firebase
566+
* @returns {Function} a child class suitable for use with $firebase (this will be ChildClass if provided)
567+
* @static
553568
*/
554569
FirebaseArray.$extend = function(ChildClass, methods) {
555570
if( arguments.length === 1 && angular.isObject(ChildClass) ) {

tests/protractor/priority/priority.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ app.controller('PriorityCtrl', function Chat($scope, $FirebaseArray, $FirebaseOb
1515

1616
/* Clears the priority Firebase reference */
1717
$scope.clearRef = function () {
18-
messagesFirebaseRef.$remove();
18+
messagesFirebaseRef.remove();
1919
};
2020

2121
/* Adds a new message to the messages list */

0 commit comments

Comments
 (0)