@@ -354,6 +354,68 @@ function $RootScopeProvider(){
354
354
} ;
355
355
} ,
356
356
357
+ /**
358
+ * @ngdoc method
359
+ * @name $rootScope.Scope#$watchSet
360
+ * @function
361
+ *
362
+ * @description
363
+ * A variant of {@link ng.$rootScope.Scope#$watch $watch()} where it watches an array of `watchExpressions`.
364
+ * If any one expression in the collection changes the `listener` is executed.
365
+ *
366
+ * - The items in the `watchCollection` array are observed via standard $watch operation and are examined on every
367
+ * call to $digest() to see if any items changes.
368
+ * - The `listener` is called whenever any expression in the `watchExpressions` array changes.
369
+ *
370
+ * @param {Array.<string|Function(scope)> } watchExpressions Array of expressions that will be individually
371
+ * watched using {@link ng.$rootScope.Scope#$watch $watch()}
372
+ *
373
+ * @param {function(newValues, oldValues, scope) } listener Callback called whenever the return value of any
374
+ * expression in `watchExpressions` changes
375
+ * The `newValues` array contains the current values of the `watchExpressions`, with the indexes matching
376
+ * those of `watchExpression`
377
+ * and the `oldValues` array contains the previous values of the `watchExpressions`, with the indexes matching
378
+ * those of `watchExpression`
379
+ * The `scope` refers to the current scope.
380
+ *
381
+ * @returns {function() } Returns a de-registration function for all listeners.
382
+ */
383
+ $watchSet : function ( watchExpressions , listener ) {
384
+ if ( watchExpressions . length === 0 ) return noop ;
385
+
386
+ var oldValues = new Array ( watchExpressions . length ) ,
387
+ newValues = new Array ( watchExpressions . length ) ;
388
+
389
+ if ( watchExpressions . length === 1 ) {
390
+ // Special case size of one
391
+ return this . $watch ( watchExpressions [ 0 ] , function ( value , oldValue , scope ) {
392
+ newValues [ 0 ] = value ;
393
+ oldValues [ 0 ] = oldValue ;
394
+ listener . call ( this , newValues , oldValues , scope ) ;
395
+ } ) ;
396
+ }
397
+ var deregisterFns = [ ] ,
398
+ changeCount = 0 ;
399
+
400
+ forEach ( watchExpressions , function ( expr , i ) {
401
+ deregisterFns . push ( this . $watch ( expr , function ( value , oldValue ) {
402
+ newValues [ i ] = value ;
403
+ oldValues [ i ] = oldValue ;
404
+ changeCount ++ ;
405
+ } ) ) ;
406
+ } , this ) ;
407
+
408
+ deregisterFns . push ( this . $watch ( function ( ) { return changeCount ; } , function ( c , o , scope ) {
409
+ listener . call ( this , newValues , oldValues , scope ) ;
410
+ } ) ) ;
411
+
412
+ return function ( ) {
413
+ forEach ( deregisterFns , function ( fn ) {
414
+ fn ( ) ;
415
+ } ) ;
416
+ } ;
417
+ } ,
418
+
357
419
358
420
/**
359
421
* @ngdoc method
0 commit comments