-
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 logging actions style
BREAKING CHANGE: Due to an improvement on how actions are defined, the enum `StarkLoggingActionsTypes` became obsolete so it has been removed. As a result, the following actions have been changed: - `StarkSetLoggingApplicationId(public applicationId: string)` -> `StarkLoggingActions.setLoggingApplicationId({ applicationId: string })` - `StarkLogMessageAction(public message: StarkLogMessage)` -> `StarkLoggingActions.logMessage({ message: StarkLogMessage })` - `StarkFlushLogMessages(public numberOfMessagesToFlush: number)` -> `StarkLoggingActions.flushLogMessages({ numberOfMessagesToFlush: number })` And aso the previous union type has been replaced: `StarkLoggingActions` -> `StarkLoggingActions.Types`. Change in effect: ```typescript // Before @effect({ dispatch: false }) public starkLogMessageAction$(): Observable<void> { return this.actions$.pipe( ofType<StarkLogMessageAction>(StarkLoggingActionsTypes.LOG_MESSAGE), map((action: StarkLogMessageAction) => { // some logic }) ); } // After public starkLogMessageAction$ = createEffect( () => this.actions$.pipe( ofType(StarkLoggingActions.logMessage), map((action) => { // some logic }) ), { dispatch: false } ); ``` Change in `action` usage: ```typescript // Before this.store.dispatch(new StarkLogMessageAction(message)); // After this.store.dispatch(StarkLoggingActions.logMessage({ message: message })); ```
- Loading branch information
1 parent
f1803a8
commit 3dd57d2
Showing
14 changed files
with
113 additions
and
120 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/logging.actions"; | ||
import * as StarkLoggingActions from "./actions/logging.actions"; | ||
export { StarkLoggingActions }; |
66 changes: 19 additions & 47 deletions
66
packages/stark-core/src/modules/logging/actions/logging.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,61 +1,33 @@ | ||
import { Action } from "@ngrx/store"; | ||
import { createAction, props, union } from "@ngrx/store"; | ||
import { StarkLogMessage } from "../entities"; | ||
|
||
/** | ||
* Actions related to {@link StarkLoggingService} | ||
*/ | ||
export enum StarkLoggingActionTypes { | ||
SET_LOGGING_APPLICATION_ID = "[StarkLogging] Set Logging Application Id", | ||
LOG_MESSAGE = "[StarkLogging] Log Message", | ||
FLUSH_LOG = "[StarkLogging] Flush Log" | ||
} | ||
import { starkLoggingStoreKey } from "../constants"; | ||
|
||
/** | ||
* Add the Application Name to the logging object | ||
* | ||
* Parameter: | ||
* - applicationId - The id of the application | ||
*/ | ||
export class StarkSetLoggingApplicationId implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkLoggingActionTypes.SET_LOGGING_APPLICATION_ID = StarkLoggingActionTypes.SET_LOGGING_APPLICATION_ID; | ||
|
||
/** | ||
* Class constructor | ||
* @param applicationId - The id of the application | ||
*/ | ||
public constructor(public applicationId: string) {} | ||
} | ||
export const setLoggingApplicationId = createAction(`[${starkLoggingStoreKey}] Set Logging Application Id`, props<{ applicationId: string }>()); | ||
|
||
/** | ||
* Store a debug/info/warning/error message | ||
* | ||
* Parameter: | ||
* - message - The message to log | ||
*/ | ||
export class StarkLogMessageAction implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkLoggingActionTypes.LOG_MESSAGE = StarkLoggingActionTypes.LOG_MESSAGE; | ||
|
||
/** | ||
* Class constructor | ||
* @param message - The message to log | ||
*/ | ||
public constructor(public message: StarkLogMessage) {} | ||
} | ||
export const logMessage = createAction(`[${starkLoggingStoreKey}] Log Message`, props<{ message: StarkLogMessage }>()); | ||
|
||
/** | ||
* Persists the log messages in the redux store to the back-end | ||
* | ||
* Parameter: | ||
* - numberOfMessagesToFlush - The number of messages to flush | ||
*/ | ||
export class StarkFlushLogMessages implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: StarkLoggingActionTypes.FLUSH_LOG = StarkLoggingActionTypes.FLUSH_LOG; | ||
|
||
/** | ||
* Class constructor | ||
* @param numberOfMessagesToFlush - The number of messages to flush | ||
*/ | ||
public constructor(public numberOfMessagesToFlush: number) {} | ||
} | ||
export const flushLogMessages = createAction(`[${starkLoggingStoreKey}] Flush Log`, props<{ numberOfMessagesToFlush: number }>()); | ||
|
||
export type StarkLoggingActions = StarkSetLoggingApplicationId | StarkLogMessageAction | StarkFlushLogMessages; | ||
/** | ||
* @ignore | ||
*/ | ||
const all = union({ setLoggingApplicationId, logMessage, flushLogMessages }); | ||
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/logging-store-key"; |
4 changes: 4 additions & 0 deletions
4
packages/stark-core/src/modules/logging/constants/logging-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 @@ | ||
/** | ||
* The store key will allow the application to find the reducer in the store | ||
*/ | ||
export const starkLoggingStoreKey = "StarkLogging"; |
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/logging.reducer"; | ||
export { selectStarkLogging, starkLoggingReducers, StarkLoggingState } from "./reducers/index"; | ||
export { loggingReducer } from "./reducers/logging.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
Oops, something went wrong.