Skip to content

v5 compat#17

Merged
rt2zz merged 2 commits intort2zz:masterfrom
Vydia:v5-compat
Dec 9, 2018
Merged

v5 compat#17
rt2zz merged 2 commits intort2zz:masterfrom
Vydia:v5-compat

Conversation

@TSMMark
Copy link
Copy Markdown
Contributor

@TSMMark TSMMark commented Dec 13, 2017

Not sure exactly what needs to be done to get a PR in here as there are no tests or guidelines but here is the crosstab persist I wrote for our app for v5. From conversation in #15 and rt2zz/redux-persist#569

I’m using it like this:

// @flow

import { applyMiddleware, createStore } from 'redux'
import { persistCombineReducers, persistStore } from 'redux-persist'
import { routerMiddleware, routerReducer } from 'react-router-redux'
import createHistory from 'history/createBrowserHistory'
import logger from 'redux-logger'
import persistCrosstab from './persistCrosstab'
import reducers from '../reducers'
import storage from 'redux-persist/es/storage'
import type { PersistConfig, Persistor } from 'redux-persist/es/types'
import type { Store } from 'redux'

export const history: History = createHistory()

const persistConfig: PersistConfig = {
  key: 'root',
  storage,
  whitelist: ['ui'], // Reducers to persist in localstorage.
}

const store: Store = createStore(
  persistCombineReducers(persistConfig, {
    ...reducers,
    router: routerReducer,
  }),
  applyMiddleware(logger, routerMiddleware(history))
)

export const persistor: Persistor = persistStore(store, undefined, () => {
  // `store.getState()` becomes available in this callback.
})

persistCrosstab(store, persistConfig, {
  whitelist: ['ui'], // Reducers to persist crosstab.
})

export default store

@rt2zz
Copy link
Copy Markdown
Owner

rt2zz commented Dec 13, 2017

This looks great. It seems to make this fully functional we will need to import the deserialize + transforms process from redux-persist. This is not currently exported but it could be.

@TSMMark
Copy link
Copy Markdown
Contributor Author

TSMMark commented Dec 15, 2017

@rt2zz If you merge rt2zz/redux-persist#620 and ship a release I can finish this up in no time

@TSMMark
Copy link
Copy Markdown
Contributor Author

TSMMark commented Jan 2, 2018

@rt2zz ?

@saeedezzati
Copy link
Copy Markdown

What's the status of this?

@TSMMark
Copy link
Copy Markdown
Contributor Author

TSMMark commented Jan 3, 2018

@markopol0 It's ready to go I'm just waiting on a maintainer for merges. @rt2zz I hope you're okay my dude!

@Cretezy
Copy link
Copy Markdown

Cretezy commented Jan 16, 2018

Can confirm this works. The README should be updated with the new usage:

crosstabSync(store, persistorConfig, crosstabConfig);

Another point to add would be that this only works with localStorage, and not others like localForage.

@avin
Copy link
Copy Markdown

avin commented Jan 17, 2018

Is it compatible with transformers like https://github.com/rt2zz/redux-persist-transform-immutable ?

I think it should be added

                if (blacklist && blacklist.indexOf(reducerKey) !== -1) {
                    return state;
                }

                state[reducerKey] = JSON.parse(statePartial[reducerKey]);

                //+++
                persistConfig.transforms && persistConfig.transforms.forEach(transform => {
                    state[reducerKey] = transform.out(state[reducerKey]);
                });

                return state;
            }, {});

@damianobarbati
Copy link
Copy Markdown

@TSMMark thanks for the effort! @rt2zz is this making it into master anytime soon? 🙏🏻

@jadennnn
Copy link
Copy Markdown

@rt2zz would be great to get redux-persist v5 support!

@TSMMark
Copy link
Copy Markdown
Contributor Author

TSMMark commented Apr 2, 2018

Can we get a merge please?

@johnnyoshika
Copy link
Copy Markdown

Agreed! Merge would be really nice. :-)

@mbalabash
Copy link
Copy Markdown

@rt2zz
Can we get a merge please?

@rt2zz rt2zz merged commit 3dde594 into rt2zz:master Dec 9, 2018
@rt2zz
Copy link
Copy Markdown
Owner

rt2zz commented Dec 9, 2018

Hi all, sorry for the slowness here, cutting a next release now. Please confirm if this is working for you if we get a couple of 👍 I will do a proper release

@rt2zz
Copy link
Copy Markdown
Owner

rt2zz commented Dec 9, 2018

4.0.0-0 out now under next tag
npm i --save redux-persist@next

@TSMMark TSMMark deleted the v5-compat branch December 10, 2018 14:08
@ignatiusreza
Copy link
Copy Markdown

was trying this out and got an error because of flow type.. i opened #21 to remove them, since we can't assume that end user will have flow type as part of their build process..

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

Successfully merging this pull request may close these issues.

10 participants