admin管理员组文章数量:1287526
Hi in our app we have a reducer pattern:
{
data: //here we have our actual data
fetching: // is it still fetching
intact: // has it been 'touched'
error: //errors if need be
}
furthermore due to business demand I need to persist a ReduxForm which is its own can of worms...
form: {
Foobar: {
values: {
},
initial: {
},
syncErrors: {
},
registeredFields: {
}
}
}
}
it is as you may have figured out is pointless to persist anything but data, but Redux-Persist persists the entire reducer. The examples on filtering and transformation is a bit... lackluster in my feel and I have been strugling to implement. Looking for an example
Hi in our app we have a reducer pattern:
{
data: //here we have our actual data
fetching: // is it still fetching
intact: // has it been 'touched'
error: //errors if need be
}
furthermore due to business demand I need to persist a ReduxForm which is its own can of worms...
form: {
Foobar: {
values: {
},
initial: {
},
syncErrors: {
},
registeredFields: {
}
}
}
}
it is as you may have figured out is pointless to persist anything but data, but Redux-Persist persists the entire reducer. The examples on filtering and transformation is a bit... lackluster in my feel and I have been strugling to implement. Looking for an example
Share Improve this question edited Sep 4, 2018 at 7:42 Tackgnol asked Sep 4, 2018 at 7:31 TackgnolTackgnol 5051 gold badge10 silver badges17 bronze badges2 Answers
Reset to default 10Ok so this works using redux-persist-transform-filter like @NickHTTPS sugested:
import createFilter from 'redux-persist-transform-filter';
const saveSubsetFilter = createFilter('form', ['Foo.bar']);
const persistConfig = {
key: 'form',
storage,
whitelist: ['form'],
transforms: [saveSubsetFilter]
};
persistCombineReducers(persistConfig, { form: formReducer });
works like a charm :)
It's possible to whitelist/blacklist keys in redux-persist:
import { createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
const persistConfig = {
key: 'form',
storage: storage,
whitelist: ['Foobar'] // only Foobar will be persisted
};
const persistedReducer = persistReducer(persistConfig, rootReducer)
export default () => {
let store = createStore(persistedReducer)
let persistor = persistStore(store)
return { store, persistor }
}
Unfortunately whitelist/blacklist only accepts 1 level deep so I think you need to use something like this: https://github./edy/redux-persist-transform-filter or rework your data structure in a way that you can bypass the 1 level deep limitation of the library.
Hope it helps!
本文标签: javascriptPersisting only some fields from the ReducerStack Overflow
版权声明:本文标题:javascript - Persisting only some fields from the Reducer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741311315a2371664.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论