@@ -2,6 +2,8 @@ import { NgZone } from '@angular/core';
2
2
import { MonoTypeOperatorFunction , Observable } from 'rxjs' ;
3
3
import { filter , mapTo , switchMap } from 'rxjs/operators' ;
4
4
import {
5
+ cancelCallback ,
6
+ scheduleCallback ,
5
7
unstable_cancelCallback ,
6
8
unstable_scheduleCallback ,
7
9
PriorityLevel ,
@@ -89,6 +91,21 @@ const idleStrategy: RxStrategyCredentials = {
89
91
} ,
90
92
} ;
91
93
94
+ const postTaskUserVisibleStrategy : RxStrategyCredentials = {
95
+ name : 'userVisible' ,
96
+ work : ( cdRef ) => cdRef . detectChanges ( ) ,
97
+ behavior : ( { work, scope, ngZone } ) => {
98
+ return ( o$ ) =>
99
+ o$ . pipe (
100
+ scheduleOnPostTaskQueue ( work , {
101
+ ngZone,
102
+ priority : PriorityLevel . IdlePriority ,
103
+ scope,
104
+ } )
105
+ ) ;
106
+ } ,
107
+ } ;
108
+
92
109
function scheduleOnQueue < T > (
93
110
work : ( ...args : any [ ] ) => void ,
94
111
options : {
@@ -97,6 +114,39 @@ function scheduleOnQueue<T>(
97
114
delay ?: number ;
98
115
ngZone : NgZone ;
99
116
}
117
+ ) : MonoTypeOperatorFunction < T > {
118
+ const scope = ( options . scope as Record < string , unknown > ) || { } ;
119
+ return ( o$ : Observable < T > ) : Observable < T > =>
120
+ o$ . pipe (
121
+ filter ( ( ) => ! coalescingManager . isCoalescing ( scope ) ) ,
122
+ switchMap ( ( v ) =>
123
+ new Observable < T > ( ( subscriber ) => {
124
+ coalescingManager . add ( scope ) ;
125
+ const task = scheduleCallback (
126
+ options . priority ,
127
+ ( ) => {
128
+ work ( ) ;
129
+ coalescingManager . remove ( scope ) ;
130
+ subscriber . next ( v ) ;
131
+ } ,
132
+ { delay : options . delay }
133
+ ) ;
134
+ return ( ) => {
135
+ coalescingManager . remove ( scope ) ;
136
+ cancelCallback ( task ) ;
137
+ } ;
138
+ } ) . pipe ( mapTo ( v ) )
139
+ )
140
+ ) ;
141
+ }
142
+ function scheduleOnPostTaskQueue < T > (
143
+ work : ( ...args : any [ ] ) => void ,
144
+ options : {
145
+ priority : PriorityLevel ;
146
+ scope : coalescingObj ;
147
+ delay ?: number ;
148
+ ngZone : NgZone ;
149
+ }
100
150
) : MonoTypeOperatorFunction < T > {
101
151
const scope = ( options . scope as Record < string , unknown > ) || { } ;
102
152
return ( o$ : Observable < T > ) : Observable < T > =>
@@ -131,4 +181,5 @@ export const RX_CONCURRENT_STRATEGIES: RxConcurrentStrategies = {
131
181
normal : normalStrategy ,
132
182
low : lowStrategy ,
133
183
idle : idleStrategy ,
184
+ userVisible : postTaskUserVisibleStrategy ,
134
185
} ;
0 commit comments