-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stark-core): update settings actions style
BREAKING CHANGE: Due to an improvement on how actions are defined, the enum `StarkSettingsActionsTypes` became obsolete so it has been removed. As a result, the following actions have been changed: - `StarkPersistPreferredLanguage(public language: string)` -> `StarkSettingsActions.persistPreferredLanguage({ language: string })` - `StarkPersistPreferredLanguageSuccess()` -> `StarkSettingsActions.persistPreferredLanguageSuccess()` - `StarkPersistPreferredLanguageFailure(public error: any)` -> `StarkSettingsActions.persistPreferredLanguageFailure({ error: any })` - `StarkSetPreferredLanguage(public language: string)` -> `StarkSettingsActions.setPreferredLanguage({ language: string })` And also the previous union type has been replaced: `StarkSettingsActions` -> `StarkSettingsActions.Types`. Change in effect: ```typescript // Before @effect({ dispatch: false }) public starkSetPreferredLanguage$(): Observable<void> { return this.actions$.pipe( ofType<StarkSetPreferredLanguage>(StarkSettingsActionsTypes.SET_PREFERRED_LANGUAGE), map((action: StarkSetPreferredLanguage) => { // some logic }) ); } // After public starkSetPreferredLanguage$ = createEffect( () => this.actions$.pipe( ofType(StarkSettingsActions.setPreferredLanguage), map((action) => { // some logic }) ), { dispatch: false } ); ``` Change in `action` usage: ```typescript // Before this.store.dispatch(new StarkSetPreferredLanguage(language)); // After this.store.dispatch(StarkSettingsActions.StarkSetPreferredLanguage({ language: language })); ```
- Loading branch information
1 parent
810bbc1
commit f1803a8
Showing
14 changed files
with
81 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./actions/settings.actions"; | ||
import * as StarkSettingsActions from "./actions/settings.actions"; | ||
export { StarkSettingsActions }; |
90 changes: 26 additions & 64 deletions
90
packages/stark-core/src/modules/settings/actions/settings.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,43 @@ | ||
import { Action } from "@ngrx/store"; | ||
|
||
/** | ||
* All the Settings action types | ||
*/ | ||
export enum StarkSettingsActionTypes { | ||
PERSIST_PREFERRED_LANGUAGE = "[StarkSettings] Persist Preferred Language", | ||
PERSIST_PREFERRED_LANGUAGE_SUCCESS = "[StarkSettings] Persist Preferred Language Success", | ||
PERSIST_PREFERRED_LANGUAGE_FAILURE = "[StarkSettings] Persist Preferred Language Failure", | ||
SET_PREFERRED_LANGUAGE = "[StarkSettings] Set Preferred Language" | ||
} | ||
import { createAction, props, union } from "@ngrx/store"; | ||
import { starkSettingsStoreKey } from "../constants"; | ||
|
||
/** | ||
* Action that requires to persist the given language locally so that the language remains the same when the user comes back | ||
* @returns The created action object | ||
* | ||
* Parameter: | ||
* - language - The language to persist | ||
*/ | ||
export class StarkPersistPreferredLanguage implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkSettingsActionTypes.PERSIST_PREFERRED_LANGUAGE = StarkSettingsActionTypes.PERSIST_PREFERRED_LANGUAGE; | ||
|
||
/** | ||
* Class constructor | ||
* @param language - The language to persist | ||
*/ | ||
public constructor(public language: string) {} | ||
} | ||
export const persistPreferredLanguage = createAction( | ||
`[${starkSettingsStoreKey}] Persist Preferred Language`, | ||
props<{ language: string }>() | ||
); | ||
|
||
/** | ||
* Action that notifies the application that the preferred language was successfully persisted. | ||
* @returns The created action object | ||
*/ | ||
export class StarkPersistPreferredLanguageSuccess implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkSettingsActionTypes.PERSIST_PREFERRED_LANGUAGE_SUCCESS = | ||
StarkSettingsActionTypes.PERSIST_PREFERRED_LANGUAGE_SUCCESS; | ||
} | ||
export const persistPreferredLanguageSuccess = createAction(`[${starkSettingsStoreKey}] Persist Preferred Language Success`); | ||
|
||
/** | ||
* Action that notifies the application that the preferred language could not be persisted. | ||
* @returns The created action object | ||
* | ||
* Parameter: | ||
* - error - The reason why the preferred language could not be persisted | ||
*/ | ||
export class StarkPersistPreferredLanguageFailure implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkSettingsActionTypes.PERSIST_PREFERRED_LANGUAGE_FAILURE = | ||
StarkSettingsActionTypes.PERSIST_PREFERRED_LANGUAGE_FAILURE; | ||
|
||
/** | ||
* Class constructor | ||
* @param error - The reason why the preferred language could not be persisted | ||
*/ | ||
public constructor(public error: any) {} | ||
} | ||
export const persistPreferredLanguageFailure = createAction( | ||
`[${starkSettingsStoreKey}] Persist Preferred Language Failure`, | ||
props<{ error: any }>() | ||
); | ||
|
||
/** | ||
* Action that notifies the application that the preferred language should be changed. | ||
* @returns The created action object | ||
* | ||
* Parameter: | ||
* - language - The new preferred language | ||
*/ | ||
export class StarkSetPreferredLanguage implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkSettingsActionTypes.SET_PREFERRED_LANGUAGE = StarkSettingsActionTypes.SET_PREFERRED_LANGUAGE; | ||
|
||
/** | ||
* Class constructor | ||
* @param language - The new preferred language | ||
*/ | ||
public constructor(public language: string) {} | ||
} | ||
export const setPreferredLanguage = createAction(`[${starkSettingsStoreKey}] Set Preferred Language`, props<{ language: string }>()); | ||
|
||
export type StarkSettingsActions = | ||
| StarkPersistPreferredLanguage | ||
| StarkPersistPreferredLanguageSuccess | ||
| StarkPersistPreferredLanguageFailure | ||
| StarkSetPreferredLanguage; | ||
/** | ||
* @ignore | ||
*/ | ||
const all = union({ persistPreferredLanguage, persistPreferredLanguageSuccess, persistPreferredLanguageFailure, setPreferredLanguage }); | ||
export type Types = typeof all; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./constants/settings-store-key"; |
4 changes: 4 additions & 0 deletions
4
packages/stark-core/src/modules/settings/constants/settings-store-key.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Key defined to find the service in a store | ||
*/ | ||
export const starkSettingsStoreKey = "StarkSettings"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./reducers/index"; | ||
export * from "./reducers/settings.reducer"; | ||
export { selectStarkSettings, starkSettingsReducers, StarkSettingsState } from "./reducers/index"; | ||
export { settingsReducer } from "./reducers/settings.reducer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters