From faa9a6b089d9780014fb4a1749f1c6174e27215e Mon Sep 17 00:00:00 2001 From: Steffen Kowalski Date: Wed, 6 Jun 2018 14:13:31 +0200 Subject: [PATCH 1/4] Added new featured to $rootScope from 1.6.10 https://github.com/angular/angular.js/blob/master/CHANGELOG.md#1610-crystalline-persuasion-2018-04-17 --- types/angular/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 6dccefc926..1133c46410 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -484,6 +484,9 @@ declare namespace angular { $broadcast(name: string, ...args: any[]): IAngularEvent; $destroy(): void; $digest(): void; + $suspend(): void; + $isSuspended(): boolean; + $resume(): void; /** * Dispatches an event name upwards through the scope hierarchy notifying the registered $rootScope.Scope listeners. * From 43448845ed60d8e2672bc2ebfd531f70ece68402 Mon Sep 17 00:00:00 2001 From: Steffen Kowalski Date: Wed, 6 Jun 2018 14:14:35 +0200 Subject: [PATCH 2/4] Added myself to "Definitions by" --- types/angular/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 1133c46410..658a97e315 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -4,6 +4,7 @@ // Georgii Dolzhykov // Caleb St-Denis // Leonard Thieu +// Steffen Kowalski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 From ef970e72adaf630f292503e2dfd56ad7f155897f Mon Sep 17 00:00:00 2001 From: Steffen Kowalski Date: Wed, 6 Jun 2018 15:27:16 +0200 Subject: [PATCH 3/4] added docs to $suspend, $isSuspended and $resume --- types/angular/index.d.ts | 82 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 658a97e315..5ba41ba04e 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -485,9 +485,91 @@ declare namespace angular { $broadcast(name: string, ...args: any[]): IAngularEvent; $destroy(): void; $digest(): void; + + /** + * @ngdoc method + * @name $rootScope.Scope#$suspend + * @kind function + * + * @description + * Suspend watchers of this scope subtree so that they will not be invoked during digest. + * + * This can be used to optimize your application when you know that running those watchers + * is redundant. + * + * **Warning** + * + * Suspending scopes from the digest cycle can have unwanted and difficult to debug results. + * Only use this approach if you are confident that you know what you are doing and have + * ample tests to ensure that bindings get updated as you expect. + * + * Some of the things to consider are: + * + * * Any external event on a directive/component will not trigger a digest while the hosting + * scope is suspended - even if the event handler calls `$apply()` or `$rootScope.$digest()`. + * * Transcluded content exists on a scope that inherits from outside a directive but exists + * as a child of the directive's containing scope. If the containing scope is suspended the + * transcluded scope will also be suspended, even if the scope from which the transcluded + * scope inherits is not suspended. + * * Multiple directives trying to manage the suspended status of a scope can confuse each other: + * * A call to `$suspend()` on an already suspended scope is a no-op. + * * A call to `$resume()` on a non-suspended scope is a no-op. + * * If two directives suspend a scope, then one of them resumes the scope, the scope will no + * longer be suspended. This could result in the other directive believing a scope to be + * suspended when it is not. + * * If a parent scope is suspended then all its descendants will be also excluded from future + * digests whether or not they have been suspended themselves. Note that this also applies to + * isolate child scopes. + * * Calling `$digest()` directly on a descendant of a suspended scope will still run the watchers + * for that scope and its descendants. When digesting we only check whether the current scope is + * locally suspended, rather than checking whether it has a suspended ancestor. + * * Calling `$resume()` on a scope that has a suspended ancestor will not cause the scope to be + * included in future digests until all its ancestors have been resumed. + * * Resolved promises, e.g. from explicit `$q` deferreds and `$http` calls, trigger `$apply()` + * against the `$rootScope` and so will still trigger a global digest even if the promise was + * initiated by a component that lives on a suspended scope. + */ $suspend(): void; + + /** + * @ngdoc method + * @name $rootScope.Scope#$isSuspended + * @kind function + * + * @description + * Call this method to determine if this scope has been explicitly suspended. It will not + * tell you whether an ancestor has been suspended. + * To determine if this scope will be excluded from a digest triggered at the $rootScope, + * for example, you must check all its ancestors: + * + * ``` + * function isExcludedFromDigest(scope) { + * while(scope) { + * if (scope.$isSuspended()) return true; + * scope = scope.$parent; + * } + * return false; + * ``` + * + * Be aware that a scope may not be included in digests if it has a suspended ancestor, + * even if `$isSuspended()` returns false. + * + * @returns true if the current scope has been suspended. + */ $isSuspended(): boolean; + + /** + * @ngdoc method + * @name $rootScope.Scope#$resume + * @kind function + * + * @description + * Resume watchers of this scope subtree in case it was suspended. + * + * See {@link $rootScope.Scope#$suspend} for information about the dangers of using this approach. + */ $resume(): void; + /** * Dispatches an event name upwards through the scope hierarchy notifying the registered $rootScope.Scope listeners. * From ce7505a1d1bb41f1e1901310a5cc8d7870a04ac9 Mon Sep 17 00:00:00 2001 From: Steffen Kowalski Date: Thu, 7 Jun 2018 09:31:07 +0200 Subject: [PATCH 4/4] fixed errors in @types/angular --- types/angular/index.d.ts | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 5ba41ba04e..56a4c46483 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -485,13 +485,8 @@ declare namespace angular { $broadcast(name: string, ...args: any[]): IAngularEvent; $destroy(): void; $digest(): void; - + /** - * @ngdoc method - * @name $rootScope.Scope#$suspend - * @kind function - * - * @description * Suspend watchers of this scope subtree so that they will not be invoked during digest. * * This can be used to optimize your application when you know that running those watchers @@ -530,13 +525,8 @@ declare namespace angular { * initiated by a component that lives on a suspended scope. */ $suspend(): void; - + /** - * @ngdoc method - * @name $rootScope.Scope#$isSuspended - * @kind function - * - * @description * Call this method to determine if this scope has been explicitly suspended. It will not * tell you whether an ancestor has been suspended. * To determine if this scope will be excluded from a digest triggered at the $rootScope, @@ -557,19 +547,14 @@ declare namespace angular { * @returns true if the current scope has been suspended. */ $isSuspended(): boolean; - + /** - * @ngdoc method - * @name $rootScope.Scope#$resume - * @kind function - * - * @description * Resume watchers of this scope subtree in case it was suspended. * - * See {@link $rootScope.Scope#$suspend} for information about the dangers of using this approach. + * See {$rootScope.Scope#$suspend} for information about the dangers of using this approach. */ $resume(): void; - + /** * Dispatches an event name upwards through the scope hierarchy notifying the registered $rootScope.Scope listeners. *