@tech4good/angular-schematics 13.8.0 → 13.8.1
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/package.json +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +1 -0
- package/src/init/files/package.json.template +1 -1
- package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +9 -30
- package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +24 -24
- package/src/init/files/src/app/core/store/app.selectors.ts.template +1 -1
- package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +7 -4
- package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +2 -2
- package/src/init/files/src/app/core/store/user/user.actions.ts.template +9 -30
- package/src/init/files/src/app/core/store/user/user.effects.ts.template +24 -24
- package/src/init/files/src/app/core/store/user/user.model.ts.template +1 -0
- package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +9 -31
- package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +24 -24
- package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +6 -6
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import { CachedLoadConnectionsService } from '../cached-load-connections.service
|
|
|
8
8
|
|
|
9
9
|
import { <%= classify(name) %> } from './<%= dasherize(name) %>.model';
|
|
10
10
|
import { <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions,
|
|
11
|
+
Added<%= classify(name) %>, Removed<%= classify(name) %>,
|
|
11
12
|
Stream<%= classify(name) %>, Stream<%= classify(name) %>Success, Stream<%= classify(name) %>Fail,
|
|
12
13
|
Load<%= classify(name) %>, Load<%= classify(name) %>Success, Load<%= classify(name) %>Fail,
|
|
13
14
|
Add<%= classify(name) %>, Add<%= classify(name) %>Success, Add<%= classify(name) %>Fail,
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@ngrx/router-store": "^13.1.0",
|
|
29
29
|
"@ngrx/store": "^13.1.0",
|
|
30
30
|
"@ngrx/store-devtools": "^13.1.0",
|
|
31
|
-
"@tech4good/angular-schematics": "^13.8.
|
|
31
|
+
"@tech4good/angular-schematics": "^13.8.1",
|
|
32
32
|
"crypto-es": "^1.2.7",
|
|
33
33
|
"rxjs": "~7.5.0",
|
|
34
34
|
"tslib": "^2.3.0",
|
|
@@ -15,9 +15,6 @@ export enum AppStateActionTypes {
|
|
|
15
15
|
UPDATE = '[AppState] update appState',
|
|
16
16
|
UPDATE_SUCCESS = '[AppState] update appState success',
|
|
17
17
|
UPDATE_FAIL = '[AppState] update appState fail',
|
|
18
|
-
UPSERT = '[AppState] upsert appState',
|
|
19
|
-
UPSERT_SUCCESS = '[AppState] upsert appState success',
|
|
20
|
-
UPSERT_FAIL = '[AppState] upsert appState fail',
|
|
21
18
|
REMOVE = '[AppState] remove appState',
|
|
22
19
|
REMOVE_SUCCESS = '[AppState] remove appState success',
|
|
23
20
|
REMOVE_FAIL = '[AppState] remove appState fail',
|
|
@@ -120,6 +117,9 @@ export class AddAppState implements Action {
|
|
|
120
117
|
constructor(
|
|
121
118
|
public appState: AppState,
|
|
122
119
|
public correlationId?: string,
|
|
120
|
+
public options?: {
|
|
121
|
+
optimistic?: boolean,
|
|
122
|
+
},
|
|
123
123
|
) {}
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -128,6 +128,9 @@ export class AddAppStateSuccess implements Action {
|
|
|
128
128
|
constructor(
|
|
129
129
|
public appState: AppState,
|
|
130
130
|
public correlationId?: string,
|
|
131
|
+
public options?: {
|
|
132
|
+
optimistic?: boolean,
|
|
133
|
+
},
|
|
131
134
|
) {}
|
|
132
135
|
}
|
|
133
136
|
|
|
@@ -136,6 +139,9 @@ export class AddAppStateFail implements Action {
|
|
|
136
139
|
constructor(
|
|
137
140
|
public error: any,
|
|
138
141
|
public correlationId?: string,
|
|
142
|
+
public options?: {
|
|
143
|
+
optimistic?: boolean,
|
|
144
|
+
},
|
|
139
145
|
) {}
|
|
140
146
|
}
|
|
141
147
|
|
|
@@ -165,30 +171,6 @@ export class UpdateAppStateFail implements Action {
|
|
|
165
171
|
) {}
|
|
166
172
|
}
|
|
167
173
|
|
|
168
|
-
export class UpsertAppState implements Action {
|
|
169
|
-
readonly type = AppStateActionTypes.UPSERT;
|
|
170
|
-
constructor(
|
|
171
|
-
public appState: AppState,
|
|
172
|
-
public correlationId?: string,
|
|
173
|
-
) {}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export class UpsertAppStateSuccess implements Action {
|
|
177
|
-
readonly type = AppStateActionTypes.UPSERT_SUCCESS;
|
|
178
|
-
constructor(
|
|
179
|
-
public appState: AppState,
|
|
180
|
-
public correlationId?: string,
|
|
181
|
-
) {}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export class UpsertAppStateFail implements Action {
|
|
185
|
-
readonly type = AppStateActionTypes.UPSERT_FAIL;
|
|
186
|
-
constructor(
|
|
187
|
-
public error: any,
|
|
188
|
-
public correlationId?: string,
|
|
189
|
-
) {}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
174
|
export class RemoveAppState implements Action {
|
|
193
175
|
readonly type = AppStateActionTypes.REMOVE;
|
|
194
176
|
constructor(
|
|
@@ -258,9 +240,6 @@ export type AppStateActions =
|
|
|
258
240
|
UpdateAppState |
|
|
259
241
|
UpdateAppStateSuccess |
|
|
260
242
|
UpdateAppStateFail |
|
|
261
|
-
UpsertAppState |
|
|
262
|
-
UpsertAppStateSuccess |
|
|
263
|
-
UpsertAppStateFail |
|
|
264
243
|
RemoveAppState |
|
|
265
244
|
RemoveAppStateSuccess |
|
|
266
245
|
RemoveAppStateFail |
|
|
@@ -8,11 +8,11 @@ import { CachedLoadConnectionsService } from '../cached-load-connections.service
|
|
|
8
8
|
|
|
9
9
|
import { AppState } from './app-state.model';
|
|
10
10
|
import { AppStateActionTypes, AppStateActions,
|
|
11
|
+
AddedAppState, RemovedAppState,
|
|
11
12
|
StreamAppState, StreamAppStateSuccess, StreamAppStateFail,
|
|
12
13
|
LoadAppState, LoadAppStateSuccess, LoadAppStateFail,
|
|
13
14
|
AddAppState, AddAppStateSuccess, AddAppStateFail,
|
|
14
15
|
UpdateAppState, UpdateAppStateSuccess, UpdateAppStateFail,
|
|
15
|
-
UpsertAppState, UpsertAppStateSuccess, UpsertAppStateFail,
|
|
16
16
|
RemoveAppState, RemoveAppStateSuccess, RemoveAppStateFail } from './app-state.actions';
|
|
17
17
|
|
|
18
18
|
@Injectable()
|
|
@@ -52,13 +52,29 @@ export class AppStateEffects {
|
|
|
52
52
|
() => this.actions$.pipe(
|
|
53
53
|
ofType<AddAppState>(AppStateActionTypes.ADD),
|
|
54
54
|
mergeMap((action: AddAppState) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
of(new
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
if (action.options && action.options.optimistic) {
|
|
56
|
+
return merge(
|
|
57
|
+
of(new AddedAppState(action.appState, action.correlationId)),
|
|
58
|
+
this.db.addEntity('appStates', action.appState).pipe(
|
|
59
|
+
mergeMap(() => merge(
|
|
60
|
+
of(new AddAppStateSuccess(action.appState, action.correlationId)),
|
|
61
|
+
this.actionsOnAdd(action),
|
|
62
|
+
)),
|
|
63
|
+
catchError((error) => merge(
|
|
64
|
+
of(new AddAppStateFail(error, action.correlationId)),
|
|
65
|
+
of(new RemovedAppState(action.appState, action.correlationId)),
|
|
66
|
+
)),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
return this.db.addEntity('appStates', action.appState).pipe(
|
|
71
|
+
mergeMap(() => merge(
|
|
72
|
+
of(new AddAppStateSuccess(action.appState, action.correlationId)),
|
|
73
|
+
this.actionsOnAdd(action),
|
|
74
|
+
)),
|
|
75
|
+
catchError((error) => of(new AddAppStateFail(error, action.correlationId))),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
62
78
|
}),
|
|
63
79
|
),
|
|
64
80
|
);
|
|
@@ -79,22 +95,6 @@ export class AppStateEffects {
|
|
|
79
95
|
),
|
|
80
96
|
);
|
|
81
97
|
|
|
82
|
-
/** Process the upsert action to update database and initiate callbacks. */
|
|
83
|
-
upsert$: Observable<Action> = createEffect(
|
|
84
|
-
() => this.actions$.pipe(
|
|
85
|
-
ofType<UpsertAppState>(AppStateActionTypes.UPSERT),
|
|
86
|
-
mergeMap((action: UpsertAppState) => {
|
|
87
|
-
return this.db.upsertEntity('appStates', action.appState).pipe(
|
|
88
|
-
mergeMap((results) => merge(
|
|
89
|
-
of(new UpsertAppStateSuccess(action.appState, action.correlationId)),
|
|
90
|
-
results.type === 'add' ? this.actionsOnAdd(new AddAppState(action.appState, action.correlationId)) : this.actionsOnUpdate(new UpdateAppState(action.appState.__id, action.appState, action.correlationId)),
|
|
91
|
-
)),
|
|
92
|
-
catchError((error) => of(new UpsertAppStateFail(error, action.correlationId))),
|
|
93
|
-
);
|
|
94
|
-
}),
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
98
|
/** Process the remove action to update database and initiate callbacks. */
|
|
99
99
|
remove$: Observable<Action> = createEffect(
|
|
100
100
|
() => this.actions$.pipe(
|
|
@@ -36,7 +36,7 @@ export class EntitySelectorService {
|
|
|
36
36
|
public selectUserContext = this.userContext.selectUserContext;
|
|
37
37
|
public selectUserContexts = this.userContext.selectUserContexts;
|
|
38
38
|
public selectUser = this.user.selectUser;
|
|
39
|
-
public
|
|
39
|
+
public selectUsers = this.user.selectUsers;
|
|
40
40
|
public getUser = this.user.getUser;
|
|
41
41
|
public getUsers = this.user.getUsers;
|
|
42
42
|
}
|
|
@@ -43,10 +43,12 @@ export class AuthEffects {
|
|
|
43
43
|
switchMap(() => this.db.afUser()),
|
|
44
44
|
switchMap((afUser: any) => {
|
|
45
45
|
if (afUser) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
// Note that using this.db.queryObjValueChanges doesn't work since it first returns
|
|
47
|
+
// undefined from the cache which messes up the logic (results in it doing a Logout)
|
|
48
|
+
return this.db.queryListValueChanges<User>('users', [['__id', '==', afUser.uid]]).pipe(
|
|
49
|
+
map((users: User[]) => {
|
|
50
|
+
if (users && users.length > 0) {
|
|
51
|
+
return new LoadedAuth({ user: users[0] });
|
|
50
52
|
} else {
|
|
51
53
|
// This should not happen. If there is no entry in DB despite
|
|
52
54
|
// having a FireAuth user, make them login again to create an entry
|
|
@@ -96,6 +98,7 @@ export class AuthEffects {
|
|
|
96
98
|
action: new AddUser(Object.assign({}, userParams, {
|
|
97
99
|
__id: afUser.uid,
|
|
98
100
|
tokens: this.getToken(results.credential),
|
|
101
|
+
isAdmin: false,
|
|
99
102
|
consented: false,
|
|
100
103
|
accessState: AccessState.CONSENT,
|
|
101
104
|
})),
|
|
@@ -217,7 +217,7 @@ export class CachedSelectorsService {
|
|
|
217
217
|
const val = this.getList<T>(entityStore.entities, queryParams);
|
|
218
218
|
return val.map((e) => {
|
|
219
219
|
if (this.hardcodedFields[entityStoreKey]) {
|
|
220
|
-
return Object.assign({}, e, this.hardcodedFields[entityStoreKey][e
|
|
220
|
+
return Object.assign({}, e, this.hardcodedFields[entityStoreKey][e['__id']]);
|
|
221
221
|
} else {
|
|
222
222
|
return e;
|
|
223
223
|
}
|
|
@@ -357,7 +357,7 @@ export class CachedSelectorsService {
|
|
|
357
357
|
(entityStore) => {
|
|
358
358
|
const e = this.getObj<T>(entityStore.entities, id);
|
|
359
359
|
if (e && this.hardcodedFields[entityStoreKey]) {
|
|
360
|
-
return Object.assign({}, e, this.hardcodedFields[entityStoreKey][e
|
|
360
|
+
return Object.assign({}, e, this.hardcodedFields[entityStoreKey][e['__id']]);
|
|
361
361
|
} else {
|
|
362
362
|
return e;
|
|
363
363
|
}
|
|
@@ -15,9 +15,6 @@ export enum UserActionTypes {
|
|
|
15
15
|
UPDATE = '[User] update user',
|
|
16
16
|
UPDATE_SUCCESS = '[User] update user success',
|
|
17
17
|
UPDATE_FAIL = '[User] update user fail',
|
|
18
|
-
UPSERT = '[User] upsert user',
|
|
19
|
-
UPSERT_SUCCESS = '[User] upsert user success',
|
|
20
|
-
UPSERT_FAIL = '[User] upsert user fail',
|
|
21
18
|
REMOVE = '[User] remove user',
|
|
22
19
|
REMOVE_SUCCESS = '[User] remove user success',
|
|
23
20
|
REMOVE_FAIL = '[User] remove user fail',
|
|
@@ -119,6 +116,9 @@ export class AddUser implements Action {
|
|
|
119
116
|
constructor(
|
|
120
117
|
public user: User,
|
|
121
118
|
public correlationId?: string,
|
|
119
|
+
public options?: {
|
|
120
|
+
optimistic?: boolean,
|
|
121
|
+
},
|
|
122
122
|
) {}
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -127,6 +127,9 @@ export class AddUserSuccess implements Action {
|
|
|
127
127
|
constructor(
|
|
128
128
|
public user: User,
|
|
129
129
|
public correlationId?: string,
|
|
130
|
+
public options?: {
|
|
131
|
+
optimistic?: boolean,
|
|
132
|
+
},
|
|
130
133
|
) {}
|
|
131
134
|
}
|
|
132
135
|
|
|
@@ -135,6 +138,9 @@ export class AddUserFail implements Action {
|
|
|
135
138
|
constructor(
|
|
136
139
|
public error: any,
|
|
137
140
|
public correlationId?: string,
|
|
141
|
+
public options?: {
|
|
142
|
+
optimistic?: boolean,
|
|
143
|
+
},
|
|
138
144
|
) {}
|
|
139
145
|
}
|
|
140
146
|
|
|
@@ -164,30 +170,6 @@ export class UpdateUserFail implements Action {
|
|
|
164
170
|
) {}
|
|
165
171
|
}
|
|
166
172
|
|
|
167
|
-
export class UpsertUser implements Action {
|
|
168
|
-
readonly type = UserActionTypes.UPSERT;
|
|
169
|
-
constructor(
|
|
170
|
-
public user: User,
|
|
171
|
-
public correlationId?: string,
|
|
172
|
-
) {}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export class UpsertUserSuccess implements Action {
|
|
176
|
-
readonly type = UserActionTypes.UPSERT_SUCCESS;
|
|
177
|
-
constructor(
|
|
178
|
-
public user: User,
|
|
179
|
-
public correlationId?: string,
|
|
180
|
-
) {}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export class UpsertUserFail implements Action {
|
|
184
|
-
readonly type = UserActionTypes.UPSERT_FAIL;
|
|
185
|
-
constructor(
|
|
186
|
-
public error: any,
|
|
187
|
-
public correlationId?: string,
|
|
188
|
-
) {}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
173
|
export class RemoveUser implements Action {
|
|
192
174
|
readonly type = UserActionTypes.REMOVE;
|
|
193
175
|
constructor(
|
|
@@ -257,9 +239,6 @@ export type UserActions =
|
|
|
257
239
|
UpdateUser |
|
|
258
240
|
UpdateUserSuccess |
|
|
259
241
|
UpdateUserFail |
|
|
260
|
-
UpsertUser |
|
|
261
|
-
UpsertUserSuccess |
|
|
262
|
-
UpsertUserFail |
|
|
263
242
|
RemoveUser |
|
|
264
243
|
RemoveUserSuccess |
|
|
265
244
|
RemoveUserFail |
|
|
@@ -8,11 +8,11 @@ import { CachedLoadConnectionsService } from '../cached-load-connections.service
|
|
|
8
8
|
|
|
9
9
|
import { User } from './user.model';
|
|
10
10
|
import { UserActionTypes, UserActions,
|
|
11
|
+
AddedUser, RemovedUser,
|
|
11
12
|
StreamUser, StreamUserSuccess, StreamUserFail,
|
|
12
13
|
LoadUser, LoadUserSuccess, LoadUserFail,
|
|
13
14
|
AddUser, AddUserSuccess, AddUserFail,
|
|
14
15
|
UpdateUser, UpdateUserSuccess, UpdateUserFail,
|
|
15
|
-
UpsertUser, UpsertUserSuccess, UpsertUserFail,
|
|
16
16
|
RemoveUser, RemoveUserSuccess, RemoveUserFail } from './user.actions';
|
|
17
17
|
|
|
18
18
|
@Injectable()
|
|
@@ -52,13 +52,29 @@ export class UserEffects {
|
|
|
52
52
|
() => this.actions$.pipe(
|
|
53
53
|
ofType<AddUser>(UserActionTypes.ADD),
|
|
54
54
|
mergeMap((action: AddUser) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
of(new
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
if (action.options && action.options.optimistic) {
|
|
56
|
+
return merge(
|
|
57
|
+
of(new AddedUser(action.user, action.correlationId)),
|
|
58
|
+
this.db.addEntity('users', action.user).pipe(
|
|
59
|
+
mergeMap(() => merge(
|
|
60
|
+
of(new AddUserSuccess(action.user, action.correlationId)),
|
|
61
|
+
this.actionsOnAdd(action),
|
|
62
|
+
)),
|
|
63
|
+
catchError((error) => merge(
|
|
64
|
+
of(new AddUserFail(error, action.correlationId)),
|
|
65
|
+
of(new RemovedUser(action.user, action.correlationId)),
|
|
66
|
+
)),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
return this.db.addEntity('users', action.user).pipe(
|
|
71
|
+
mergeMap(() => merge(
|
|
72
|
+
of(new AddUserSuccess(action.user, action.correlationId)),
|
|
73
|
+
this.actionsOnAdd(action),
|
|
74
|
+
)),
|
|
75
|
+
catchError((error) => of(new AddUserFail(error, action.correlationId))),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
62
78
|
}),
|
|
63
79
|
),
|
|
64
80
|
);
|
|
@@ -79,22 +95,6 @@ export class UserEffects {
|
|
|
79
95
|
),
|
|
80
96
|
);
|
|
81
97
|
|
|
82
|
-
/** Process the upsert action to update database and initiate callbacks. */
|
|
83
|
-
upsert$: Observable<Action> = createEffect(
|
|
84
|
-
() => this.actions$.pipe(
|
|
85
|
-
ofType<UpsertUser>(UserActionTypes.UPSERT),
|
|
86
|
-
mergeMap((action: UpsertUser) => {
|
|
87
|
-
return this.db.upsertEntity('users', action.user).pipe(
|
|
88
|
-
mergeMap((results) => merge(
|
|
89
|
-
of(new UpsertUserSuccess(action.user, action.correlationId)),
|
|
90
|
-
results.type === 'add' ? this.actionsOnAdd(new AddUser(action.user, action.correlationId)) : this.actionsOnUpdate(new UpdateUser(action.user.__id, action.user, action.correlationId)),
|
|
91
|
-
)),
|
|
92
|
-
catchError((error) => of(new UpsertUserFail(error, action.correlationId))),
|
|
93
|
-
);
|
|
94
|
-
}),
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
98
|
/** Process the remove action to update database and initiate callbacks. */
|
|
99
99
|
remove$: Observable<Action> = createEffect(
|
|
100
100
|
() => this.actions$.pipe(
|
|
@@ -15,9 +15,6 @@ export enum UserContextActionTypes {
|
|
|
15
15
|
UPDATE = '[UserContext] update userContext',
|
|
16
16
|
UPDATE_SUCCESS = '[UserContext] update userContext success',
|
|
17
17
|
UPDATE_FAIL = '[UserContext] update userContext fail',
|
|
18
|
-
UPSERT = '[UserContext] upsert userContext',
|
|
19
|
-
UPSERT_SUCCESS = '[UserContext] upsert userContext success',
|
|
20
|
-
UPSERT_FAIL = '[UserContext] upsert userContext fail',
|
|
21
18
|
REMOVE = '[UserContext] remove userContext',
|
|
22
19
|
REMOVE_SUCCESS = '[UserContext] remove userContext success',
|
|
23
20
|
REMOVE_FAIL = '[UserContext] remove userContext fail',
|
|
@@ -71,7 +68,6 @@ export class StreamUserContextFail implements Action {
|
|
|
71
68
|
) {}
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
|
|
75
71
|
export class LoadUserContext implements Action {
|
|
76
72
|
readonly type = UserContextActionTypes.LOAD;
|
|
77
73
|
constructor(
|
|
@@ -120,6 +116,9 @@ export class AddUserContext implements Action {
|
|
|
120
116
|
constructor(
|
|
121
117
|
public userContext: UserContext,
|
|
122
118
|
public correlationId?: string,
|
|
119
|
+
public options?: {
|
|
120
|
+
optimistic?: boolean,
|
|
121
|
+
},
|
|
123
122
|
) {}
|
|
124
123
|
}
|
|
125
124
|
|
|
@@ -128,6 +127,9 @@ export class AddUserContextSuccess implements Action {
|
|
|
128
127
|
constructor(
|
|
129
128
|
public userContext: UserContext,
|
|
130
129
|
public correlationId?: string,
|
|
130
|
+
public options?: {
|
|
131
|
+
optimistic?: boolean,
|
|
132
|
+
},
|
|
131
133
|
) {}
|
|
132
134
|
}
|
|
133
135
|
|
|
@@ -136,6 +138,9 @@ export class AddUserContextFail implements Action {
|
|
|
136
138
|
constructor(
|
|
137
139
|
public error: any,
|
|
138
140
|
public correlationId?: string,
|
|
141
|
+
public options?: {
|
|
142
|
+
optimistic?: boolean,
|
|
143
|
+
},
|
|
139
144
|
) {}
|
|
140
145
|
}
|
|
141
146
|
|
|
@@ -165,30 +170,6 @@ export class UpdateUserContextFail implements Action {
|
|
|
165
170
|
) {}
|
|
166
171
|
}
|
|
167
172
|
|
|
168
|
-
export class UpsertUserContext implements Action {
|
|
169
|
-
readonly type = UserContextActionTypes.UPSERT;
|
|
170
|
-
constructor(
|
|
171
|
-
public userContext: UserContext,
|
|
172
|
-
public correlationId?: string,
|
|
173
|
-
) {}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export class UpsertUserContextSuccess implements Action {
|
|
177
|
-
readonly type = UserContextActionTypes.UPSERT_SUCCESS;
|
|
178
|
-
constructor(
|
|
179
|
-
public userContext: UserContext,
|
|
180
|
-
public correlationId?: string,
|
|
181
|
-
) {}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export class UpsertUserContextFail implements Action {
|
|
185
|
-
readonly type = UserContextActionTypes.UPSERT_FAIL;
|
|
186
|
-
constructor(
|
|
187
|
-
public error: any,
|
|
188
|
-
public correlationId?: string,
|
|
189
|
-
) {}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
173
|
export class RemoveUserContext implements Action {
|
|
193
174
|
readonly type = UserContextActionTypes.REMOVE;
|
|
194
175
|
constructor(
|
|
@@ -258,9 +239,6 @@ export type UserContextActions =
|
|
|
258
239
|
UpdateUserContext |
|
|
259
240
|
UpdateUserContextSuccess |
|
|
260
241
|
UpdateUserContextFail |
|
|
261
|
-
UpsertUserContext |
|
|
262
|
-
UpsertUserContextSuccess |
|
|
263
|
-
UpsertUserContextFail |
|
|
264
242
|
RemoveUserContext |
|
|
265
243
|
RemoveUserContextSuccess |
|
|
266
244
|
RemoveUserContextFail |
|
|
@@ -8,11 +8,11 @@ import { CachedLoadConnectionsService } from '../cached-load-connections.service
|
|
|
8
8
|
|
|
9
9
|
import { UserContext } from './user-context.model';
|
|
10
10
|
import { UserContextActionTypes, UserContextActions,
|
|
11
|
+
AddedUserContext, RemovedUserContext,
|
|
11
12
|
StreamUserContext, StreamUserContextSuccess, StreamUserContextFail,
|
|
12
13
|
LoadUserContext, LoadUserContextSuccess, LoadUserContextFail,
|
|
13
14
|
AddUserContext, AddUserContextSuccess, AddUserContextFail,
|
|
14
15
|
UpdateUserContext, UpdateUserContextSuccess, UpdateUserContextFail,
|
|
15
|
-
UpsertUserContext, UpsertUserContextSuccess, UpsertUserContextFail,
|
|
16
16
|
RemoveUserContext, RemoveUserContextSuccess, RemoveUserContextFail } from './user-context.actions';
|
|
17
17
|
|
|
18
18
|
@Injectable()
|
|
@@ -52,13 +52,29 @@ export class UserContextEffects {
|
|
|
52
52
|
() => this.actions$.pipe(
|
|
53
53
|
ofType<AddUserContext>(UserContextActionTypes.ADD),
|
|
54
54
|
mergeMap((action: AddUserContext) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
of(new
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
if (action.options && action.options.optimistic) {
|
|
56
|
+
return merge(
|
|
57
|
+
of(new AddedUserContext(action.userContext, action.correlationId)),
|
|
58
|
+
this.db.addEntity('userContexts', action.userContext).pipe(
|
|
59
|
+
mergeMap(() => merge(
|
|
60
|
+
of(new AddUserContextSuccess(action.userContext, action.correlationId)),
|
|
61
|
+
this.actionsOnAdd(action),
|
|
62
|
+
)),
|
|
63
|
+
catchError((error) => merge(
|
|
64
|
+
of(new AddUserContextFail(error, action.correlationId)),
|
|
65
|
+
of(new RemovedUserContext(action.userContext, action.correlationId)),
|
|
66
|
+
)),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
return this.db.addEntity('userContexts', action.userContext).pipe(
|
|
71
|
+
mergeMap(() => merge(
|
|
72
|
+
of(new AddUserContextSuccess(action.userContext, action.correlationId)),
|
|
73
|
+
this.actionsOnAdd(action),
|
|
74
|
+
)),
|
|
75
|
+
catchError((error) => of(new AddUserContextFail(error, action.correlationId))),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
62
78
|
}),
|
|
63
79
|
),
|
|
64
80
|
);
|
|
@@ -79,22 +95,6 @@ export class UserContextEffects {
|
|
|
79
95
|
),
|
|
80
96
|
);
|
|
81
97
|
|
|
82
|
-
/** Process the upsert action to update database and initiate callbacks. */
|
|
83
|
-
upsert$: Observable<Action> = createEffect(
|
|
84
|
-
() => this.actions$.pipe(
|
|
85
|
-
ofType<UpsertUserContext>(UserContextActionTypes.UPSERT),
|
|
86
|
-
mergeMap((action: UpsertUserContext) => {
|
|
87
|
-
return this.db.upsertEntity('userContexts', action.userContext).pipe(
|
|
88
|
-
mergeMap((results) => merge(
|
|
89
|
-
of(new UpsertUserContextSuccess(action.userContext, action.correlationId)),
|
|
90
|
-
results.type === 'add' ? this.actionsOnAdd(new AddUserContext(action.userContext, action.correlationId)) : this.actionsOnUpdate(new UpdateUserContext(action.userContext.__id, action.userContext, action.correlationId)),
|
|
91
|
-
)),
|
|
92
|
-
catchError((error) => of(new UpsertUserContextFail(error, action.correlationId))),
|
|
93
|
-
);
|
|
94
|
-
}),
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
98
|
/** Process the remove action to update database and initiate callbacks. */
|
|
99
99
|
remove$: Observable<Action> = createEffect(
|
|
100
100
|
() => this.actions$.pipe(
|
|
@@ -162,8 +162,8 @@ export class WaitingComponent implements OnInit, OnDestroy {
|
|
|
162
162
|
desiredValue: this.desiredValue,
|
|
163
163
|
}, this.containerId),
|
|
164
164
|
responseActionTypes: {
|
|
165
|
-
success: UserContextActionTypes.
|
|
166
|
-
failure: UserContextActionTypes.
|
|
165
|
+
success: UserContextActionTypes.ADD_SUCCESS,
|
|
166
|
+
failure: UserContextActionTypes.ADD_FAIL,
|
|
167
167
|
},
|
|
168
168
|
});
|
|
169
169
|
}
|
|
@@ -219,8 +219,8 @@ export class WaitingComponent implements OnInit, OnDestroy {
|
|
|
219
219
|
_totalWaiting: waitlistData.appState._totalWaiting + 1,
|
|
220
220
|
}, this.containerId),
|
|
221
221
|
responseActionTypes: {
|
|
222
|
-
success:
|
|
223
|
-
failure:
|
|
222
|
+
success: AppStateActionTypes.UPDATE_SUCCESS,
|
|
223
|
+
failure: AppStateActionTypes.UPDATE_FAIL,
|
|
224
224
|
},
|
|
225
225
|
});
|
|
226
226
|
} else {
|
|
@@ -230,8 +230,8 @@ export class WaitingComponent implements OnInit, OnDestroy {
|
|
|
230
230
|
_totalWaiting: 1,
|
|
231
231
|
}, this.containerId),
|
|
232
232
|
responseActionTypes: {
|
|
233
|
-
success:
|
|
234
|
-
failure:
|
|
233
|
+
success: AppStateActionTypes.ADD_SUCCESS,
|
|
234
|
+
failure: AppStateActionTypes.ADD_FAIL,
|
|
235
235
|
},
|
|
236
236
|
});
|
|
237
237
|
}
|