Skip to content

Commit 8c502c7

Browse files
feat: Enhanced withCallState to accept mutliple collection configuration backward compatibility
1 parent 661f275 commit 8c502c7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

libs/ngrx-toolkit/src/lib/with-call-state.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type SetCallState<Prop extends string | undefined> = Prop extends string
3131
? NamedCallStateSlice<Prop>
3232
: CallStateSlice;
3333

34-
export function getCallStateKeys(collection?: string) {
34+
export function deriveCallStateKeys<Collection extends string>(collection?: Collection) {
3535
return {
3636
callStateKey: collection ? `${collection}CallState` : 'callState',
3737
loadingKey: collection ? `${collection}Loading` : 'loading',
@@ -40,7 +40,12 @@ export function getCallStateKeys(collection?: string) {
4040
};
4141
}
4242

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[]){
4449
return Array.isArray(collection) ? collection : [collection];
4550
}
4651

@@ -84,7 +89,7 @@ export function withCallState<Collection extends string>(config?: {
8489
const collection = getCollectionArray(config.collection);
8590
return collection.reduce<Record<string, Signal<unknown>>>((acc, cur: string) => {
8691
const { callStateKey, errorKey, loadedKey, loadingKey } =
87-
getCallStateKeys(cur);
92+
deriveCallStateKeys(cur);
8893
const callState = state[callStateKey] as Signal<CallState>;
8994
return {
9095
...acc,
@@ -97,7 +102,7 @@ export function withCallState<Collection extends string>(config?: {
97102
};
98103
}, {});
99104
}
100-
const { callStateKey, errorKey, loadedKey, loadingKey } = getCallStateKeys();
105+
const { callStateKey, errorKey, loadedKey, loadingKey } = deriveCallStateKeys();
101106
const callState = state[callStateKey] as Signal<CallState>;
102107
return {
103108
[loadingKey]: computed(() => callState() === 'loading'),

0 commit comments

Comments
 (0)