@@ -18,23 +18,26 @@ import {
18
18
} from 'rxjs' ;
19
19
import { InternalRxState , RxStateful , RxStatefulConfig , RxStatefulWithError , } from './types/types' ;
20
20
import { _handleSyncValue } from './util/handle-sync-value' ;
21
+ import { defaultAccumulationFn } from "./types/accumulation-fn" ;
21
22
22
23
/**
23
24
* @publicApi
24
25
*/
25
26
export function rxStateful$ < T , E = unknown > ( source$ : Observable < T > ) : RxStateful < T , E > ;
26
- export function rxStateful$ < T , E = unknown > ( source$ : Observable < T > , config : RxStatefulConfig ) : RxStateful < T , E > ;
27
+ export function rxStateful$ < T , E = unknown > ( source$ : Observable < T > , config : RxStatefulConfig < T , E > ) : RxStateful < T , E > ;
27
28
export function rxStateful$ < T , E = unknown > (
28
29
source$ : Observable < T > ,
29
- config ?: RxStatefulConfig
30
+ config ?: RxStatefulConfig < T , E >
30
31
) : RxStateful < T , E > {
31
32
const error$$ = new Subject < RxStatefulWithError < T , E > > ( ) ;
32
- const mergedConfig : RxStatefulConfig = {
33
+ const mergedConfig : RxStatefulConfig < T , E > = {
33
34
keepValueOnRefresh : true ,
34
35
...config ,
35
36
} ;
37
+ const accumulationFn = mergedConfig . accumulationFn ?? defaultAccumulationFn ;
36
38
37
- const refreshTriggerIsBehaivorSubject = ( config : RxStatefulConfig ) =>
39
+
40
+ const refreshTriggerIsBehaivorSubject = ( config : RxStatefulConfig < T , E > ) =>
38
41
config . refreshTrigger$ instanceof BehaviorSubject ;
39
42
40
43
const refresh$ = mergedConfig ?. refreshTrigger$ ?? new Subject < unknown > ( ) ;
@@ -87,10 +90,7 @@ export function rxStateful$<T, E = unknown>(
87
90
88
91
const state$ = merge ( request$ , refreshedRequest$ , error$$ ) . pipe (
89
92
scan (
90
- // @ts -ignore
91
- ( acc , curr ) => {
92
- return { ...acc , ...curr } ;
93
- } ,
93
+ accumulationFn ,
94
94
{ isLoading : false , isRefreshing : false , value : undefined , error : undefined , context : 'idle' }
95
95
) ,
96
96
distinctUntilChanged ( ) ,
0 commit comments