Skip to content

Commit

Permalink
feat(store): change the StateModule name into State (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
profanis authored Nov 23, 2023
1 parent f7ec3a6 commit 783234c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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', () => {
let store: Store;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NgxsModule.forRoot([AuthStateModule])]
imports: [NgxsModule.forRoot([AuthState])]
})
.compileComponents()
.then();
Expand All @@ -25,7 +25,7 @@ describe('[TEST]: AuthStore', () => {
roles: []
};
store.dispatch(new SetAuthData(Authentication));
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthStateModule.getAuthData);
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
expect(actual).toEqual(Authentication);
});

Expand All @@ -40,7 +40,7 @@ describe('[TEST]: AuthStore', () => {
};

store.dispatch(new SetAuthData(authentication));
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthStateModule.getAuthData);
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
expect(actual).toEqual(authentication);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface AuthenticationStateModel {
}

@State<AuthenticationStateModel>({
name: 'authStateModule',
name: 'authState',
defaults: {
id: '',
firstName: '',
Expand All @@ -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 {
Expand All @@ -40,6 +40,6 @@ export class AuthStateModule {
{ setState }: StateContext<AuthenticationStateModel>,
{ payload }: SetAuthData
) {
setState(AuthStateModule.setInstanceState(payload));
setState(AuthState.setInstanceState(payload));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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: '',
Expand All @@ -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',
Expand All @@ -46,9 +46,9 @@ describe('[TEST]: User state', () => {
positionName: 'admin'
};

store.dispatch(new SetUser(person));
const actual = store.selectSnapshot<PersonStateModel>(({ user }) => user);
store.dispatch(new SetUser(user));
const actual = store.selectSnapshot<UserStateModel>(({ user }) => user);

expect(actual).toEqual(person);
expect(actual).toEqual(user);
});
});
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +13,7 @@ export interface PersonStateModel {
departmentName: string;
}

@State<PersonStateModel>({
@State<UserStateModel>({
name: 'user',
defaults: {
userId: '',
Expand All @@ -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<PersonStateModel>, { payload }: SetUser) {
public setUser(ctx: StateContext<UserStateModel>, { payload }: SetUser) {
ctx.setState(payload);
}
}
Original file line number Diff line number Diff line change
@@ -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<NgxsConfig> = {
/**
Expand Down

0 comments on commit 783234c

Please sign in to comment.