Skip to content

Commit

Permalink
refactor(dependency): migrate deepmerge to ts-deepmerge
Browse files Browse the repository at this point in the history
Migrated the deepmerge library to ts-deepmerge for better TypeScript compatibility and enhanced type checking.

fixes btroncone#229
  • Loading branch information
NeizanSenpai committed Aug 5, 2023
1 parent ce3f480 commit a7766c8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
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"
}
}
8 changes: 4 additions & 4 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 @@ -227,11 +227,11 @@ export const syncStateUpdate = (
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 = {
mergeArrays: overwriteMerge,
};

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

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

0 comments on commit a7766c8

Please sign in to comment.