-
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 error handling actions style
Adapt showcase code BREAKING CHANGE: Due to an improvement on how actions are defined, the enum `StarkErrorHandlingActionsTypes` became obsolete so it has been removed. As a result, the following actions have been changed: - `StarkUnhandledError(public error: any)` -> `StarkErrorHandlingActions.unhandledError({ error: any })` And also the previous union type has been replaced: `StarkErrorHandlingActions` -> `StarkErrorHandlingActions.Types`. Change in effect: ```typescript // Before @effect({ dispatch: false }) public starkUnhandledError$(): Observable<void> { return this.actions$.pipe( ofType<StarkUnhandledError>(StarkErrorHandlingActionTypes.UNHANDLED_ERROR), map((action: StarkUnhandledError) => { // some logic }) ); } // After public starkUnhandledError$ = createEffect( () => this.actions$.pipe( ofType(StarkErrorHandlingActions.unhandledError), map((action) => { // some logic }) ), { dispatch: false } ); ``` Change in `action` usage: ```typescript // Before this.store.dispatch(new StarkUnhandledError(error)); // After this.store.dispatch(StarkErrorHandlingActions.unhandledError({ error: error })); ```
- Loading branch information
1 parent
8418efc
commit 727c244
Showing
4 changed files
with
35 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./actions/error-handling.actions"; | ||
import * as StarkErrorHandlingActions from "./actions/error-handling.actions"; | ||
export { StarkErrorHandlingActions }; |
30 changes: 9 additions & 21 deletions
30
packages/stark-core/src/modules/error-handling/actions/error-handling.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,27 +1,15 @@ | ||
import { Action } from "@ngrx/store"; | ||
import { createAction, props, union } from "@ngrx/store"; | ||
|
||
/** | ||
* All the StarkErrorHandling action types | ||
* Action that requires to display an error message as a toast notification | ||
* | ||
* Parameter: | ||
* - error - The error to display | ||
*/ | ||
export enum StarkErrorHandlingActionTypes { | ||
UNHANDLED_ERROR = "[StarkErrorHandling] Unhandled Error" | ||
} | ||
export const unhandledError = createAction("[StarkErrorHandling] Unhandled Error", props<{ error: any }>()); | ||
|
||
/** | ||
* Action that requires to display an error message as a toast notification | ||
* @returns The created action object | ||
* @ignore | ||
*/ | ||
export class StarkUnhandledError implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkErrorHandlingActionTypes.UNHANDLED_ERROR = StarkErrorHandlingActionTypes.UNHANDLED_ERROR; | ||
|
||
/** | ||
* Class constructor | ||
* @param error - The error to display | ||
*/ | ||
public constructor(public error: any) {} | ||
} | ||
|
||
export type StarkErrorHandlingActions = StarkUnhandledError; | ||
const all = union({ unhandledError }); | ||
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
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