@angular-architects/ngrx-toolkit 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -4
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,7 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NgRx Toolkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/angular-architects/ngrx-toolkit/main/logo.png" width="320" style="text-align: center">
|
|
5
|
+
</p>
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
NgRx Toolkit is an extension to the NgRx Signals Store. **It is still in beta** but already offers following features:
|
|
8
|
+
|
|
9
|
+
- Devtools: Integration into Redux Devtools
|
|
10
|
+
- Redux: Possibility to use the Redux Pattern (Reducer, Actions, Effects)
|
|
11
|
+
|
|
12
|
+
To install it, run
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
npm i @angular-architects/ngrx-toolkit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Devtools: `withDevtools()`
|
|
19
|
+
|
|
20
|
+
This extension is very easy to use. Just add it to a `signalStore`. Example:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
export const FlightStore = signalStore(
|
|
24
|
+
{ providedIn: 'root' },
|
|
25
|
+
withDevtools('flights'), // <-- add this
|
|
26
|
+
withState({ flights: [] as Flight[] }),
|
|
27
|
+
// ...
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Redux: `withRedux()`
|
|
32
|
+
|
|
33
|
+
`withRedux()` bring back the Redux pattern into the Signal Store.
|
|
34
|
+
|
|
35
|
+
It can be combined with any other extension of the Signal Store.
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
export const FlightStore = signalStore(
|
|
41
|
+
{ providedIn: 'root' },
|
|
42
|
+
withState({ flights: [] as Flight[] }),
|
|
43
|
+
withRedux({
|
|
44
|
+
actions: {
|
|
45
|
+
public: {
|
|
46
|
+
load: payload<{ from: string; to: string }>(),
|
|
47
|
+
},
|
|
48
|
+
private: {
|
|
49
|
+
loaded: payload<{ flights: Flight[] }>(),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
reducer(actions, on) {
|
|
53
|
+
on(actions.loaded, ({ flights }, state) => {
|
|
54
|
+
patchState(state, 'flights loaded', { flights });
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
effects(actions, create) {
|
|
58
|
+
const httpClient = inject(HttpClient);
|
|
59
|
+
return {
|
|
60
|
+
load$: create(actions.load).pipe(
|
|
61
|
+
switchMap(({ from, to }) =>
|
|
62
|
+
httpClient.get<Flight[]>(
|
|
63
|
+
'https://demo.angulararchitects.io/api/flight',
|
|
64
|
+
{
|
|
65
|
+
params: new HttpParams().set('from', from).set('to', to),
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
tap((flights) => actions.loaded({ flights })),
|
|
70
|
+
),
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
```
|
|
6
76
|
|
|
7
|
-
Run `nx test ngrx-toolkit` to execute the unit tests.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-architects/ngrx-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^17.0.0",
|
|
6
6
|
"@angular/core": "^17.0.0",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"tslib": "^2.3.0"
|
|
11
11
|
},
|
|
12
|
-
"private": false,
|
|
13
12
|
"sideEffects": false,
|
|
14
13
|
"module": "fesm2022/angular-architects-ngrx-toolkit.mjs",
|
|
15
14
|
"typings": "index.d.ts",
|