Automerge storage provider for redux-persist

Storage adaptor to use Automerge with redux-persist or Apollo Client, by implementing the needed methods: setItem, getItem, removeItem and getAllKeys.

This wraps another storage provider with the same API.

Install

yarn add redux-persist-automerge

or

npm install --save redux-persist-automerge

Usage with Apollo Client

This has been tested with Apollo Client 2.5.

import { AutomergeStorage } from 'redux-persist-node-storage'

async function start() {
  const cache = new InMemoryCache()

  const docSet = automerge.init()

  // storage can be any provider on this list https://github.com/rt2zz/redux-persist#storage-engines
  const storage = new AutomergeStorage(docSet, window.localStorage)

  // Wire up the in-memory cache to persistent storage
  await persistCache({ cache, storage })

  const client = new ApolloClient({ cache, resolvers, typeDefs })
}

start()

Usage with redux-persist

import { AutomergeStorage } from 'redux-persist-node-storage'
import { persistStore, autoRehydrate } from 'redux-persist'
const store = createStore(reducer, undefined, autoRehydrate())

persistStore(store, { storage: new AutomergeStorage('/tmp/storageDir') })