How to use the @wora/cache-persist.prefixLayer function in @wora/cache-persist

To help you get started, we’ve selected a few @wora/cache-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 morrys / wora / packages / redux / src / createStore.ts View on Github external
version = -1,
        key = 'root', // TODO verify
        whitelist = undefined,
        blacklist = undefined,
        mutateKeys = undefined,
        mutateValues = undefined,
        migrate = (s: any, v: number) => Promise.resolve(s),
        stateReconciler = (s: any, o: any, r: any, c: any) => s,
    } = persistOptions || {};
    const prefix = `persist:${key}`;
    const reduxPersistKey = `redux-persist`;
    const migrateReduxPersistKey = mutateKeysLayer(
        (key) => (key === `${prefix}.${reduxPersistKey}` ? prefix : key),
        (key) => (key === prefix ? `${prefix}.${reduxPersistKey}` : key),
    );
    const internalMutateKeys = [migrateReduxPersistKey, prefixLayer(prefix)];
    if (whitelist) {
        internalMutateKeys.push(filterKeys((key) => whitelist.includes(key)));
    }
    if (blacklist) {
        internalMutateKeys.push(filterKeys((key) => !blacklist.includes(key)));
    }

    const customMutateKeys = mutateKeys ? internalMutateKeys.concat(mutateKeys) : internalMutateKeys;

    const cache: ICache = new Cache({
        disablePersist,
        prefix: null,
        mutateKeys: customMutateKeys,
        mutateValues,
        initialState: preloadedState,
        mergeState: async (originalRestoredState = {}, initialState = {}) => {