Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an Immutable store #78

Closed
okjulian opened this issue May 17, 2017 · 3 comments
Closed

Use an Immutable store #78

okjulian opened this issue May 17, 2017 · 3 comments

Comments

@okjulian
Copy link

It would be great if this library could work with Immutable.js stores, and I think it's a good idea to start talking about it in this issue.

I'm already using this library with an Immutable store and opened PR #54, but it only works with redux-offline v1.

To accept an Immutable store using my approach you only needed to set config.immutable = true. To achieve this, the only thing I needed was to teach redux-offline how to persist and rehydrate Immutable object. Luckily redux-persist-immutable makes this super easy, so I added it as a dependency.

Implementing this was straightforward: The key parts were using a different persistStore and autoRehydrate in index.js, and converting the user's state to javascript in middleware.js so that redux-offline internals can still work with plain JS objects.

Please let me know of better ways to tackle this problem. Supporting Immutable stores would be great!

@Jimmy-CC
Copy link

Jimmy-CC commented Jun 2, 2017

If you only want to use Immutable object in the redux offline, passing transforms to persistOptions is a good enough solution.

But it will be great if we can detect to use Immutable transit by passing options and works with immutable store.

import immutableTransform from 'redux-persist-transform-immutable'
import offlineConfig from 'redux-offline/lib/defaults'

const store = createStore(
  combineReducers(reducers),
  {},
  compose(
    applyMiddleware(middleware),
    offline({
      ...offlineConfig,
      persistOptions: {
        transforms: [immutableTransform()],
      },
    })
  )
)

@fabriziomoscon
Copy link
Contributor

I created a PR #99 for this very same issue

@sorodrigo
Copy link
Member

PR is now merged in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants