@@ -178,6 +178,7 @@ function $RootScopeProvider() {
178
178
this . $$childHead = this . $$childTail = null ;
179
179
this . $root = this ;
180
180
this . $$destroyed = false ;
181
+ this . $$suspended = false ;
181
182
this . $$listeners = { } ;
182
183
this . $$listenerCount = { } ;
183
184
this . $$watchersCount = 0 ;
@@ -811,7 +812,7 @@ function $RootScopeProvider() {
811
812
812
813
traverseScopesLoop:
813
814
do { // "traverse the scopes" loop
814
- if ( ( watchers = current . $$watchers ) ) {
815
+ if ( ( watchers = ! current . $$suspended && current . $$watchers ) ) {
815
816
// process our watches
816
817
watchers . $$digestWatchIndex = watchers . length ;
817
818
while ( watchers . $$digestWatchIndex -- ) {
@@ -855,7 +856,7 @@ function $RootScopeProvider() {
855
856
// Insanity Warning: scope depth-first traversal
856
857
// yes, this code is a bit crazy, but it works and we have tests to prove it!
857
858
// this piece should be kept in sync with the traversal in $broadcast
858
- if ( ! ( next = ( ( current . $$watchersCount && current . $$childHead ) ||
859
+ if ( ! ( next = ( ( ! current . $$suspended && current . $$watchersCount && current . $$childHead ) ||
859
860
( current !== target && current . $$nextSibling ) ) ) ) {
860
861
while ( current !== target && ! ( next = current . $$nextSibling ) ) {
861
862
current = current . $parent ;
@@ -892,6 +893,35 @@ function $RootScopeProvider() {
892
893
$browser . $$checkUrlChange ( ) ;
893
894
} ,
894
895
896
+ /**
897
+ * @ngdoc method
898
+ * @name $rootScope.Scope#$suspend
899
+ * @kind function
900
+ *
901
+ * @description
902
+ * Suspend watchers of this scope subtree so that they will not be invoked during digest.
903
+ *
904
+ * This can be used to optimize your application when you know that running those watchers
905
+ * is redundant.
906
+ */
907
+ $suspend : function ( ) {
908
+ this . $$suspended = true ;
909
+ } ,
910
+
911
+ /**
912
+ * @ngdoc method
913
+ * @name $rootScope.Scope#$resume
914
+ * @kind function
915
+ *
916
+ * @description
917
+ * Resume watchers of this scope subtree in case it was suspended.
918
+ *
919
+ * It is recommended to digest on this scope after it is resumed to catch any modifications
920
+ * that might have happened while it was suspended.
921
+ */
922
+ $resume : function ( ) {
923
+ this . $$suspended = false ;
924
+ } ,
895
925
896
926
/**
897
927
* @ngdoc event
0 commit comments