@nrwl/angular 14.4.3 → 14.5.0-beta.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/CHANGELOG.md +1 -1
- package/esm2020/src/runtime/nx/data-persistence.mjs +257 -181
- package/esm2020/src/runtime/nx/nx.module.mjs +3 -1
- package/fesm2015/nrwl-angular.mjs +258 -180
- package/fesm2015/nrwl-angular.mjs.map +1 -1
- package/fesm2020/nrwl-angular.mjs +258 -180
- package/fesm2020/nrwl-angular.mjs.map +1 -1
- package/ng-package.json +2 -1
- package/package.json +10 -9
- package/src/generators/component-cypress-spec/component-cypress-spec.js +6 -5
- package/src/generators/component-cypress-spec/component-cypress-spec.js.map +1 -1
- package/src/generators/component-cypress-spec/files/{__componentFileName__.spec.ts__tmpl__ → __componentFileName__.__fileExt__} +0 -0
- package/src/generators/ng-add/utilities/e2e.migrator.d.ts +14 -2
- package/src/generators/ng-add/utilities/e2e.migrator.js +274 -43
- package/src/generators/ng-add/utilities/e2e.migrator.js.map +1 -1
- package/src/generators/ng-add/utilities/file-change-recorder.d.ts +16 -0
- package/src/generators/ng-add/utilities/file-change-recorder.js +37 -0
- package/src/generators/ng-add/utilities/file-change-recorder.js.map +1 -0
- package/src/generators/ngrx/schema.d.ts +9 -1
- package/src/generators/ngrx/schema.json +4 -2
- package/src/runtime/nx/data-persistence.d.ts +256 -192
- package/src/runtime/nx/data-persistence.js +256 -180
- package/src/runtime/nx/data-persistence.js.map +1 -1
- package/src/runtime/nx/nx.module.d.ts +2 -0
- package/src/runtime/nx/nx.module.js +2 -0
- package/src/runtime/nx/nx.module.js.map +1 -1
- package/src/utils/mf/with-module-federation.js +4 -1
- package/src/utils/mf/with-module-federation.js.map +1 -1
|
@@ -61,12 +61,14 @@
|
|
|
61
61
|
"type": "string",
|
|
62
62
|
"enum": ["classes", "creators"],
|
|
63
63
|
"default": "creators",
|
|
64
|
-
"description": "Specifies whether to use class-based or creator functions for actions, reducers, and effects."
|
|
64
|
+
"description": "Specifies whether to use class-based or creator functions for actions, reducers, and effects.",
|
|
65
|
+
"x-deprecated": "Classes syntax is deprecated and this option will be removed in v15. Creators syntax will be the default in v15 and this option will be removed."
|
|
65
66
|
},
|
|
66
67
|
"useDataPersistence": {
|
|
67
68
|
"type": "boolean",
|
|
68
69
|
"default": false,
|
|
69
|
-
"description": "Generate NgRx Effects with the `DataPersistence` helper service. Set to false to use plain effects data persistence operators."
|
|
70
|
+
"description": "Generate NgRx Effects with the `DataPersistence` helper service. Set to false to use plain effects data persistence operators.",
|
|
71
|
+
"x-deprecated": "This option is deprecated and will be removed in v15. Using the individual operators is recommended."
|
|
70
72
|
},
|
|
71
73
|
"barrels": {
|
|
72
74
|
"type": "boolean",
|
|
@@ -4,31 +4,19 @@ import { Actions } from '@ngrx/effects';
|
|
|
4
4
|
import { Action, Store, ActionCreator } from '@ngrx/store';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
|
-
/**
|
|
8
|
-
* See {@link DataPersistence.pessimisticUpdate} for more information.
|
|
9
|
-
*/
|
|
10
7
|
export interface PessimisticUpdateOpts<T extends Array<unknown>, A> {
|
|
11
8
|
run(a: A, ...slices: [...T]): Observable<Action> | Action | void;
|
|
12
9
|
onError(a: A, e: any): Observable<any> | any;
|
|
13
10
|
}
|
|
14
|
-
/**
|
|
15
|
-
* See {@link DataPersistence.pessimisticUpdate} for more information.
|
|
16
|
-
*/
|
|
17
11
|
export interface OptimisticUpdateOpts<T extends Array<unknown>, A> {
|
|
18
12
|
run(a: A, ...slices: [...T]): Observable<Action> | Action | void;
|
|
19
13
|
undoAction(a: A, e: any): Observable<Action> | Action;
|
|
20
14
|
}
|
|
21
|
-
/**
|
|
22
|
-
* See {@link DataPersistence.fetch} for more information.
|
|
23
|
-
*/
|
|
24
15
|
export interface FetchOpts<T extends Array<unknown>, A> {
|
|
25
16
|
id?(a: A, ...slices: [...T]): any;
|
|
26
17
|
run(a: A, ...slices: [...T]): Observable<Action> | Action | void;
|
|
27
18
|
onError?(a: A, e: any): Observable<any> | any;
|
|
28
19
|
}
|
|
29
|
-
/**
|
|
30
|
-
* See {@link DataPersistence.navigation} for more information.
|
|
31
|
-
*/
|
|
32
20
|
export interface HandleNavigationOpts<T extends Array<unknown>> {
|
|
33
21
|
run(a: ActivatedRouteSnapshot, ...slices: [...T]): Observable<Action> | Action | void;
|
|
34
22
|
onError?(a: ActivatedRouteSnapshot, e: any): Observable<any> | any;
|
|
@@ -37,211 +25,287 @@ export declare type ActionOrActionWithStates<T extends Array<unknown>, A> = A |
|
|
|
37
25
|
export declare type ActionOrActionWithState<T, A> = ActionOrActionWithStates<[T], A>;
|
|
38
26
|
export declare type ActionStatesStream<T extends Array<unknown>, A> = Observable<ActionOrActionWithStates<T, A>>;
|
|
39
27
|
export declare type ActionStateStream<T, A> = Observable<ActionOrActionWithStates<[T], A>>;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @whatItDoes Handles pessimistic updates (updating the server first).
|
|
31
|
+
*
|
|
32
|
+
* Updating the server, when implemented naively, suffers from race conditions and poor error handling.
|
|
33
|
+
*
|
|
34
|
+
* `pessimisticUpdate` addresses these problems. It runs all fetches in order, which removes race conditions
|
|
35
|
+
* and forces the developer to handle errors.
|
|
36
|
+
*
|
|
37
|
+
* ## Example:
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @Injectable()
|
|
41
|
+
* class TodoEffects {
|
|
42
|
+
* updateTodo$ = createEffect(() =>
|
|
43
|
+
* this.actions$.pipe(
|
|
44
|
+
* ofType('UPDATE_TODO'),
|
|
45
|
+
* pessimisticUpdate({
|
|
46
|
+
* // provides an action
|
|
47
|
+
* run: (action: UpdateTodo) => {
|
|
48
|
+
* // update the backend first, and then dispatch an action that will
|
|
49
|
+
* // update the client side
|
|
50
|
+
* return this.backend.updateTodo(action.todo.id, action.todo).pipe(
|
|
51
|
+
* map((updated) => ({
|
|
52
|
+
* type: 'UPDATE_TODO_SUCCESS',
|
|
53
|
+
* todo: updated,
|
|
54
|
+
* }))
|
|
55
|
+
* );
|
|
56
|
+
* },
|
|
57
|
+
* onError: (action: UpdateTodo, error: any) => {
|
|
58
|
+
* // we don't need to undo the changes on the client side.
|
|
59
|
+
* // we can dispatch an error, or simply log the error here and return `null`
|
|
60
|
+
* return null;
|
|
61
|
+
* },
|
|
62
|
+
* })
|
|
63
|
+
* )
|
|
64
|
+
* );
|
|
65
|
+
*
|
|
66
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
|
71
|
+
* of the effect to false, like this:
|
|
72
|
+
*
|
|
73
|
+
* ```typescript
|
|
74
|
+
* class TodoEffects {
|
|
75
|
+
* updateTodo$ = createEffect(() =>
|
|
76
|
+
* this.actions$.pipe(
|
|
77
|
+
* //...
|
|
78
|
+
* ), { dispatch: false }
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param opts
|
|
84
|
+
*/
|
|
40
85
|
export declare function pessimisticUpdate<T extends Array<unknown>, A extends Action>(opts: PessimisticUpdateOpts<T, A>): (source: ActionStatesStream<T, A>) => Observable<Action>;
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @whatItDoes Handles optimistic updates (updating the client first).
|
|
89
|
+
*
|
|
90
|
+
* It runs all fetches in order, which removes race conditions and forces the developer to handle errors.
|
|
91
|
+
*
|
|
92
|
+
* When using `optimisticUpdate`, in case of a failure, the developer has already updated the state locally,
|
|
93
|
+
* so the developer must provide an undo action.
|
|
94
|
+
*
|
|
95
|
+
* The error handling must be done in the callback, or by means of the undo action.
|
|
96
|
+
*
|
|
97
|
+
* ## Example:
|
|
98
|
+
*
|
|
99
|
+
* ```typescript
|
|
100
|
+
* @Injectable()
|
|
101
|
+
* class TodoEffects {
|
|
102
|
+
* updateTodo$ = createEffect(() =>
|
|
103
|
+
* this.actions$.pipe(
|
|
104
|
+
* ofType('UPDATE_TODO'),
|
|
105
|
+
* optimisticUpdate({
|
|
106
|
+
* // provides an action
|
|
107
|
+
* run: (action: UpdateTodo) => {
|
|
108
|
+
* return this.backend.updateTodo(action.todo.id, action.todo).pipe(
|
|
109
|
+
* mapTo({
|
|
110
|
+
* type: 'UPDATE_TODO_SUCCESS',
|
|
111
|
+
* })
|
|
112
|
+
* );
|
|
113
|
+
* },
|
|
114
|
+
* undoAction: (action: UpdateTodo, error: any) => {
|
|
115
|
+
* // dispatch an undo action to undo the changes in the client state
|
|
116
|
+
* return {
|
|
117
|
+
* type: 'UNDO_TODO_UPDATE',
|
|
118
|
+
* todo: action.todo,
|
|
119
|
+
* };
|
|
120
|
+
* },
|
|
121
|
+
* })
|
|
122
|
+
* )
|
|
123
|
+
* );
|
|
124
|
+
*
|
|
125
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
|
130
|
+
* of the effect to false, like this:
|
|
131
|
+
*
|
|
132
|
+
* ```typescript
|
|
133
|
+
* class TodoEffects {
|
|
134
|
+
* updateTodo$ = createEffect(() =>
|
|
135
|
+
* this.actions$.pipe(
|
|
136
|
+
* //...
|
|
137
|
+
* ), { dispatch: false }
|
|
138
|
+
* );
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param opts
|
|
143
|
+
*/
|
|
41
144
|
export declare function optimisticUpdate<T extends Array<unknown>, A extends Action>(opts: OptimisticUpdateOpts<T, A>): (source: ActionStatesStream<T, A>) => Observable<Action>;
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
* @whatItDoes Handles data fetching.
|
|
148
|
+
*
|
|
149
|
+
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
|
150
|
+
*
|
|
151
|
+
* `fetch` addresses these problems. It runs all fetches in order, which removes race conditions
|
|
152
|
+
* and forces the developer to handle errors.
|
|
153
|
+
*
|
|
154
|
+
* ## Example:
|
|
155
|
+
*
|
|
156
|
+
* ```typescript
|
|
157
|
+
* @Injectable()
|
|
158
|
+
* class TodoEffects {
|
|
159
|
+
* loadTodos$ = createEffect(() =>
|
|
160
|
+
* this.actions$.pipe(
|
|
161
|
+
* ofType('GET_TODOS'),
|
|
162
|
+
* fetch({
|
|
163
|
+
* // provides an action
|
|
164
|
+
* run: (a: GetTodos) => {
|
|
165
|
+
* return this.backend.getAll().pipe(
|
|
166
|
+
* map((response) => ({
|
|
167
|
+
* type: 'TODOS',
|
|
168
|
+
* todos: response.todos,
|
|
169
|
+
* }))
|
|
170
|
+
* );
|
|
171
|
+
* },
|
|
172
|
+
* onError: (action: GetTodos, error: any) => {
|
|
173
|
+
* // dispatch an undo action to undo the changes in the client state
|
|
174
|
+
* return null;
|
|
175
|
+
* },
|
|
176
|
+
* })
|
|
177
|
+
* )
|
|
178
|
+
* );
|
|
179
|
+
*
|
|
180
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* This is correct, but because it set the concurrency to 1, it may not be performant.
|
|
185
|
+
*
|
|
186
|
+
* To fix that, you can provide the `id` function, like this:
|
|
187
|
+
*
|
|
188
|
+
* ```typescript
|
|
189
|
+
* @Injectable()
|
|
190
|
+
* class TodoEffects {
|
|
191
|
+
* loadTodo$ = createEffect(() =>
|
|
192
|
+
* this.actions$.pipe(
|
|
193
|
+
* ofType('GET_TODO'),
|
|
194
|
+
* fetch({
|
|
195
|
+
* id: (todo: GetTodo) => {
|
|
196
|
+
* return todo.id;
|
|
197
|
+
* },
|
|
198
|
+
* // provides an action
|
|
199
|
+
* run: (todo: GetTodo) => {
|
|
200
|
+
* return this.backend.getTodo(todo.id).map((response) => ({
|
|
201
|
+
* type: 'LOAD_TODO_SUCCESS',
|
|
202
|
+
* todo: response.todo,
|
|
203
|
+
* }));
|
|
204
|
+
* },
|
|
205
|
+
* onError: (action: GetTodo, error: any) => {
|
|
206
|
+
* // dispatch an undo action to undo the changes in the client state
|
|
207
|
+
* return null;
|
|
208
|
+
* },
|
|
209
|
+
* })
|
|
210
|
+
* )
|
|
211
|
+
* );
|
|
212
|
+
*
|
|
213
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* With this setup, the requests for Todo 1 will run concurrently with the requests for Todo 2.
|
|
218
|
+
*
|
|
219
|
+
* In addition, if there are multiple requests for Todo 1 scheduled, it will only run the last one.
|
|
220
|
+
*
|
|
221
|
+
* @param opts
|
|
222
|
+
*/
|
|
42
223
|
export declare function fetch<T extends Array<unknown>, A extends Action>(opts: FetchOpts<T, A>): (source: ActionStatesStream<T, A>) => Observable<Action>;
|
|
224
|
+
/**
|
|
225
|
+
* @whatItDoes Handles data fetching as part of router navigation.
|
|
226
|
+
*
|
|
227
|
+
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
|
228
|
+
*
|
|
229
|
+
* `navigation` addresses these problems.
|
|
230
|
+
*
|
|
231
|
+
* It checks if an activated router state contains the passed in component type, and, if it does, runs the `run`
|
|
232
|
+
* callback. It provides the activated snapshot associated with the component and the current state. And it only runs
|
|
233
|
+
* the last request.
|
|
234
|
+
*
|
|
235
|
+
* ## Example:
|
|
236
|
+
*
|
|
237
|
+
* ```typescript
|
|
238
|
+
* @Injectable()
|
|
239
|
+
* class TodoEffects {
|
|
240
|
+
* loadTodo$ = createEffect(() =>
|
|
241
|
+
* this.actions$.pipe(
|
|
242
|
+
* // listens for the routerNavigation action from @ngrx/router-store
|
|
243
|
+
* navigation(TodoComponent, {
|
|
244
|
+
* run: (activatedRouteSnapshot: ActivatedRouteSnapshot) => {
|
|
245
|
+
* return this.backend
|
|
246
|
+
* .fetchTodo(activatedRouteSnapshot.params['id'])
|
|
247
|
+
* .pipe(
|
|
248
|
+
* map((todo) => ({
|
|
249
|
+
* type: 'LOAD_TODO_SUCCESS',
|
|
250
|
+
* todo: todo,
|
|
251
|
+
* }))
|
|
252
|
+
* );
|
|
253
|
+
* },
|
|
254
|
+
* onError: (
|
|
255
|
+
* activatedRouteSnapshot: ActivatedRouteSnapshot,
|
|
256
|
+
* error: any
|
|
257
|
+
* ) => {
|
|
258
|
+
* // we can log and error here and return null
|
|
259
|
+
* // we can also navigate back
|
|
260
|
+
* return null;
|
|
261
|
+
* },
|
|
262
|
+
* })
|
|
263
|
+
* )
|
|
264
|
+
* );
|
|
265
|
+
*
|
|
266
|
+
* constructor(private actions$: Actions, private backend: Backend) {}
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @param component
|
|
271
|
+
* @param opts
|
|
272
|
+
*/
|
|
43
273
|
export declare function navigation<T extends Array<unknown>, A extends Action>(component: Type<any>, opts: HandleNavigationOpts<T>): (source: ActionStatesStream<T, A>) => Observable<Action>;
|
|
44
274
|
/**
|
|
45
275
|
* @whatItDoes Provides convenience methods for implementing common operations of persisting data.
|
|
276
|
+
*
|
|
277
|
+
* @deprecated Use the individual operators instead. Will be removed in v15.
|
|
46
278
|
*/
|
|
47
279
|
export declare class DataPersistence<T> {
|
|
48
280
|
store: Store<T>;
|
|
49
281
|
actions: Actions;
|
|
50
282
|
constructor(store: Store<T>, actions: Actions);
|
|
51
283
|
/**
|
|
284
|
+
* See {@link pessimisticUpdate} operator for more information.
|
|
52
285
|
*
|
|
53
|
-
* @
|
|
54
|
-
*
|
|
55
|
-
* Update the server implemented naively suffers from race conditions and poor error handling.
|
|
56
|
-
*
|
|
57
|
-
* `pessimisticUpdate` addresses these problems--it runs all fetches in order, which removes race conditions
|
|
58
|
-
* and forces the developer to handle errors.
|
|
59
|
-
*
|
|
60
|
-
* ## Example:
|
|
61
|
-
*
|
|
62
|
-
* ```typescript
|
|
63
|
-
* @Injectable()
|
|
64
|
-
* class TodoEffects {
|
|
65
|
-
* @Effect() updateTodo = this.s.pessimisticUpdate<UpdateTodo>('UPDATE_TODO', {
|
|
66
|
-
* // provides an action and the current state of the store
|
|
67
|
-
* run(a, state) {
|
|
68
|
-
* // update the backend first, and then dispatch an action that will
|
|
69
|
-
* // update the client side
|
|
70
|
-
* return this.backend(state.user, a.payload).map(updated => ({
|
|
71
|
-
* type: 'TODO_UPDATED',
|
|
72
|
-
* payload: updated
|
|
73
|
-
* }));
|
|
74
|
-
* },
|
|
75
|
-
*
|
|
76
|
-
* onError(a, e: any) {
|
|
77
|
-
* // we don't need to undo the changes on the client side.
|
|
78
|
-
* // we can dispatch an error, or simply log the error here and return `null`
|
|
79
|
-
* return null;
|
|
80
|
-
* }
|
|
81
|
-
* });
|
|
82
|
-
*
|
|
83
|
-
* constructor(private s: DataPersistence<TodosState>, private backend: Backend) {}
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
|
88
|
-
* of the effect to false, like this:
|
|
89
|
-
*
|
|
90
|
-
* ```
|
|
91
|
-
* class TodoEffects {
|
|
92
|
-
* @Effect({dispatch: false})
|
|
93
|
-
* updateTodo; //...
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
286
|
+
* @deprecated Use the {@link pessimisticUpdate} operator instead.
|
|
287
|
+
* The {@link DataPersistence} class will be removed in v15.
|
|
96
288
|
*/
|
|
97
289
|
pessimisticUpdate<A extends Action = Action>(actionType: string | ActionCreator, opts: PessimisticUpdateOpts<[T], A>): Observable<any>;
|
|
98
290
|
/**
|
|
291
|
+
* See {@link optimisticUpdate} operator for more information.
|
|
99
292
|
*
|
|
100
|
-
* @
|
|
101
|
-
*
|
|
102
|
-
* `optimisticUpdate` addresses these problems--it runs all fetches in order, which removes race conditions
|
|
103
|
-
* and forces the developer to handle errors.
|
|
104
|
-
*
|
|
105
|
-
* `optimisticUpdate` is different from `pessimisticUpdate`. In case of a failure, when using `optimisticUpdate`,
|
|
106
|
-
* the developer already updated the state locally, so the developer must provide an undo action.
|
|
107
|
-
*
|
|
108
|
-
* The error handling must be done in the callback, or by means of the undo action.
|
|
109
|
-
*
|
|
110
|
-
* ## Example:
|
|
111
|
-
*
|
|
112
|
-
* ```typescript
|
|
113
|
-
* @Injectable()
|
|
114
|
-
* class TodoEffects {
|
|
115
|
-
* @Effect() updateTodo = this.s.optimisticUpdate<UpdateTodo>('UPDATE_TODO', {
|
|
116
|
-
* // provides an action and the current state of the store
|
|
117
|
-
* run: (a, state) => {
|
|
118
|
-
* return this.backend(state.user, a.payload);
|
|
119
|
-
* },
|
|
120
|
-
*
|
|
121
|
-
* undoAction: (a, e: any) => {
|
|
122
|
-
* // dispatch an undo action to undo the changes in the client state
|
|
123
|
-
* return ({
|
|
124
|
-
* type: 'UNDO_UPDATE_TODO',
|
|
125
|
-
* payload: a
|
|
126
|
-
* });
|
|
127
|
-
* }
|
|
128
|
-
* });
|
|
129
|
-
*
|
|
130
|
-
* constructor(private s: DataPersistence<TodosState>, private backend: Backend) {}
|
|
131
|
-
* }
|
|
132
|
-
* ```
|
|
133
|
-
*
|
|
134
|
-
* Note that if you don't return a new action from the run callback, you must set the dispatch property
|
|
135
|
-
* of the effect to false, like this:
|
|
136
|
-
*
|
|
137
|
-
* ```
|
|
138
|
-
* class TodoEffects {
|
|
139
|
-
* @Effect({dispatch: false})
|
|
140
|
-
* updateTodo; //...
|
|
141
|
-
* }
|
|
142
|
-
* ```
|
|
293
|
+
* @deprecated Use the {@link optimisticUpdate} operator instead.
|
|
294
|
+
* The {@link DataPersistence} class will be removed in v15.
|
|
143
295
|
*/
|
|
144
296
|
optimisticUpdate<A extends Action = Action>(actionType: string | ActionCreator, opts: OptimisticUpdateOpts<[T], A>): Observable<any>;
|
|
145
297
|
/**
|
|
298
|
+
* See {@link fetch} operator for more information.
|
|
146
299
|
*
|
|
147
|
-
* @
|
|
148
|
-
*
|
|
149
|
-
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
|
150
|
-
*
|
|
151
|
-
* `fetch` addresses these problems--it runs all fetches in order, which removes race conditions
|
|
152
|
-
* and forces the developer to handle errors.
|
|
153
|
-
*
|
|
154
|
-
* ## Example:
|
|
155
|
-
*
|
|
156
|
-
* ```typescript
|
|
157
|
-
* @Injectable()
|
|
158
|
-
* class TodoEffects {
|
|
159
|
-
* @Effect() loadTodos = this.s.fetch<GetTodos>('GET_TODOS', {
|
|
160
|
-
* // provides an action and the current state of the store
|
|
161
|
-
* run: (a, state) => {
|
|
162
|
-
* return this.backend(state.user, a.payload).map(r => ({
|
|
163
|
-
* type: 'TODOS',
|
|
164
|
-
* payload: r
|
|
165
|
-
* });
|
|
166
|
-
* },
|
|
167
|
-
*
|
|
168
|
-
* onError: (a, e: any) => {
|
|
169
|
-
* // dispatch an undo action to undo the changes in the client state
|
|
170
|
-
* }
|
|
171
|
-
* });
|
|
172
|
-
*
|
|
173
|
-
* constructor(private s: DataPersistence<TodosState>, private backend: Backend) {}
|
|
174
|
-
* }
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* This is correct, but because it set the concurrency to 1, it may not be performant.
|
|
178
|
-
*
|
|
179
|
-
* To fix that, you can provide the `id` function, like this:
|
|
180
|
-
*
|
|
181
|
-
* ```typescript
|
|
182
|
-
* @Injectable()
|
|
183
|
-
* class TodoEffects {
|
|
184
|
-
* @Effect() loadTodo = this.s.fetch<GetTodo>('GET_TODO', {
|
|
185
|
-
* id: (a, state) => {
|
|
186
|
-
* return a.payload.id;
|
|
187
|
-
* }
|
|
188
|
-
*
|
|
189
|
-
* // provides an action and the current state of the store
|
|
190
|
-
* run: (a, state) => {
|
|
191
|
-
* return this.backend(state.user, a.payload).map(r => ({
|
|
192
|
-
* type: 'TODO',
|
|
193
|
-
* payload: r
|
|
194
|
-
* });
|
|
195
|
-
* },
|
|
196
|
-
*
|
|
197
|
-
* onError: (a, e: any) => {
|
|
198
|
-
* // dispatch an undo action to undo the changes in the client state
|
|
199
|
-
* return null;
|
|
200
|
-
* }
|
|
201
|
-
* });
|
|
202
|
-
*
|
|
203
|
-
* constructor(private s: DataPersistence<TodosState>, private backend: Backend) {}
|
|
204
|
-
* }
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* With this setup, the requests for Todo 1 will run concurrently with the requests for Todo 2.
|
|
208
|
-
*
|
|
209
|
-
* In addition, if DataPersistence notices that there are multiple requests for Todo 1 scheduled,
|
|
210
|
-
* it will only run the last one.
|
|
300
|
+
* @deprecated Use the {@link fetch} operator instead.
|
|
301
|
+
* The {@link DataPersistence} class will be removed in v15.
|
|
211
302
|
*/
|
|
212
303
|
fetch<A extends Action = Action>(actionType: string | ActionCreator, opts: FetchOpts<[T], A>): Observable<any>;
|
|
213
304
|
/**
|
|
214
|
-
* @
|
|
215
|
-
*
|
|
216
|
-
* Data fetching implemented naively suffers from race conditions and poor error handling.
|
|
217
|
-
*
|
|
218
|
-
* `navigation` addresses these problems.
|
|
219
|
-
*
|
|
220
|
-
* It checks if an activated router state contains the passed in component type, and, if it does, runs the `run`
|
|
221
|
-
* callback. It provides the activated snapshot associated with the component and the current state. And it only runs
|
|
222
|
-
* the last request.
|
|
223
|
-
*
|
|
224
|
-
* ## Example:
|
|
305
|
+
* See {@link navigation} operator for more information.
|
|
225
306
|
*
|
|
226
|
-
*
|
|
227
|
-
* @
|
|
228
|
-
* class TodoEffects {
|
|
229
|
-
* @Effect() loadTodo = this.s.navigation(TodoComponent, {
|
|
230
|
-
* run: (a, state) => {
|
|
231
|
-
* return this.backend.fetchTodo(a.params['id']).map(todo => ({
|
|
232
|
-
* type: 'TODO_LOADED',
|
|
233
|
-
* payload: todo
|
|
234
|
-
* }));
|
|
235
|
-
* },
|
|
236
|
-
* onError: (a, e: any) => {
|
|
237
|
-
* // we can log and error here and return null
|
|
238
|
-
* // we can also navigate back
|
|
239
|
-
* return null;
|
|
240
|
-
* }
|
|
241
|
-
* });
|
|
242
|
-
* constructor(private s: DataPersistence<TodosState>, private backend: Backend) {}
|
|
243
|
-
* }
|
|
244
|
-
* ```
|
|
307
|
+
* @deprecated Use the {@link navigation} operator instead.
|
|
308
|
+
* The {@link DataPersistence} class will be removed in v15.
|
|
245
309
|
*/
|
|
246
310
|
navigation(component: Type<any>, opts: HandleNavigationOpts<[T]>): Observable<any>;
|
|
247
311
|
static ɵfac: i0.ɵɵFactoryDeclaration<DataPersistence<any>, never>;
|