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.
yarn add redux-persist-automerge
or
npm install --save redux-persist-automerge
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()
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') })