File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ import {
2
+ type MutationFilters ,
3
+ notifyManager
4
+ } from '@tanstack/query-core' ;
5
+ import { injectQueryClient } from './query-client' ;
6
+ import { inject , Injectable , InjectionToken } from '@angular/core' ;
7
+ import { distinctUntilChanged , Observable } from 'rxjs' ;
8
+
9
+ @Injectable ( { providedIn : 'root' } )
10
+ export class IsMutatingService {
11
+ private queryClient = injectQueryClient ( ) ;
12
+
13
+ use ( filters ?: MutationFilters ) {
14
+ return new Observable < number > ( ( observer ) => {
15
+ observer . next ( this . queryClient . isMutating ( filters ) ) ;
16
+ this . queryClient . getMutationCache ( ) . subscribe (
17
+ notifyManager . batchCalls ( ( ) => {
18
+ observer . next ( this . queryClient . isMutating ( filters ) ) ;
19
+ } )
20
+ ) ;
21
+ } ) . pipe ( distinctUntilChanged ( ) ) ;
22
+ }
23
+ }
24
+
25
+ const UseIsMutating = new InjectionToken < IsMutatingService [ 'use' ] > (
26
+ 'UseIsFetching' ,
27
+ {
28
+ providedIn : 'root' ,
29
+ factory ( ) {
30
+ const isMutating = new IsMutatingService ( ) ;
31
+ return isMutating . use . bind ( isMutating ) ;
32
+ } ,
33
+ }
34
+ ) ;
35
+
36
+ export function injectIsMutating ( ) {
37
+ return inject ( UseIsMutating ) ;
38
+ }
You can’t perform that action at this time.
0 commit comments