How to use @wora/cache-persist - 10 common examples

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 / relay-offline / src / EnvironmentIDB.ts View on Github external
recordSourceOptions: CacheOptions = {},
        storeOptions: {
            persistOptions?: CacheOptionsStore;
            gcScheduler?: Scheduler;
            operationLoader?: OperationLoader;
            getDataID?: any; // do not use
        } = {},
        offlineStoreOptions: CacheOptions = {},
    ): RelayModernEnvironment {
        let idbStore: CacheOptions;
        let idbRecords: CacheOptions;
        let idbOffline: CacheOptions;
        const { gcScheduler, operationLoader, getDataID, persistOptions } = storeOptions;
        if (typeof window !== 'undefined') {
            const { name = 'relay', onUpgrade, version } = idbOptions;
            const idbStorages: ICacheStorage[] = IDBStorage.create({
                name,
                storeNames: ['store', 'records', 'offline'],
                onUpgrade,
                version,
            });

            idbStore = {
                storage: idbStorages[0],
                serialize: false,
                prefix: null,
                ...persistOptions,
            };

            idbRecords = {
                storage: idbStorages[1],
                serialize: false,
github morrys / wora / packages / redux / src / createStore.ts View on Github external
let promiseRestore;
    const {
        disablePersist = !persistOptions,
        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,
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 = {}) => {
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
console.log(idbStorages);

const CacheLocalIDBNO = new Cache({
    prefix: null,
    serialize: false,
    storage: idbStorageNo[0],
});

const CacheLocalIDB = new Cache({
    layers: [filterNoPersistReplace],
    serialize: false,
    storage: idbStorages[0],
});


const CacheLocalIDB2 = new Cache({
    layers: [filterPersistReplace],
    serialize: false,
    storage: idbStorages[1],
});

const CacheLocalDisable = new Cache({
    disablePersist: true
});


const App = () => {
    return
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
const StyledApp = styled.div`
    display: flex;
    justify-content: center;
    flex-direction: column-reverse;
`;

const filterPersistReplace: ILayer = filterKeys(key => key.includes("replace"));

const filterNoPersistReplace: ILayer = filterKeys(key => !key.includes("replace"));

const CacheLocal = new Cache({
    layers: [filterNoPersistReplace],
});

const CacheLocalNew = new Cache({
    errorHandling: (error) => { 
        console.log("error", error);
        return true;
    },
    layers: [filterPersistReplace],
    prefix: 'cachenew',
});

const CacheSessionNew = new Cache({
    prefix: 'cachenew',
    webStorage: 'session'
});

const idbStorages: CacheStorage[] = IDBStorage.create( {
    name: "cache",
    onUpgrade: (db, oldv, newv, transaction) => {
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
const filterNoPersistReplace: ILayer = filterKeys(key => !key.includes("replace"));

const CacheLocal = new Cache({
    layers: [filterNoPersistReplace],
});

const CacheLocalNew = new Cache({
    errorHandling: (error) => { 
        console.log("error", error);
        return true;
    },
    layers: [filterPersistReplace],
    prefix: 'cachenew',
});

const CacheSessionNew = new Cache({
    prefix: 'cachenew',
    webStorage: 'session'
});

const idbStorages: CacheStorage[] = IDBStorage.create( {
    name: "cache",
    onUpgrade: (db, oldv, newv, transaction) => { 
        console.log("onUpgrade", db, oldv, newv, transaction);
    }, 
    storeNames: ["persist", "persist2"],
    version: 1,
    
});

const idbStorageNo: CacheStorage[] = IDBStorage.create( {
    name: "nocache",
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
-moz-osx-font-smoothing: grayscale;
    font-weight: 300;
  }
  `

const StyledApp = styled.div`
    display: flex;
    justify-content: center;
    flex-direction: column-reverse;
`;

const filterPersistReplace: ILayer = filterKeys(key => key.includes("replace"));

const filterNoPersistReplace: ILayer = filterKeys(key => !key.includes("replace"));

const CacheLocal = new Cache({
    layers: [filterNoPersistReplace],
});

const CacheLocalNew = new Cache({
    errorHandling: (error) => { 
        console.log("error", error);
        return true;
    },
    layers: [filterPersistReplace],
    prefix: 'cachenew',
});

const CacheSessionNew = new Cache({
    prefix: 'cachenew',
    webStorage: 'session'
});
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
storeNames: ["persist"],
    version: 1,
    
});

console.log(idbStorages[0]);

console.log(idbStorages);

const CacheLocalIDBNO = new Cache({
    prefix: null,
    serialize: false,
    storage: idbStorageNo[0],
});

const CacheLocalIDB = new Cache({
    layers: [filterNoPersistReplace],
    serialize: false,
    storage: idbStorages[0],
});


const CacheLocalIDB2 = new Cache({
    layers: [filterPersistReplace],
    serialize: false,
    storage: idbStorages[1],
});

const CacheLocalDisable = new Cache({
    disablePersist: true
});
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
const CacheLocalNew = new Cache({
    errorHandling: (error) => { 
        console.log("error", error);
        return true;
    },
    layers: [filterPersistReplace],
    prefix: 'cachenew',
});

const CacheSessionNew = new Cache({
    prefix: 'cachenew',
    webStorage: 'session'
});

const idbStorages: CacheStorage[] = IDBStorage.create( {
    name: "cache",
    onUpgrade: (db, oldv, newv, transaction) => { 
        console.log("onUpgrade", db, oldv, newv, transaction);
    }, 
    storeNames: ["persist", "persist2"],
    version: 1,
    
});

const idbStorageNo: CacheStorage[] = IDBStorage.create( {
    name: "nocache",
    onUpgrade: (db, oldv, newv, transaction) => { 
        console.log("onUpgrade", db, oldv, newv, transaction);
    }, 
    storeNames: ["persist"],
    version: 1,
github morrys / wora / packages / cache-persist / examples / react-example / src / index.tsx View on Github external
const CacheSessionNew = new Cache({
    prefix: 'cachenew',
    webStorage: 'session'
});

const idbStorages: CacheStorage[] = IDBStorage.create( {
    name: "cache",
    onUpgrade: (db, oldv, newv, transaction) => { 
        console.log("onUpgrade", db, oldv, newv, transaction);
    }, 
    storeNames: ["persist", "persist2"],
    version: 1,
    
});

const idbStorageNo: CacheStorage[] = IDBStorage.create( {
    name: "nocache",
    onUpgrade: (db, oldv, newv, transaction) => { 
        console.log("onUpgrade", db, oldv, newv, transaction);
    }, 
    storeNames: ["persist"],
    version: 1,
    
});

console.log(idbStorages[0]);

console.log(idbStorages);

const CacheLocalIDBNO = new Cache({
    prefix: null,
    serialize: false,