Skip to content

Commit

Permalink
feat: Add the possibility to specify action types to invoke the reduc…
Browse files Browse the repository at this point in the history
…er in the storage sync helper
  • Loading branch information
Abhishek Buragohain committed Feb 7, 2024
1 parent f703128 commit 3098090
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/@o3r/store-sync/src/sync-storage/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ export interface SyncStorageConfig {
logger?: Logger;
/** Post process after sync storage execution */
postProcess?: (state: any) => void;
/** The list of action types to invoke the reducer for the respective store when the state is not defined */
actionTypes?: string[];
}
6 changes: 5 additions & 1 deletion packages/@o3r/store-sync/src/sync-storage/storage-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ export const syncStorage = (config: SyncStorageConfig) => (reducer: any) => {
config.restoreDates = true;
}

if (!config.actionTypes) {
config.actionTypes = [INIT];
}

// Use default merge reducer.
let mergeReducer = config.mergeReducer;

Expand All @@ -328,7 +332,7 @@ export const syncStorage = (config: SyncStorageConfig) => (reducer: any) => {

// If state arrives undefined, we need to let it through the supplied reducer
// in order to get a complete state as defined by user
if (action.type === INIT && !state) {
if (config.actionTypes!.includes(action.type) && !state) {
nextState = reducer(state, action);
} else {
nextState = { ...state };
Expand Down

0 comments on commit 3098090

Please sign in to comment.