Skip to content

Commit

Permalink
fix(schematics): dasherize the state and store file name (#2090)
Browse files Browse the repository at this point in the history
* fix(schematics): dasherize the state and store file name

* chore: remove public access modifier
  • Loading branch information
profanis authored Dec 18, 2023
1 parent 414599c commit e0981de
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class <%= classify(name) %>Action {
public static readonly type = '[<%= classify(name) %>] Add item';
constructor(public payload: any) { }
static readonly type = '[<%= classify(name) %>] Add item';
constructor(readonly payload: any) { }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AuthenticationStateModel } from './auth.state';

export class SetAuthData {
public static readonly type = '[Auth] Auth data';

constructor(public payload: AuthenticationStateModel) {}
static readonly type = '[Auth] Auth data';
constructor(readonly payload: AuthenticationStateModel) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface AuthenticationStateModel {
@Injectable()
export class AuthState {
@Selector()
public static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel {
static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel {
return AuthState.getInstanceState(state);
}

Expand All @@ -38,7 +38,7 @@ export class AuthState {
}

@Action(SetAuthData)
public setAuthData(
setAuthData(
{ setState }: StateContext<AuthenticationStateModel>,
{ payload }: SetAuthData
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { DictionaryStateModel } from './dictionary.state';

export class SetDictionaryData {
public static readonly type = '[Dictionary] Set dictionary data action';

constructor(public payload: DictionaryStateModel) {}
static readonly type = '[Dictionary] Set dictionary data action';
constructor(readonly payload: DictionaryStateModel) {}
}

export class DictionaryReset {
public static readonly type = '[Dictionary] Reset dictionary action';

constructor() {}
static readonly type = '[Dictionary] Reset dictionary action';
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export interface DictionaryStateModel {
@Injectable()
export class DictionaryState {
@Selector()
public static getDictionaryState(state: DictionaryStateModel): DictionaryStateModel {
static getDictionaryState(state: DictionaryStateModel): DictionaryStateModel {
return DictionaryState.getInstanceState(state);
}

@Selector()
public static getDictionaryContent(state: DictionaryStateModel) {
static getDictionaryContent(state: DictionaryStateModel) {
return state.content;
}

Expand All @@ -41,15 +41,15 @@ export class DictionaryState {
}

@Action(SetDictionaryData)
public setTasks(
setTasks(
{ setState }: StateContext<DictionaryStateModel>,
{ payload }: SetDictionaryData
) {
setState(DictionaryState.setInstanceState(payload));
}

@Action(DictionaryReset)
public resetTasks({ setState }: StateContext<DictionaryStateModel>) {
resetTasks({ setState }: StateContext<DictionaryStateModel>) {
const initialState = {
content: [],
page: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserStateModel } from './user.state';

export class SetUser {
public static readonly type = '[SetUser] action';
constructor(public payload: UserStateModel) {}
static readonly type = '[SetUser] action';
constructor(readonly payload: UserStateModel) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export interface UserStateModel {
@Injectable()
export class UserState {
@Selector()
public static getUser(state: UserStateModel): UserStateModel {
static getUser(state: UserStateModel): UserStateModel {
return state;
}

@Action(SetUser)
public setUser(ctx: StateContext<UserStateModel>, { payload }: SetUser) {
setUser(ctx: StateContext<UserStateModel>, { payload }: SetUser) {
ctx.setState(payload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface <%= classify(name) %>StateModel {
export class <%= classify(name) %>State {

@Selector()
public static getState(state: <%= classify(name) %>StateModel) {
static getState(state: <%= classify(name) %>StateModel) {
return state;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/store/schematics/src/state/state.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export function state(options: StateSchema): Rule {
? normalizedOptions.path
: join(normalizedOptions.path, normalizedOptions.name);

return generateFiles(url('./files'), path, { ...options, isStandalone }, options.spec);
return generateFiles(
url('./files'),
path,
{ ...normalizedOptions, isStandalone },
options.spec
);
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class <%= classify(name) %>Action {
public static readonly type = '[<%= classify(name) %>] Add item';
constructor(public payload: string) { }
}
static readonly type = '[<%= classify(name) %>] Add item';
constructor(readonly payload: string) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export interface <%= classify(name) %>StateModel {
export class <%= classify(name) %>State {

@Selector()
public static getState(state: <%= classify(name) %>StateModel) {
static getState(state: <%= classify(name) %>StateModel) {
return state;
}

@Action(<%= classify(name) %>Action)
public add(ctx: StateContext<<%= classify(name) %>StateModel>, { payload }: <%= classify(name) %>Action) {
add(ctx: StateContext<<%= classify(name) %>StateModel>, { payload }: <%= classify(name) %>Action) {
const stateModel = ctx.getState();
stateModel.items = [...stateModel.items, payload];
ctx.setState(stateModel);
Expand Down
7 changes: 6 additions & 1 deletion packages/store/schematics/src/store/store.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export function store(options: StoreSchema): Rule {
? normalizedOptions.path
: join(normalizedOptions.path, normalizedOptions.name);

return generateFiles(url('./files'), path, { ...options, isStandalone }, options.spec);
return generateFiles(
url('./files'),
path,
{ ...normalizedOptions, isStandalone },
options.spec
);
};
}

0 comments on commit e0981de

Please sign in to comment.