8
8
9
9
import { BehaviorSubject , Subscription } from 'rxjs' ;
10
10
11
- /** Represents the status of change detection batching . */
12
- export interface ChangeDetectionBatchingStatus {
13
- /** Whether change detection is batching . */
14
- isBatching : boolean ;
11
+ /** Represents the status of auto change detection. */
12
+ export interface AutoChangeDetectionStatus {
13
+ /** Whether auto change detection is disabled . */
14
+ isDisabled : boolean ;
15
15
/**
16
16
* An optional callback, if present it indicates that change detection should be run immediately,
17
- * while handling the batching status change. The callback should then be called as soon as change
17
+ * while handling the status change. The callback should then be called as soon as change
18
18
* detection is done.
19
19
*/
20
20
onDetectChangesNow ?: ( ) => void ;
21
21
}
22
22
23
- /** Subject used to dispatch and listen for changes to the change detection batching status . */
24
- const batchChangeDetectionSubject = new BehaviorSubject < ChangeDetectionBatchingStatus > ( {
25
- isBatching : false
23
+ /** Subject used to dispatch and listen for changes to the auto change detection status . */
24
+ const autoChangeDetectionSubject = new BehaviorSubject < AutoChangeDetectionStatus > ( {
25
+ isDisabled : false
26
26
} ) ;
27
27
28
- /** The current subscription to `batchChangeDetectionSubject `. */
29
- let batchChangeDetectionSubscription : Subscription | null ;
28
+ /** The current subscription to `autoChangeDetectionSubject `. */
29
+ let autoChangeDetectionSubscription : Subscription | null ;
30
30
31
31
/**
32
- * The default handler for change detection batching status changes. This handler will be used if
33
- * the specific environment does not install its own.
34
- * @param status The new change detection batching status.
32
+ * The default handler for auto change detection status changes. This handler will be used if the
33
+ * specific environment does not install its own.
34
+ * @param status The new auto change detection status.
35
35
*/
36
- function defaultBatchChangeDetectionHandler ( status : ChangeDetectionBatchingStatus ) {
36
+ function defaultAutoChangeDetectionHandler ( status : AutoChangeDetectionStatus ) {
37
37
status . onDetectChangesNow ?.( ) ;
38
38
}
39
39
40
40
/**
41
- * Allows a test `HarnessEnvironment` to install its own handler for change detection batching
42
- * status changes.
43
- * @param handler The handler for the change detection batching status.
41
+ * Allows a test `HarnessEnvironment` to install its own handler for auto change detection status
42
+ * changes.
43
+ * @param handler The handler for the auto change detection status.
44
44
*/
45
- export function handleChangeDetectionBatching (
46
- handler : ( status : ChangeDetectionBatchingStatus ) => void ) {
47
- stopHandlingChangeDetectionBatching ( ) ;
48
- batchChangeDetectionSubscription = batchChangeDetectionSubject . subscribe ( handler ) ;
45
+ export function handleAutoChangeDetectionStatus (
46
+ handler : ( status : AutoChangeDetectionStatus ) => void ) {
47
+ stopHandlingAutoChangeDetectionStatus ( ) ;
48
+ autoChangeDetectionSubscription = autoChangeDetectionSubject . subscribe ( handler ) ;
49
49
}
50
50
51
- /** Allows a `HarnessEnvironment` to stop handling change detection batching status changes. */
52
- export function stopHandlingChangeDetectionBatching ( ) {
53
- batchChangeDetectionSubscription ?. unsubscribe ( ) ;
54
- batchChangeDetectionSubscription = null ;
51
+ /** Allows a `HarnessEnvironment` to stop handling auto change detection status changes. */
52
+ export function stopHandlingAutoChangeDetectionStatus ( ) {
53
+ autoChangeDetectionSubscription ?. unsubscribe ( ) ;
54
+ autoChangeDetectionSubscription = null ;
55
55
}
56
56
57
57
/**
@@ -63,30 +63,30 @@ export function stopHandlingChangeDetectionBatching() {
63
63
*/
64
64
async function batchChangeDetection < T > ( fn : ( ) => Promise < T > , triggerBeforeAndAfter : boolean ) {
65
65
// If change detection batching is already in progress, just run the function.
66
- if ( batchChangeDetectionSubject . getValue ( ) . isBatching ) {
66
+ if ( autoChangeDetectionSubject . getValue ( ) . isDisabled ) {
67
67
return await fn ( ) ;
68
68
}
69
69
70
70
// If nothing is handling change detection batching, install the default handler.
71
- if ( ! batchChangeDetectionSubscription ) {
72
- batchChangeDetectionSubject . subscribe ( defaultBatchChangeDetectionHandler ) ;
71
+ if ( ! autoChangeDetectionSubscription ) {
72
+ autoChangeDetectionSubject . subscribe ( defaultAutoChangeDetectionHandler ) ;
73
73
}
74
74
75
75
if ( triggerBeforeAndAfter ) {
76
- await new Promise ( resolve => batchChangeDetectionSubject . next ( {
77
- isBatching : true ,
76
+ await new Promise ( resolve => autoChangeDetectionSubject . next ( {
77
+ isDisabled : true ,
78
78
onDetectChangesNow : resolve ,
79
79
} ) ) ;
80
80
const result = await fn ( ) ;
81
- await new Promise ( resolve => batchChangeDetectionSubject . next ( {
82
- isBatching : false ,
81
+ await new Promise ( resolve => autoChangeDetectionSubject . next ( {
82
+ isDisabled : false ,
83
83
onDetectChangesNow : resolve ,
84
84
} ) ) ;
85
85
return result ;
86
86
} else {
87
- batchChangeDetectionSubject . next ( { isBatching : true } ) ;
87
+ autoChangeDetectionSubject . next ( { isDisabled : true } ) ;
88
88
const result = await fn ( ) ;
89
- batchChangeDetectionSubject . next ( { isBatching : false } ) ;
89
+ autoChangeDetectionSubject . next ( { isDisabled : false } ) ;
90
90
return result ;
91
91
}
92
92
}
0 commit comments