From 783234cfcb4f84a2bc6806d96c08819f7aeffe4c Mon Sep 17 00:00:00 2001 From: profanis Date: Fri, 24 Nov 2023 00:30:29 +0200 Subject: [PATCH] feat(store): change the StateModule name into State (#2082) --- .../store/auth/auth.state.spec.ts__template__ | 8 ++++---- .../store/auth/auth.state.ts__template__ | 8 ++++---- .../store/dashboard/index.ts__template__ | 4 ++-- .../states/user/user.actions.ts__template__ | 4 ++-- .../user/user.state.spec.ts__template__ | 20 +++++++++---------- .../states/user/user.state.ts__template__ | 8 ++++---- .../files/store/store.config.ts__template__ | 6 +++--- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ index 3aab1b6e2..f22f777f3 100644 --- a/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ @@ -1,6 +1,6 @@ import { NgxsModule, Store } from '@ngxs/store'; import { async, TestBed } from '@angular/core/testing'; -import { AuthenticationStateModel, AuthStateModule } from './auth.state'; +import { AuthenticationStateModel, AuthState } from './auth.state'; import { SetAuthData } from './auth.actions'; describe('[TEST]: AuthStore', () => { @@ -8,7 +8,7 @@ describe('[TEST]: AuthStore', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [NgxsModule.forRoot([AuthStateModule])] + imports: [NgxsModule.forRoot([AuthState])] }) .compileComponents() .then(); @@ -25,7 +25,7 @@ describe('[TEST]: AuthStore', () => { roles: [] }; store.dispatch(new SetAuthData(Authentication)); - const actual = store.selectSnapshot(AuthStateModule.getAuthData); + const actual = store.selectSnapshot(AuthState.getAuthData); expect(actual).toEqual(Authentication); }); @@ -40,7 +40,7 @@ describe('[TEST]: AuthStore', () => { }; store.dispatch(new SetAuthData(authentication)); - const actual = store.selectSnapshot(AuthStateModule.getAuthData); + const actual = store.selectSnapshot(AuthState.getAuthData); expect(actual).toEqual(authentication); }); }); diff --git a/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ index a4864bcea..2bb2c028d 100644 --- a/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ @@ -11,7 +11,7 @@ export interface AuthenticationStateModel { } @State({ - name: 'authStateModule', + name: 'authState', defaults: { id: '', firstName: '', @@ -21,10 +21,10 @@ export interface AuthenticationStateModel { roles: [] } }) -export class AuthStateModule { +export class AuthState { @Selector() public static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel { - return AuthStateModule.getInstanceState(state); + return AuthState.getInstanceState(state); } private static setInstanceState(state: AuthenticationStateModel): AuthenticationStateModel { @@ -40,6 +40,6 @@ export class AuthStateModule { { setState }: StateContext, { payload }: SetAuthData ) { - setState(AuthStateModule.setInstanceState(payload)); + setState(AuthState.setInstanceState(payload)); } } diff --git a/packages/store/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ index 1fd8d3a3a..690e84074 100644 --- a/packages/store/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ @@ -5,7 +5,7 @@ import { UserState } from './states/user/user.state'; export const DashboardStates = [DictionaryState, UserState]; @State({ - name: 'dashboardStateModule', + name: 'dashboardState', children: DashboardStates }) -export class DashboardStateModule {} +export class DashboardState {} diff --git a/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ index c295ca045..cf8ac07be 100644 --- a/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ @@ -1,6 +1,6 @@ -import { PersonStateModel } from './user.state'; +import { UserStateModel } from './user.state'; export class SetUser { public static readonly type = '[SetUser] action'; - constructor(public payload: PersonStateModel) {} + constructor(public payload: UserStateModel) {} } diff --git a/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ index 16d31b1ea..424918d77 100644 --- a/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ @@ -1,6 +1,6 @@ import { NgxsModule, Store } from '@ngxs/store'; import { async, TestBed } from '@angular/core/testing'; -import { PersonStateModel, UserState } from './user.state'; +import { UserStateModel, UserState } from './user.state'; import { SetUser } from './user.actions'; describe('[TEST]: User state', () => { @@ -15,8 +15,8 @@ describe('[TEST]: User state', () => { store = TestBed.get(Store); })); - it('Should be state is PersonStateModel', () => { - const person: PersonStateModel = { + it('Should be state is UserStateModel', () => { + const user: UserStateModel = { userId: '', departmentCode: '', departmentName: '', @@ -27,14 +27,14 @@ describe('[TEST]: User state', () => { positionId: '', positionName: '' }; - store.dispatch(new SetUser(person)); + store.dispatch(new SetUser(user)); const actual = store.selectSnapshot(({ user }) => user); - expect(actual).toEqual(person); + expect(actual).toEqual(user); }); - it('Should be state is filled PersonStateModel', () => { - const person: PersonStateModel = { + it('Should be state is filled UserStateModel', () => { + const user: UserStateModel = { userId: '12', departmentCode: '2392', departmentName: 'Main office', @@ -46,9 +46,9 @@ describe('[TEST]: User state', () => { positionName: 'admin' }; - store.dispatch(new SetUser(person)); - const actual = store.selectSnapshot(({ user }) => user); + store.dispatch(new SetUser(user)); + const actual = store.selectSnapshot(({ user }) => user); - expect(actual).toEqual(person); + expect(actual).toEqual(user); }); }); diff --git a/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ index 6478a5083..fa28508d4 100644 --- a/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ @@ -1,7 +1,7 @@ import { Action, Selector, State, StateContext } from '@ngxs/store'; import { SetUser } from './user.actions'; -export interface PersonStateModel { +export interface UserStateModel { userId: string; email: string; firstName: string; @@ -13,7 +13,7 @@ export interface PersonStateModel { departmentName: string; } -@State({ +@State({ name: 'user', defaults: { userId: '', @@ -29,12 +29,12 @@ export interface PersonStateModel { }) export class UserState { @Selector() - public static getUser(state: PersonStateModel): PersonStateModel { + public static getUser(state: UserStateModel): UserStateModel { return state; } @Action(SetUser) - public setUser(ctx: StateContext, { payload }: SetUser) { + public setUser(ctx: StateContext, { payload }: SetUser) { ctx.setState(payload); } } diff --git a/packages/store/schematics/src/starter-kit/files/store/store.config.ts__template__ b/packages/store/schematics/src/starter-kit/files/store/store.config.ts__template__ index 9a0c156f8..992e7457b 100644 --- a/packages/store/schematics/src/starter-kit/files/store/store.config.ts__template__ +++ b/packages/store/schematics/src/starter-kit/files/store/store.config.ts__template__ @@ -1,10 +1,10 @@ -import { AuthStateModule } from './auth/auth.state'; -import { DashboardStates, DashboardStateModule } from './dashboard'; +import { AuthState } from './auth/auth.state'; +import { DashboardStates, DashboardState } from './dashboard'; import { NgxsConfig } from '@ngxs/store/src/symbols'; import { NgxsDevtoolsOptions } from '@ngxs/devtools-plugin/src/symbols'; import { NgxsLoggerPluginOptions } from '@ngxs/logger-plugin/src/symbols'; -export const STATES_MODULES = [AuthStateModule, DashboardStateModule, ...DashboardStates]; +export const STATES_MODULES = [AuthState, DashboardState, ...DashboardStates]; export const OPTIONS_CONFIG: Partial = { /**