@ngxs/store 3.8.1-dev.master-744e67c → 3.8.1-dev.master-783234c
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/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +4 -4
- package/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +4 -4
- package/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ +2 -2
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ +2 -2
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +10 -10
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +4 -4
- package/schematics/src/starter-kit/files/store/store.config.ts__template__ +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
2
2
|
import { async, TestBed } from '@angular/core/testing';
|
|
3
|
-
import { AuthenticationStateModel,
|
|
3
|
+
import { AuthenticationStateModel, AuthState } from './auth.state';
|
|
4
4
|
import { SetAuthData } from './auth.actions';
|
|
5
5
|
|
|
6
6
|
describe('[TEST]: AuthStore', () => {
|
|
@@ -8,7 +8,7 @@ describe('[TEST]: AuthStore', () => {
|
|
|
8
8
|
|
|
9
9
|
beforeEach(async(() => {
|
|
10
10
|
TestBed.configureTestingModule({
|
|
11
|
-
imports: [NgxsModule.forRoot([
|
|
11
|
+
imports: [NgxsModule.forRoot([AuthState])]
|
|
12
12
|
})
|
|
13
13
|
.compileComponents()
|
|
14
14
|
.then();
|
|
@@ -25,7 +25,7 @@ describe('[TEST]: AuthStore', () => {
|
|
|
25
25
|
roles: []
|
|
26
26
|
};
|
|
27
27
|
store.dispatch(new SetAuthData(Authentication));
|
|
28
|
-
const actual = store.selectSnapshot<AuthenticationStateModel>(
|
|
28
|
+
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
|
|
29
29
|
expect(actual).toEqual(Authentication);
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -40,7 +40,7 @@ describe('[TEST]: AuthStore', () => {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
store.dispatch(new SetAuthData(authentication));
|
|
43
|
-
const actual = store.selectSnapshot<AuthenticationStateModel>(
|
|
43
|
+
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
|
|
44
44
|
expect(actual).toEqual(authentication);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
@@ -11,7 +11,7 @@ export interface AuthenticationStateModel {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
@State<AuthenticationStateModel>({
|
|
14
|
-
name: '
|
|
14
|
+
name: 'authState',
|
|
15
15
|
defaults: {
|
|
16
16
|
id: '',
|
|
17
17
|
firstName: '',
|
|
@@ -21,10 +21,10 @@ export interface AuthenticationStateModel {
|
|
|
21
21
|
roles: []
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
|
-
export class
|
|
24
|
+
export class AuthState {
|
|
25
25
|
@Selector()
|
|
26
26
|
public static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel {
|
|
27
|
-
return
|
|
27
|
+
return AuthState.getInstanceState(state);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
private static setInstanceState(state: AuthenticationStateModel): AuthenticationStateModel {
|
|
@@ -40,6 +40,6 @@ export class AuthStateModule {
|
|
|
40
40
|
{ setState }: StateContext<AuthenticationStateModel>,
|
|
41
41
|
{ payload }: SetAuthData
|
|
42
42
|
) {
|
|
43
|
-
setState(
|
|
43
|
+
setState(AuthState.setInstanceState(payload));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -5,7 +5,7 @@ import { UserState } from './states/user/user.state';
|
|
|
5
5
|
export const DashboardStates = [DictionaryState, UserState];
|
|
6
6
|
|
|
7
7
|
@State({
|
|
8
|
-
name: '
|
|
8
|
+
name: 'dashboardState',
|
|
9
9
|
children: DashboardStates
|
|
10
10
|
})
|
|
11
|
-
export class
|
|
11
|
+
export class DashboardState {}
|
package/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserStateModel } from './user.state';
|
|
2
2
|
|
|
3
3
|
export class SetUser {
|
|
4
4
|
public static readonly type = '[SetUser] action';
|
|
5
|
-
constructor(public payload:
|
|
5
|
+
constructor(public payload: UserStateModel) {}
|
|
6
6
|
}
|
package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
2
2
|
import { async, TestBed } from '@angular/core/testing';
|
|
3
|
-
import {
|
|
3
|
+
import { UserStateModel, UserState } from './user.state';
|
|
4
4
|
import { SetUser } from './user.actions';
|
|
5
5
|
|
|
6
6
|
describe('[TEST]: User state', () => {
|
|
@@ -15,8 +15,8 @@ describe('[TEST]: User state', () => {
|
|
|
15
15
|
store = TestBed.get(Store);
|
|
16
16
|
}));
|
|
17
17
|
|
|
18
|
-
it('Should be state is
|
|
19
|
-
const
|
|
18
|
+
it('Should be state is UserStateModel', () => {
|
|
19
|
+
const user: UserStateModel = {
|
|
20
20
|
userId: '',
|
|
21
21
|
departmentCode: '',
|
|
22
22
|
departmentName: '',
|
|
@@ -27,14 +27,14 @@ describe('[TEST]: User state', () => {
|
|
|
27
27
|
positionId: '',
|
|
28
28
|
positionName: ''
|
|
29
29
|
};
|
|
30
|
-
store.dispatch(new SetUser(
|
|
30
|
+
store.dispatch(new SetUser(user));
|
|
31
31
|
const actual = store.selectSnapshot(({ user }) => user);
|
|
32
32
|
|
|
33
|
-
expect(actual).toEqual(
|
|
33
|
+
expect(actual).toEqual(user);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it('Should be state is filled
|
|
37
|
-
const
|
|
36
|
+
it('Should be state is filled UserStateModel', () => {
|
|
37
|
+
const user: UserStateModel = {
|
|
38
38
|
userId: '12',
|
|
39
39
|
departmentCode: '2392',
|
|
40
40
|
departmentName: 'Main office',
|
|
@@ -46,9 +46,9 @@ describe('[TEST]: User state', () => {
|
|
|
46
46
|
positionName: 'admin'
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
store.dispatch(new SetUser(
|
|
50
|
-
const actual = store.selectSnapshot<
|
|
49
|
+
store.dispatch(new SetUser(user));
|
|
50
|
+
const actual = store.selectSnapshot<UserStateModel>(({ user }) => user);
|
|
51
51
|
|
|
52
|
-
expect(actual).toEqual(
|
|
52
|
+
expect(actual).toEqual(user);
|
|
53
53
|
});
|
|
54
54
|
});
|
package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Action, Selector, State, StateContext } from '@ngxs/store';
|
|
2
2
|
import { SetUser } from './user.actions';
|
|
3
3
|
|
|
4
|
-
export interface
|
|
4
|
+
export interface UserStateModel {
|
|
5
5
|
userId: string;
|
|
6
6
|
email: string;
|
|
7
7
|
firstName: string;
|
|
@@ -13,7 +13,7 @@ export interface PersonStateModel {
|
|
|
13
13
|
departmentName: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
@State<
|
|
16
|
+
@State<UserStateModel>({
|
|
17
17
|
name: 'user',
|
|
18
18
|
defaults: {
|
|
19
19
|
userId: '',
|
|
@@ -29,12 +29,12 @@ export interface PersonStateModel {
|
|
|
29
29
|
})
|
|
30
30
|
export class UserState {
|
|
31
31
|
@Selector()
|
|
32
|
-
public static getUser(state:
|
|
32
|
+
public static getUser(state: UserStateModel): UserStateModel {
|
|
33
33
|
return state;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
@Action(SetUser)
|
|
37
|
-
public setUser(ctx: StateContext<
|
|
37
|
+
public setUser(ctx: StateContext<UserStateModel>, { payload }: SetUser) {
|
|
38
38
|
ctx.setState(payload);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DashboardStates,
|
|
1
|
+
import { AuthState } from './auth/auth.state';
|
|
2
|
+
import { DashboardStates, DashboardState } from './dashboard';
|
|
3
3
|
import { NgxsConfig } from '@ngxs/store/src/symbols';
|
|
4
4
|
import { NgxsDevtoolsOptions } from '@ngxs/devtools-plugin/src/symbols';
|
|
5
5
|
import { NgxsLoggerPluginOptions } from '@ngxs/logger-plugin/src/symbols';
|
|
6
6
|
|
|
7
|
-
export const STATES_MODULES = [
|
|
7
|
+
export const STATES_MODULES = [AuthState, DashboardState, ...DashboardStates];
|
|
8
8
|
|
|
9
9
|
export const OPTIONS_CONFIG: Partial<NgxsConfig> = {
|
|
10
10
|
/**
|