Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const persistConfig = {
whitelist: ['entities', 'pagination']
};
// window.__data = initial state passed down by server to client
let initialState = window.__data; // eslint-disable-line
try {
const restoredState = await getStoredState(persistConfig);
initialState = merge({}, initialState, restoredState);
} catch (error) {
console.log('error restoring state:', error);
}
const dest = document.getElementById('content');
const store = configureStore(history, initialState);
const persistor = createPersistor(store, persistConfig); // eslint-disable-line
store.runSaga(rootSaga);
render(
,
dest
);
if (process.env.NODE_ENV !== 'production') {
window.React = React; // enable debugger
}
}
// 5. 启动应用
app.start('#root');
localForage.config({
...config,
});
persistStore(app._store, {
storage: localForage,
keyPrefix: 'webend:',
whitelist: ['global'],
});
// secondaryPersistor
createPersistor(app._store, {
keyPrefix: 'webend:',
whitelist: ['global'],
});
}
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers'); // eslint-disable-line global-require
store.replaceReducer(nextReducer);
});
}
}
const store = createStore(
rootReducer,
restoredState,
composeEnhancers(applyMiddleware(exportState, api))
);
const persistor = createPersistor(store, persistConfig);
callback(store, restoredState);
if (err) persistor.purge();
});
}
import { createStore, Reducer, Store } from "redux"
import { createPersistor, Transform } from "redux-persist"
import createCompressor = require("redux-persist-transform-compress")
const reducer: Reducer = (state: any, action: any) => ({ state, action })
const compressor: Transform = createCompressor({ whitelist : ["foo"] })
const store: Store = createStore(reducer)
createPersistor(store, { transforms : [compressor] })
import { createStore, Reducer, Store } from "redux"
import { createPersistor, Transform } from "redux-persist"
import createFilter from "redux-persist-transform-filter"
const reducer: Reducer = (state: any, action: any) => ({ state, action })
const filter: Transform = createFilter(
"foo",
["foo.bar"],
["fizz.buzz"]
)
const store: Store = createStore(reducer)
createPersistor(store, { transforms : [filter] })
import { createStore, Reducer, Store } from "redux"
import { createPersistor, Transform } from "redux-persist"
import { EncryptorConfig } from "redux-persist-transform-encrypt"
import createEncryptor from "redux-persist-transform-encrypt"
import createAsyncEncryptor from "redux-persist-transform-encrypt/async"
const reducer: Reducer = (state: any, action: any) => ({ state, action })
const config: EncryptorConfig = { secretKey : "foo" }
const encryptor: Transform = createEncryptor(config)
const asyncEncryptor: Transform = createAsyncEncryptor(config)
const store: Store = createStore(reducer)
createPersistor(store, { transforms : [encryptor, asyncEncryptor] })
.then(() => {
const incomingState = state.getState();
const updatedState = updateSafely(incomingState, restoredState, config.blacklist);
const persistor = createPersistor(state, config);
persistor.rehydrate(updatedState);
return persistState(state, config, cb);
})
.catch(() => persistState(state, config, cb));
const createPersistor = (store, config = {}, ...args) => {
return baseCreatePersistor(store, extendConfig(config), ...args)
}