gabceb / redux-persist-transform-expire

Add expiration to your persisted store
MIT License
64 stars 19 forks source link

Default state at per reducer level #6

Open skyshader opened 7 years ago

skyshader commented 7 years ago

The example shows how to provide default value at the time of creating an instance:

const expireTransform = createExpirationTransform({
  expireKey: 'customExpiresAt',
  defaultState: {
    custom: 'values'
  }
});

persistStore(store, {
  transforms: [expireTransform]
});

Can I configure somehow the defaultState to be defined at reducer level?

gabceb commented 7 years ago

You can do this today by making sure your reducer alwags returns an expiration key on its root. If you want config level settings yo can put a PR together where a reducer name is passed along with a key and an expiration which is injected on the inbound function

iou90 commented 7 years ago

https://github.com/iou90/redux-persist-transform-expire try this.

skyshader commented 7 years ago

@iou90 Still all the config remains at one place, ie., at the time of creating an instance. I was wondering if the expiration triggers REHYDRATE in the affected reducers. If it does, I can set up the default state there itself. If not then this seems like a good solution.