This repository was archived by the owner on Mar 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed
Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 188188 * Called by $firebase whenever an item is changed at the server.
189189 * This method must exist on any objectFactory passed into $firebase.
190190 *
191- * @param snap
191+ * It should return true if any changes were made, otherwise `$$notify` will
192+ * not be invoked.
193+ *
194+ * @param {object } snap a Firebase snapshot
195+ * @return {boolean } true if any changes were made.
192196 */
193197 $$updated : function ( snap ) {
194198 // applies new data to this object
195199 var changed = $firebaseUtils . updateRec ( this , snap ) ;
200+ // applies any defaults set using $$defaults
196201 $firebaseUtils . applyDefaults ( this , this . $$defaults ) ;
197- if ( changed ) {
198- // notifies $watch listeners and
199- // updates $scope if bound to a variable
200- this . $$notify ( ) ;
201- }
202+ // returning true here causes $$notify to be triggered
203+ return changed ;
202204 } ,
203205
204206 /**
225227 } ,
226228
227229 /**
228- * Updates any bound scope variables and notifies listeners registered
229- * with $watch any time there is a change to data
230+ * Updates any bound scope variables and
231+ * notifies listeners registered with $watch
230232 */
231233 $$notify : function ( ) {
232234 var self = this , list = this . $$conf . listeners . slice ( ) ;
Original file line number Diff line number Diff line change 261261 var obj = new ObjectFactory ( $inst , destroy , def . promise ) ;
262262 var ref = $inst . $ref ( ) ;
263263 var batch = $firebaseUtils . batch ( ) ;
264- var applyUpdate = batch ( obj . $$updated , obj ) ;
264+ var applyUpdate = batch ( function ( snap ) {
265+ var changed = obj . $$updated ( snap ) ;
266+ if ( changed ) {
267+ // notifies $watch listeners and
268+ // updates $scope if bound to a variable
269+ obj . $$notify ( ) ;
270+ }
271+ } ) ;
265272 var error = batch ( obj . $$error , obj ) ;
266273 var resolve = batch ( _resolveFn ) ;
267274
Original file line number Diff line number Diff line change @@ -248,6 +248,7 @@ describe('$FirebaseObject', function() {
248248 $timeout . flush ( ) ;
249249 $fb . $set . calls . reset ( ) ;
250250 obj . $$updated ( fakeSnap ( { foo : 'bar' } ) ) ;
251+ obj . $$notify ( ) ;
251252 flushAll ( ) ;
252253 expect ( $scope . test ) . toEqual ( { foo : 'bar' , $id : obj . $id , $priority : obj . $priority } ) ;
253254 } ) ;
You can’t perform that action at this time.
0 commit comments