next-persist
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "next-persist", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Bridging the gap between client-side persistence and server-side rendering", | ||
@@ -5,0 +5,0 @@ "main": "src/next-persist.js", |
@@ -24,6 +24,7 @@ /** | ||
nextPersistCookie.setCookie = (cookieConfig, state) => { | ||
const { key, allowList } = cookieConfig; | ||
const key = Object.keys(cookieConfig)[0]; | ||
const allowList = Object.values(cookieConfig)[0]; | ||
// if allowList was not defined in cookieConfig, sets cookie containing entire state | ||
if (!allowList) { | ||
Cookie.set(key, state); | ||
if (allowList.length === 0) { | ||
Cookie.set(key, JSON.stringify(state)); | ||
} else { | ||
@@ -35,3 +36,3 @@ // sets cookie containing only properties listed in allowList | ||
}, {}); | ||
Cookie.set(key, allowedState); | ||
Cookie.set(key, JSON.stringify(allowedState)); | ||
} | ||
@@ -52,11 +53,11 @@ }; | ||
nextPersistCookie.getCookie = (req, state, cookieName) => { | ||
nextPersistCookie.getCookie = (req, cookieName, state) => { | ||
// if application is running client-side, parse and return cookie from browser | ||
if (!req) { | ||
const stateFromCookie = Cookie.get(cookieName); | ||
return stateFromCookie ? JSON.parse(stateFromCookie) : state | ||
return stateFromCookie ? JSON.parse(stateFromCookie) : state; | ||
} // if application is running server-side, parse and return cooking from request body | ||
else return cookie.parse(req.ctx.req.headers.cookie || ''); | ||
} | ||
}; | ||
module.exports = nextPersistCookie; |
@@ -21,3 +21,4 @@ /** | ||
nextPersist.setStorage = (storageConfig, state) => { | ||
const { key, allowList } = storageConfig; | ||
const key = Object.keys(storageConfig)[0]; | ||
const allowList = Object.values(storageConfig)[0]; | ||
@@ -27,3 +28,3 @@ // if application is running client-side, localStorage is accessible | ||
// if allowList was not defined in persistConfig, set all propertiesfrom state to localStorage | ||
if (!allowList) { | ||
if (allowList.length === 0) { | ||
localStorage.setItem(key, JSON.stringify(state)); | ||
@@ -30,0 +31,0 @@ } else { |
@@ -32,23 +32,18 @@ /** | ||
// if redux combines reducers, each reducer's state gets saved to local storage | ||
// under a unique key specified in wrapperConfig | ||
if (this.props.wrapperConfig.combinedReducers) { | ||
const { allowedKeys } = this.props.wrapperConfig; | ||
const { allowedReducers } = this.props.wrapperConfig; | ||
const { allowList } = this.props.wrapperConfig; | ||
const nextPersistConfig = {}; | ||
allowedReducers.forEach((allowedReducer, index) => { | ||
const nextPersistConfig = { | ||
key: allowedKeys[index], | ||
}; | ||
// if no allowlist provided save all state to their corresponding keys | ||
if (!allowList) { | ||
const key = Object.keys(this.props.state)[0]; | ||
nextPersistConfig[key] = []; | ||
method(nextPersistConfig, this.props.state[key]); | ||
} | ||
// if allowlist exists pass subconfigs of allowed reducers into storage method | ||
else { | ||
const allowedReducers = Object.keys(allowList); | ||
allowedReducers.forEach((allowedReducer) => { | ||
nextPersistConfig[allowedReducer] = allowList[allowedReducer]; | ||
method(nextPersistConfig, this.props.state[allowedReducer]); | ||
}); | ||
// otherwise, the single reducer's state gets saved to local storage | ||
// according to allowList configuration | ||
} else { | ||
const nextPersistConfig = { | ||
key: this.props.wrapperConfig.key, | ||
allowList: this.props.wrapperConfig.allowList, | ||
}; | ||
method(nextPersistConfig, this.props.state); | ||
} | ||
@@ -55,0 +50,0 @@ return this.props.children; |
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
7857
6
163