Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dependency): migrate deepmerge to ts-deepmerge #256

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@angular/platform-browser-dynamic": "^16.0.1",
"@angular/router": "^16.0.1",
"@ngrx/store": "^16.0.0",
"deepmerge": "^4.2.2",
"rxjs": "~7.5.5",
"ts-deepmerge": "^6.2.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/lib/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"entryFile": "src/public_api.ts"
},
"allowedNonPeerDependencies": [
"deepmerge"
"ts-deepmerge"
]
}
2 changes: 1 addition & 1 deletion projects/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@ngrx/store": "^16.0.0"
},
"dependencies": {
"deepmerge": "^4.2.2",
"ts-deepmerge": "^6.2.0",
"tslib": "^2.3.0"
}
}
11 changes: 6 additions & 5 deletions projects/lib/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import deepmerge from 'deepmerge';
import merge from 'ts-deepmerge';

// Cannot import from the @ngrx/store package due to a module resolution issue.
// See Issue #206.
Expand Down Expand Up @@ -226,12 +226,13 @@ export const syncStateUpdate = (
// Default merge strategy is a full deep merge.
export const defaultMergeReducer = (state: any, rehydratedState: any, action: any) => {
if ((action.type === INIT_ACTION || action.type === UPDATE_ACTION) && rehydratedState) {
const overwriteMerge = (destinationArray: any, sourceArray: any, options: any) => sourceArray;
const options: deepmerge.Options = {
arrayMerge: overwriteMerge,
const options = {
allowUndefinedOverrides: false,
mergeArrays: true,
uniqueArrayItems: false
};

state = deepmerge(state, rehydratedState, options);
state = merge.withOptions(options, state, rehydratedState);
}

return state;
Expand Down
6 changes: 3 additions & 3 deletions spec/index_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare var it, describe, expect;
require('es6-shim');
import * as CryptoJS from 'crypto-js';
import deepmerge from 'deepmerge';
import merge from 'ts-deepmerge';
import 'localstorage-polyfill';
import { dateReviver, localStorageSync, rehydrateApplicationState, syncStateUpdate } from '../projects/lib/src/public_api';

Expand Down Expand Up @@ -525,14 +525,14 @@ describe('ngrxLocalStorage', () => {
const reducer = (state = initialState, action) => state;
const mergeReducer = (state, rehydratedState, action) => {
// Perform a merge where we only want a single property from feature1
// but a deepmerge with feature2
// but a merge with feature2

return {
...state,
feature1: {
slice11: rehydratedState.feature1.slice11,
},
feature2: deepmerge(state.feature2, rehydratedState.feature2),
feature2: merge(state.feature2, rehydratedState.feature2),
};
};
const metaReducer = localStorageSync({
Expand Down