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 26, 2024
1 parent f703128 commit fda2794
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/@o3r/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@capacitor/device": "^5.0.0",
"@capacitor/preferences": "^5.0.0",
"@ngrx/store": "~16.3.0",
"@ngrx/store-devtools": "~16.3.0",
"@o3r/core": "workspace:^",
"@o3r/logger": "workspace:^",
"@o3r/schematics": "workspace:^",
Expand Down Expand Up @@ -78,6 +79,7 @@
"@capacitor/preferences": "^5.0.0",
"@compodoc/compodoc": "^1.1.19",
"@ngrx/store": "~16.3.0",
"@ngrx/store-devtools": "~16.3.0",
"@nx/eslint-plugin": "~16.10.0",
"@nx/jest": "~16.10.0",
"@nx/js": "~16.10.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/@o3r/store-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@angular-devkit/schematics": "~16.2.0",
"@ngrx/entity": "~16.3.0",
"@ngrx/store": "~16.3.0",
"@ngrx/store-devtools": "~16.3.0",
"@o3r/core": "workspace:^",
"@o3r/dev-tools": "workspace:^",
"@o3r/logger": "workspace:^",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@angular/platform-browser-dynamic": "~16.2.0",
"@ngrx/entity": "~16.3.0",
"@ngrx/store": "~16.3.0",
"@ngrx/store-devtools": "~16.3.0",
"@nx/eslint-plugin": "~16.10.0",
"@nx/js": "~16.10.0",
"@nx/linter": "~16.10.0",
Expand Down
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
@@ -1,8 +1,12 @@
import { INIT, UPDATE } from '@ngrx/store';
import type { RECOMPUTE } from '@ngrx/store-devtools';
import { deepFill } from '@o3r/core';
import type { Logger } from '@o3r/core';
import type { StorageKeyConfiguration, StorageKeys, SyncStorageConfig, SyncStorageSyncOptions } from './interfaces';

/** The recompute action type of ngrx store devtools */
const RECOMPUTE_ACTION: typeof RECOMPUTE = '@ngrx/store-devtools/recompute';

/**
* Reviver the date from a JSON field if the string is matching iso format. Return the same value otherwise
*
Expand Down Expand Up @@ -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 ((action.type === INIT || action.type === UPDATE || action.type === RECOMPUTE_ACTION) && !state) {
nextState = reducer(state, action);
} else {
nextState = { ...state };
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8167,6 +8167,7 @@ __metadata:
"@capacitor/preferences": "npm:^5.0.0"
"@compodoc/compodoc": "npm:^1.1.19"
"@ngrx/store": "npm:~16.3.0"
"@ngrx/store-devtools": "npm:~16.3.0"
"@nx/eslint-plugin": "npm:~16.10.0"
"@nx/jest": "npm:~16.10.0"
"@nx/js": "npm:~16.10.0"
Expand Down Expand Up @@ -8216,6 +8217,7 @@ __metadata:
"@capacitor/device": ^5.0.0
"@capacitor/preferences": ^5.0.0
"@ngrx/store": ~16.3.0
"@ngrx/store-devtools": ~16.3.0
"@o3r/core": "workspace:^"
"@o3r/logger": "workspace:^"
"@o3r/schematics": "workspace:^"
Expand Down Expand Up @@ -8621,6 +8623,7 @@ __metadata:
"@angular/platform-browser-dynamic": "npm:~16.2.0"
"@ngrx/entity": "npm:~16.3.0"
"@ngrx/store": "npm:~16.3.0"
"@ngrx/store-devtools": "npm:~16.3.0"
"@nx/eslint-plugin": "npm:~16.10.0"
"@nx/js": "npm:~16.10.0"
"@nx/linter": "npm:~16.10.0"
Expand Down Expand Up @@ -8659,6 +8662,7 @@ __metadata:
"@angular-devkit/schematics": ~16.2.0
"@ngrx/entity": ~16.3.0
"@ngrx/store": ~16.3.0
"@ngrx/store-devtools": ~16.3.0
"@o3r/core": "workspace:^"
"@o3r/dev-tools": "workspace:^"
"@o3r/logger": "workspace:^"
Expand Down

0 comments on commit fda2794

Please sign in to comment.