Skip to content

Commit

Permalink
Merge pull request #173 from dnbo/fix-types-to-allow-mixed-partial-an…
Browse files Browse the repository at this point in the history
…d-full-state-sync-keys

fix: allow mix of partial and full state in keys
  • Loading branch information
BBlackwo authored Oct 23, 2020
2 parents dfb3537 + 2319cc4 commit c38b89f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 41 additions & 1 deletion spec/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ describe('ngrxLocalStorage', () => {
keys: [{ feature1: [{ slice11: ['slice11_1'], slice14: ['slice14_2'] }] }, { feature2: ['slice21'] }],
});

// Excute action
// Execute action
metaReducer((state: any, _action: any) => state)(
// Initial state with lots of unrelated properties
{
Expand All @@ -567,4 +567,44 @@ describe('ngrxLocalStorage', () => {
});
expect(JSON.parse(localStorage['feature2'])).toEqual({ slice21: 'third_good_value' });
});

it('should allow a mix of partial and full state in keys', () => {
// given
const metaReducer = localStorageSync({
keys: [
// partial state - object
{ feature1: [{ slice11: ['slice11_1'], slice14: ['slice14_2'] }] },

// full state - string
'feature2',
],
});

// when
metaReducer((state: any, _action: any) => state)(
{
feature1: {
slice11: { slice11_1: 'good_value', slice11_2: 'bad_value' },
slice12: [],
slice13: false,
slice14: { slice14_1: true, slice14_2: 'other_good_value' },
},
feature2: {
slice21: 'third_good_value',
slice22: 'fourth_good_value',
},
},
{ type: 'SomeAction' }
);

// then
expect(JSON.parse(localStorage['feature1'])).toEqual({
slice11: { slice11_1: 'good_value' },
slice14: { slice14_2: 'other_good_value' },
});
expect(JSON.parse(localStorage['feature2'])).toEqual({
slice21: 'third_good_value',
slice22: 'fourth_good_value',
});
});
});
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,4 @@ interface Options {
space?: string | number;
}

export type Keys = string[] | (KeyConfiguration | Options)[];
export type Keys = (KeyConfiguration | Options| string)[];

0 comments on commit c38b89f

Please sign in to comment.