How to use the redux-persist.createTransform function in redux-persist

To help you get started, we’ve selected a few redux-persist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github csprance / MisRCON / src / lib / value-transformers.ts View on Github external
// redux-persist value transforms to store and restore non serializable state
import { createTransform } from 'redux-persist';

import { makeDefaultOutputs } from '../components/RCONTerminal/defaults';
import { ServersState } from '../redux/servers';
import { OnTickFunctionFactory, TasksState } from '../redux/tasks';
import { Terminal } from '../redux/terminal/types';
import { decryptPassword, encryptPassword } from './crypto';

// Null out our cronjob and stringify <-> functionify onTick
export const functionTransform = createTransform(
  // Called before state is persisted
  (inboundState: TasksState) => {
    return inboundState.map(task => {
      return {
        ...task,
        job: null,
        onTick: String(task.onTick)
      };
    });
  },
  // Called before state is rehydrated
  outboundState => {
    return outboundState.map((task: any) => ({
      ...task,
      job: null,
      onTick: eval(task.onTick) as OnTickFunctionFactory // tslint:disable-line
github kamranahmedse / redux-persist-expire / index.js View on Github external
const defaults = {
    // Key to be used for the time relative to which store is to be expired
    persistedAtKey: '__persisted_at',
    // Seconds after which store will be expired
    expireSeconds: null,
    // State to be used for resetting e.g. provide initial reducer state
    expiredState: {},
    // Use it if you don't want to manually set the time and want the store to
    // be automatically expired if the record is not updated in the `expireSeconds` time
    autoExpire: false
  };

  config = Object.assign({}, defaults, config);

  return createTransform(
    // transform state on its way to being serialized and persisted.
    (inboundState) => transformPersistence(inboundState, config),
    // transform state being rehydrated
    (outboundState) => transformRehydrate(outboundState, config),
    // define which reducers this transform gets called for.
    {
      whitelist: [reducerKey]
    }
  );
}
github blackLearning / react-native-cloud-music / src / redux / store / index.js View on Github external
import reduxThunk from 'redux-thunk';
import { persistReducer, persistStore, createTransform } from 'redux-persist';
import rootReducer from '../reducer';
import enhancers from './enhancers';
import screenTrackingMiddleware from './screenTrackingMiddleware';

// Note: logger must be the last middleware in chain,
// otherwise it will log thunk and promise, not actual actions
const sagaMiddleware = createSagaMiddleware();
const middlewares = [reduxThunk, screenTrackingMiddleware, sagaMiddleware];
if (__DEV__) {
  const { logger } = require('redux-logger'); // eslint-disable-line
  middlewares.unshift(logger);
}

const myTransform = createTransform(
  // transform state coming from redux on its way to being serialized and stored
  state => (Immutable.isImmutable(state) ? Immutable.asMutable(state) : state),
  // transform state coming from storage, on its way to be rehydrated into redux
  state => Immutable(state)
)

const config = {
  key: 'root',
  debug: true,
  blacklist: ['nav', '_persist'],
  transforms: [myTransform],
  storage,
};

export const store = createStore(
  persistReducer(config, rootReducer),
github shoutem / extensions / shoutem-persist / app / enhancers.js View on Github external
const persistStoreEnhancer = createStore => (...args) => {
  const store = createStore(...args);
  storePersistor = persistStore(
    store,
    {
      storage: AsyncStorage, // Use RN storage system
      transforms: [createTransform(toSerializableFormat, fromSerializableFormat)],
    }
  );
  return store;
};
github mattermost / mattermost-redux / test / test_store.js View on Github external
export default async function testConfigureStore() {
    const storageTransform = createTransform(
      () => ({}),
      () => ({})
    );

    const offlineConfig = {
        detectNetwork: () => true,
        persist: (store, options) => {
            return persistStore(store, {storage: new AsyncNodeStorage('./.tmp'), ...options});
        },
        persistOptions: {
            debounce: 1000,
            transforms: [
                storageTransform
            ]
        }
    };
github foxfolio / foxfolio-desktop / app / store / configureReduxPersist.ts View on Github external
const createExchangeTransform = () =>
  createTransform((inboundState, key) => {
    if (key === 'exchanges') {
      return _.mapValues(inboundState, object => _.omit(object, 'openRequests'));
    }
    return inboundState;
  }, _.identity);
github mattermost / mattermost-webapp / store / index.js View on Github external
export default function configureStore(initialState) {
    const setTransformer = createTransform(
        (inboundState, key) => {
            if (key === 'entities') {
                const state = {...inboundState};
                for (const prop in state) {
                    if (state.hasOwnProperty(prop)) {
                        state[prop] = transformSet(state[prop], setTransforms);
                    }
                }

                return state;
            }

            return inboundState;
        },
        (outboundState, key) => {
            if (key === 'entities') {
github este / este / src / common / configureStorage.js View on Github external
paths.forEach(([feature, props]) => {
  whitelist.push(feature);
  if (!props) return;
  const inOut = state => pick(props, state);
  transforms.push(createTransform(inOut, inOut, { whitelist: [feature] }));
});
github Noitidart / Chrome-Store-Foxified / src / webext / flow-control / filesTransform.js View on Github external
if (err) reject(err);
            else {
                somethingRead = true;
                LAST_STATE[id] = stateNew[id] = { data:value };
                resolve();
            }
        }) );
    });


    await Promise.all(reads);

    return somethingRead ? { ...LAST_STATE } : state;
}

export default createTransform(
    inbound,
    outbound,
    { whitelist:['files'] }
)
github alphasp / pxview / src / common / store / configureStore.js View on Github external
import { createStore, applyMiddleware, compose } from 'redux';
import createSagaMiddleware from 'redux-saga';
import invariant from 'redux-immutable-state-invariant';
import { persistStore, persistReducer, createTransform } from 'redux-persist';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import getStoredStateMigrateV4 from 'redux-persist/lib/integration/getStoredStateMigrateV4';
import applyAppStateListener from 'redux-enhancer-react-native-appstate';
import FileSystemStorage from 'redux-persist-filesystem-storage';
import AsyncStorage from '@react-native-community/async-storage';
import rootReducer from '../reducers';
import rootSaga from '../sagas';
import getStoredStateMigrateToFileSystemStorage from './getStoredStateMigrateToFileSystemStorage';

const myTransform = createTransform(
  (inboundState, key, state) => {
    switch (key) {
      case 'entities': {
        const {
          entities,
          browsingHistoryIllusts,
          browsingHistoryNovels,
          muteUsers,
        } = state;
        const selectedUsersEntities = {};
        const selectedIllustsEntities = browsingHistoryIllusts.items
          .filter(id => entities.illusts[id])
          .reduce((prev, id) => {
            prev[id] = entities.illusts[id];
            const userId = entities.illusts[id].user;
            selectedUsersEntities[userId] = entities.users[userId];