ngrx-store-localstorage
Advanced tools
Comparing version 5.1.1 to 6.0.0
@@ -195,3 +195,19 @@ "use strict"; | ||
rehydratedState) { | ||
state = Object.assign({}, state, rehydratedState); | ||
if (state) { | ||
Object.keys(state).forEach(function (key) { | ||
if (state[key] instanceof Array && rehydratedState[key] instanceof Array) { | ||
state[key] = rehydratedState[key]; | ||
} | ||
else if (typeof state[key] === 'object' | ||
&& typeof rehydratedState[key] === 'object') { | ||
state[key] = Object.assign({}, state[key], rehydratedState[key]); | ||
} | ||
else { | ||
state[key] = rehydratedState[key]; | ||
} | ||
}); | ||
} | ||
else { | ||
state = Object.assign({}, state, rehydratedState); | ||
} | ||
} | ||
@@ -198,0 +214,0 @@ var nextState = reducer(state, action); |
{ | ||
"name": "ngrx-store-localstorage", | ||
"version": "5.1.1", | ||
"version": "6.0.0", | ||
"description": "State and local storage syncing for @ngrx/store", | ||
@@ -40,3 +40,3 @@ "main": "./dist/index.js", | ||
"@ngrx/core": "^1.2.0", | ||
"@ngrx/store": "^5.0.0", | ||
"@ngrx/store": "^7.0.0", | ||
"@types/core-js": "^0.9.35", | ||
@@ -51,2 +51,3 @@ "@types/crypto-js": "^3.1.33", | ||
"jasmine-core": "^2.4.1", | ||
"localstorage-polyfill": "^1.0.1", | ||
"rimraf": "^2.5.4", | ||
@@ -53,0 +54,0 @@ "rxjs": "^5.1.1", |
@@ -1,5 +0,7 @@ | ||
declare var beforeEachProviders, it, describe, expect, inject; | ||
declare var it, describe, expect; | ||
require('es6-shim'); | ||
import { syncStateUpdate, rehydrateApplicationState, dateReviver } from '../src/index'; | ||
import { syncStateUpdate, rehydrateApplicationState, dateReviver, localStorageSync } from '../src/index'; | ||
import * as CryptoJS from 'crypto-js'; | ||
import 'localstorage-polyfill'; | ||
const INIT_ACTION = '@ngrx/store/init'; | ||
@@ -419,2 +421,17 @@ // Very simple classes to test serialization options. They cover string, number, date, and nested classes | ||
}); | ||
it('merge initial state and rehydrated state', () => { | ||
// localStorage starts out in a "bad" state. This could happen if our application state schema | ||
// changes. End users may have the old schema and a software update has the new schema. | ||
localStorage.setItem('state', JSON.stringify({oldstring: 'foo'})); | ||
// Set up reducers | ||
const reducer = (state = initialState, action) => state; | ||
const metaReducer = localStorageSync({keys: ['state'], rehydrate: true}); | ||
const action = {type: INIT_ACTION}; | ||
// Resultant state should merge the oldstring state and our initual state | ||
const finalState = metaReducer(reducer)(initialState, action); | ||
expect(finalState.state.astring).toEqual(initialState.state.astring); | ||
}); | ||
}); |
@@ -249,3 +249,16 @@ const INIT_ACTION = '@ngrx/store/init'; | ||
) { | ||
state = Object.assign({}, state, rehydratedState); | ||
if (state) { | ||
Object.keys(state).forEach(function (key) { | ||
if (state[key] instanceof Array && rehydratedState[key] instanceof Array) { | ||
state[key] = rehydratedState[key]; | ||
} else if (typeof state[key] === 'object' | ||
&& typeof rehydratedState[key] === 'object') { | ||
state[key] = Object.assign({}, state[key], rehydratedState[key]); | ||
} else { | ||
state[key] = rehydratedState[key]; | ||
} | ||
}); | ||
} else { | ||
state = Object.assign({}, state, rehydratedState); | ||
} | ||
} | ||
@@ -252,0 +265,0 @@ const nextState = reducer(state, action); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59068
971
18