Skip to content

Commit 4cf48a5

Browse files
authored
feat: enhanced withDataService to require callState collection name (#154)
1 parent 0b1a4b9 commit 4cf48a5

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

libs/ngrx-toolkit/src/lib/with-data-service.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ describe('withDataService', () => {
383383
});
384384
}));
385385

386+
it('should ensure that collection name is provided in callState ', () => {
387+
// @ts-expect-error should not allow `withCallState` without collection name if `withDataService` has it
388+
signalStore(
389+
withCallState(),
390+
withEntities({
391+
entity: type<Flight>(),
392+
collection: 'flight',
393+
}),
394+
withDataService({
395+
dataServiceType: MockFlightService,
396+
filter: { from: 'Paris', to: 'New York' },
397+
collection: 'flight',
398+
})
399+
);
400+
});
401+
386402
// TODO 3A: setting error state (without named collection)
387403
// TODO 3B: setting error state (with named collection)
388404
});

libs/ngrx-toolkit/src/lib/with-data-service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ import {
1111
} from '@ngrx/signals';
1212
import {
1313
CallState,
14+
NamedCallStateSlice,
1415
getCallStateKeys,
1516
setError,
1617
setLoaded,
1718
setLoading,
1819
} from './with-call-state';
1920
import {
21+
NamedEntityState,
2022
setAllEntities,
2123
EntityId,
2224
addEntity,
2325
updateEntity,
2426
removeEntity,
2527
} from '@ngrx/signals/entities';
26-
import { EntityState, NamedEntityComputed } from './shared/signal-store-models';
28+
import { EntityState } from './shared/signal-store-models';
2729

2830
export type Filter = Record<string, unknown>;
2931
export type Entity = { id: EntityId };
@@ -201,10 +203,9 @@ export function withDataService<
201203
filter: F;
202204
collection: Collection;
203205
}): SignalStoreFeature<
204-
// These alternatives break type inference:
205-
// state: { callState: CallState } & NamedEntityState<E, Collection>,
206-
// state: NamedEntityState<E, Collection>,
207-
EmptyFeatureResult & { props: NamedEntityComputed<E, Collection> },
206+
EmptyFeatureResult & {
207+
state: NamedCallStateSlice<Collection> & NamedEntityState<E, Collection>;
208+
},
208209
{
209210
state: NamedDataServiceState<E, F, Collection>;
210211
props: NamedDataServiceComputed<E, Collection>;

0 commit comments

Comments
 (0)