redux-persist#PersistMigrate TypeScript Examples

The following examples show how to use redux-persist#PersistMigrate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From marina with MIT License 6 votes vote down vote up
function createLocalStorageConfig<S>(
  key: string,
  migration: PersistMigrate,
  whitelist?: string[],
  blacklist?: string[],
  version = 0
): PersistConfig<S, any, any, any> {
  return {
    key,
    storage: browserLocalStorage,
    version,
    whitelist,
    blacklist,
    migrate: migration,
  };
}
Example #2
Source File: index.ts    From marina with MIT License 6 votes vote down vote up
// custom persist reducer function
function persist<S extends any>(opts: {
  reducer: Reducer<S, AnyAction>;
  migrate: PersistMigrate;
  key: string;
  whitelist?: string[];
  blacklist?: string[];
  version?: number;
}): Reducer<S & PersistPartial, AnyAction> {
  return persistReducer(
    createLocalStorageConfig(opts.key, opts.migrate, opts.whitelist, opts.blacklist, opts.version),
    opts.reducer
  );
}
Example #3
Source File: index.ts    From marina with MIT License 5 votes vote down vote up
migrateAfter =
  (initialState: any): PersistMigrate =>
  (state: any) =>
    Promise.resolve({
      ...initialState,
      ...state, // /!\ state should be merged **after** initialState !
    })
Example #4
Source File: index.ts    From marina with MIT License 5 votes vote down vote up
migrateBefore =
  (initialState: any): PersistMigrate =>
  (state: any) =>
    Promise.resolve({
      ...state, // /!\ state should be merged **before** initialState !
      ...initialState,
    })