@@ -31,7 +31,7 @@ export type SetCallState<Prop extends string | undefined> = Prop extends string
31
31
? NamedCallStateSlice < Prop >
32
32
: CallStateSlice ;
33
33
34
- export function getCallStateKeys ( collection ?: string ) {
34
+ export function deriveCallStateKeys < Collection extends string > ( collection ?: Collection ) {
35
35
return {
36
36
callStateKey : collection ? `${ collection } CallState` : 'callState' ,
37
37
loadingKey : collection ? `${ collection } Loading` : 'loading' ,
@@ -40,7 +40,12 @@ export function getCallStateKeys(collection?: string) {
40
40
} ;
41
41
}
42
42
43
- function getCollectionArray ( collection : string | string [ ] ) {
43
+ export function getCallStateKeys ( config ?: { collection ?: string } ) {
44
+ const prop = config ?. collection ;
45
+ return deriveCallStateKeys ( prop ) ;
46
+ }
47
+
48
+ export function getCollectionArray ( collection : string | string [ ] ) {
44
49
return Array . isArray ( collection ) ? collection : [ collection ] ;
45
50
}
46
51
@@ -84,7 +89,7 @@ export function withCallState<Collection extends string>(config?: {
84
89
const collection = getCollectionArray ( config . collection ) ;
85
90
return collection . reduce < Record < string , Signal < unknown > > > ( ( acc , cur : string ) => {
86
91
const { callStateKey, errorKey, loadedKey, loadingKey } =
87
- getCallStateKeys ( cur ) ;
92
+ deriveCallStateKeys ( cur ) ;
88
93
const callState = state [ callStateKey ] as Signal < CallState > ;
89
94
return {
90
95
...acc ,
@@ -97,7 +102,7 @@ export function withCallState<Collection extends string>(config?: {
97
102
} ;
98
103
} , { } ) ;
99
104
}
100
- const { callStateKey, errorKey, loadedKey, loadingKey } = getCallStateKeys ( ) ;
105
+ const { callStateKey, errorKey, loadedKey, loadingKey } = deriveCallStateKeys ( ) ;
101
106
const callState = state [ callStateKey ] as Signal < CallState > ;
102
107
return {
103
108
[ loadingKey ] : computed ( ( ) => callState ( ) === 'loading' ) ,
0 commit comments