rt2zz / redux-action-buffer

Buffer Redux Actions
MIT License
79 stars 6 forks source link

autoRehydrate #2

Closed jeroenbourgois closed 8 years ago

jeroenbourgois commented 8 years ago

When using the enhancer like in the docs, the creation of my store fails. However if I omit the autoRehydrate it seems to work. Is it an error in the docs or am I doing something wrong?

Here is my full 'configureStore' file:

'use strict'

import { AsyncStorage } from 'react-native'
import { createStore, compose, applyMiddleware } from 'redux'
import rootReducer from '../reducers'
import thunk from 'redux-thunk'

import {REHYDRATE} from 'redux-persist/constants'
import createActionBuffer from 'redux-action-buffer'

import {persistStore, autoRehydrate} from 'redux-persist'

const enhancer = compose(
  // autoRehydrate,
  applyMiddleware(
    thunk,
    createActionBuffer(REHYDRATE) //make sure to apply this after redux-thunk et al.
  )
)

export const store = createStore(
  rootReducer,
  {},
  enhancer
)

persistStore(store, {storage: AsyncStorage}, () => {
  console.log(">>> RESTORED")
})
rt2zz commented 8 years ago
  1. autoRehydrate is a factory function so your code should read:
const enhancer = compose(
  autoRehydrate(),
//...
  1. You will definitely want to call persistStore(store) otherwise you will not get any persistence :)

Let me know if that works! Also what is the error you were seeing? It would be cool if there is some way to detect autoRehydrate is being used in this way, e.g. we could possibly check if the arguments look like enhancer arguments and if so warn.

jeroenbourgois commented 8 years ago

Aha that was it! I blindly followed the docs, let me PR that!

I will keep an eye on the Immutablejs discussion, since I use it throughout my reducers and see that a plain js object is returned (what is the behaviour now, which is fine!)

rt2zz commented 8 years ago

if you are using immutable I would strongly consider using https://github.com/rt2zz/redux-persist-transform-immutable which uses transit to automatically handle immutable objects.

jeroenbourgois commented 8 years ago

I already did :) it is integrated + working