Skip to content

Commit 3d61dd2

Browse files
feat: update to NgRx Signals 18 Release
1 parent c24cba8 commit 3d61dd2

21 files changed

+307
-308
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Starting with 18.0.0-rc.2, we have a [strict version dependency](#why-is-the-ver
2525
|----------------|----------------------------------|
2626
| <= 18.0.0-rc.1 | 0.0.4 |
2727
| 18.0.0-rc.2 | 18.0.0-rc.2.x |
28+
| 18.0.0-rc.3 | (not supported) |
29+
| 18.0.0 | 18.0.0 |
2830

2931
To install it, run
3032

apps/demo/src/app/lazy-routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { FlightEditSimpleComponent } from './flight-search-data-service-simple/f
66
import { FlightSearchDynamicComponent } from './flight-search-data-service-dynamic/flight-search.component';
77
import { FlightEditDynamicComponent } from './flight-search-data-service-dynamic/flight-edit.component';
88
import { TodoStorageSyncComponent } from './todo-storage-sync/todo-storage-sync.component';
9-
import { provideFlightStore } from './flight-search-redux-connector/+state/redux';
10-
import { FlightSearchReducConnectorComponent } from './flight-search-redux-connector/flight-search.component';
119
import { FlightSearchWithPaginationComponent } from './flight-search-with-pagination/flight-search-with-pagination.component';
10+
import { FlightSearchReducConnectorComponent } from './flight-search-redux-connector/flight-search.component';
11+
import { provideFlightStore } from './flight-search-redux-connector/+state/redux';
1212

1313
export const lazyRoutes: Route[] = [
1414
{ path: 'todo', component: TodoComponent },
@@ -24,7 +24,7 @@ export const lazyRoutes: Route[] = [
2424
},
2525
{
2626
path: 'flight-search-with-pagination',
27-
component: FlightSearchWithPaginationComponent
27+
component: FlightSearchWithPaginationComponent,
2828
},
2929
{ path: 'flight-edit-dynamic/:id', component: FlightEditDynamicComponent },
3030
{ path: 'todo-storage-sync', component: TodoStorageSyncComponent },

libs/ngrx-toolkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@angular-architects/ngrx-toolkit",
3-
"version": "18.0.0-rc.2.0",
3+
"version": "18.0.0",
44
"license": "MIT",
55
"repository": {
66
"type": "GitHub",
77
"url": "https://github.com/angular-architects/ngrx-toolkit"
88
},
99
"peerDependencies": {
10-
"@ngrx/signals": "18.0.0-rc.2"
10+
"@ngrx/signals": "18.0.0"
1111
},
1212
"dependencies": {
1313
"tslib": "^2.3.0"

libs/ngrx-toolkit/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from './lib/with-call-state';
1010
export * from './lib/with-undo-redo';
1111
export * from './lib/with-data-service';
1212
export { withStorageSync, SyncConfig } from './lib/with-storage-sync';
13+
export * from './lib/with-pagination';
14+
1315
export * from './lib/redux-connector';
1416
export * from './lib/redux-connector/rxjs-interop';
15-
export * from './lib/with-pagination';
Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,63 @@
1-
import { EnvironmentProviders, Signal, Type } from "@angular/core";
2-
import { DeepSignal } from "@ngrx/signals/src/deep-signal";
3-
import { SignalStoreFeatureResult } from "@ngrx/signals/src/signal-store-models";
4-
import { StateSignal } from "@ngrx/signals/src/state-signal";
5-
import { Action, ActionCreator, ActionType, Prettify } from "@ngrx/store/src/models";
6-
import { Observable, Unsubscribable } from "rxjs";
1+
import { EnvironmentProviders, Signal, Type } from '@angular/core';
2+
import { DeepSignal } from '@ngrx/signals/src/deep-signal';
3+
import {
4+
SignalStoreFeatureResult,
5+
StateSignals,
6+
} from '@ngrx/signals/src/signal-store-models';
7+
import {
8+
Action,
9+
ActionCreator,
10+
ActionType,
11+
Prettify,
12+
} from '@ngrx/store/src/models';
13+
import { Observable, Unsubscribable } from 'rxjs';
714

8-
9-
export type IncludePropType<T, V, WithNevers =
10-
{ [K in keyof T]: Exclude<T[K], undefined> extends V
11-
? T[K] extends Record<string, unknown>
12-
? IncludePropType<T[K], V>
13-
: T[K]
14-
: never
15-
}> = Prettify<
16-
Pick<
17-
WithNevers,
18-
{ [K in keyof WithNevers]: WithNevers[K] extends never
15+
export type IncludePropType<
16+
T,
17+
V,
18+
WithNevers = {
19+
[K in keyof T]: Exclude<T[K], undefined> extends V
20+
? T[K] extends Record<string, unknown>
21+
? IncludePropType<T[K], V>
22+
: T[K]
23+
: never;
24+
}
25+
> = Prettify<
26+
Pick<
27+
WithNevers,
28+
{
29+
[K in keyof WithNevers]: WithNevers[K] extends never
1930
? never
2031
: K extends string
21-
? K
22-
: never
23-
}[keyof WithNevers]
24-
>
25-
>;
32+
? K
33+
: never;
34+
}[keyof WithNevers]
35+
>
36+
>;
2637

27-
export type Store = Type<Record<string, unknown> & StateSignal<SignalStoreFeatureResult['state']>>;
38+
export type Store = Type<
39+
Record<string, unknown> & StateSignals<SignalStoreFeatureResult['state']>
40+
>;
2841

29-
export type CreateReduxState<
30-
StoreName extends string,
31-
STORE extends Store
32-
> = {
33-
[K in StoreName as `provide${Capitalize<K>}Store`]: (connectReduxDevtools?: boolean) => EnvironmentProviders
42+
export type CreateReduxState<StoreName extends string, STORE extends Store> = {
43+
[K in StoreName as `provide${Capitalize<K>}Store`]: (
44+
connectReduxDevtools?: boolean
45+
) => EnvironmentProviders;
3446
} & {
35-
[K in StoreName as `inject${Capitalize<K>}Store`]: () => InjectableReduxSlice<STORE>
47+
[K in StoreName as `inject${Capitalize<K>}Store`]: () => InjectableReduxSlice<STORE>;
3648
};
3749

38-
export type Selectors<STORE extends Store> = IncludePropType<InstanceType<STORE>, Signal<unknown> | DeepSignal<unknown>>;
39-
export type Dispatch = { dispatch: (input: Action | Observable<Action> | Signal<Action>) => Unsubscribable };
40-
export type InjectableReduxSlice<STORE extends Store> = Selectors<STORE> & Dispatch;
50+
export type Selectors<STORE extends Store> = IncludePropType<
51+
InstanceType<STORE>,
52+
Signal<unknown> | DeepSignal<unknown>
53+
>;
54+
export type Dispatch = {
55+
dispatch: (
56+
input: Action | Observable<Action> | Signal<Action>
57+
) => Unsubscribable;
58+
};
59+
export type InjectableReduxSlice<STORE extends Store> = Selectors<STORE> &
60+
Dispatch;
4161

4262
export type ExtractActionTypes<Creators extends readonly ActionCreator[]> = {
4363
[Key in keyof Creators]: Creators[Key] extends ActionCreator<infer T>
@@ -51,17 +71,13 @@ export interface ActionMethod<T, V extends Action = Action> {
5171

5272
export interface StoreMethod<
5373
Creators extends readonly ActionCreator[],
54-
ResultState = unknown,
74+
ResultState = unknown
5575
> {
56-
(
57-
action: ActionType<Creators[number]>
58-
): ResultState;
76+
(action: ActionType<Creators[number]>): ResultState;
5977
}
6078

61-
export interface MapperTypes<
62-
Creators extends readonly ActionCreator[]
63-
> {
64-
types: ExtractActionTypes<Creators>,
65-
storeMethod: StoreMethod<Creators>,
66-
resultMethod?: (...args: unknown[]) => unknown
79+
export interface MapperTypes<Creators extends readonly ActionCreator[]> {
80+
types: ExtractActionTypes<Creators>;
81+
storeMethod: StoreMethod<Creators>;
82+
resultMethod?: (...args: unknown[]) => unknown;
6783
}

libs/ngrx-toolkit/src/lib/shared/empty.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/ngrx-toolkit/src/lib/shared/signal-store-models.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@
1515
import { Signal } from '@angular/core';
1616
import { EntityId } from '@ngrx/signals/entities';
1717

18-
export type SignalStoreFeatureResult = {
19-
state: object;
20-
computed: Record<string, Signal<unknown>>;
21-
methods: Record<string, Function>;
22-
};
23-
24-
export type EmptyFeatureResult = {
25-
state: {};
26-
computed: {};
27-
methods: {};
28-
};
29-
3018
// withEntites models
3119
export type EntityState<Entity> = {
3220
entityMap: Record<EntityId, Entity>;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { patchState, signalStore } from '@ngrx/signals';
2-
import { setLoaded, setLoading, withCallState } from 'ngrx-toolkit';
2+
import { setLoaded, setLoading, withCallState } from './with-call-state';
33

44
describe('withCallState', () => {
55
it('should use and update a callState', () => {
6-
const DataStore = signalStore(withCallState());
6+
const DataStore = signalStore({ protectedState: false }, withCallState());
77
const dataStore = new DataStore();
88

99
patchState(dataStore, setLoading());
@@ -13,7 +13,10 @@ describe('withCallState', () => {
1313
});
1414

1515
it('should use the callState for a collection', () => {
16-
const DataStore = signalStore(withCallState({ collection: 'entities' }));
16+
const DataStore = signalStore(
17+
{ protectedState: false },
18+
withCallState({ collection: 'entities' })
19+
);
1720
const dataStore = new DataStore();
1821

1922
patchState(dataStore, setLoaded('entities'));

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Signal, computed } from '@angular/core';
22
import {
3+
EmptyFeatureResult,
34
SignalStoreFeature,
45
signalStoreFeature,
56
withComputed,
67
withState,
78
} from '@ngrx/signals';
8-
import { Empty } from './shared/empty';
99

1010
export type CallState = 'init' | 'loading' | 'loaded' | { error: string };
1111

@@ -44,19 +44,17 @@ export function getCallStateKeys(config?: { collection?: string }) {
4444
export function withCallState<Collection extends string>(config: {
4545
collection: Collection;
4646
}): SignalStoreFeature<
47-
{ state: Empty; methods: Empty; computed: Empty },
48-
{
47+
EmptyFeatureResult,
48+
EmptyFeatureResult & {
4949
state: NamedCallStateSlice<Collection>;
5050
computed: NamedCallStateSignals<Collection>;
51-
methods: Empty;
5251
}
5352
>;
5453
export function withCallState(): SignalStoreFeature<
55-
{ state: Empty; methods: Empty; computed: Empty },
56-
{
54+
EmptyFeatureResult,
55+
EmptyFeatureResult & {
5756
state: CallStateSlice;
5857
computed: CallStateSignals;
59-
methods: Empty;
6058
}
6159
>;
6260
export function withCallState<Collection extends string>(config?: {
@@ -106,7 +104,7 @@ export function setError<Prop extends string | undefined = undefined>(
106104
error: unknown,
107105
prop?: Prop
108106
): SetCallState<Prop> {
109-
let errorMessage = '';
107+
let errorMessage: string;
110108

111109
if (!error) {
112110
errorMessage = '';

0 commit comments

Comments
 (0)