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

No action.key on REHYDRATE #71

Closed
jwindridge opened this issue Apr 2, 2016 · 2 comments
Closed

No action.key on REHYDRATE #71

jwindridge opened this issue Apr 2, 2016 · 2 comments

Comments

@jwindridge
Copy link

As per the "Custom Rehydration" section in recipies.md, I implemented a case REHYDRATE statement in my reducer.

case REHYDRATE:
    const { key } = action  // key = undefined !!!
    if (key === 'newAppointmentForm') { // key === 'forms.newAppointmentForm' ?
      const startedMoment = moment(action.payload.startedMoment)
      return Object.assign({}, state, { startedMoment })
    }

However, when the action fires during the rehydration process, the action has no key attribute attached.

My alternate method (which seems to work) is to simply pull out the relevant part of the state tree from action.payload, and implement my custom rehydration logic there:

case REHYDRATE:
  const startedMoment = moment(action.payload.forms.newAppointmentForm.startedMoment)
  return Object.assign({}, state, { startedMoment })

Could you confirm that this is the "new" way of doing things, and that the docs are just out-of-sync with the API?

Thanks!

@rt2zz
Copy link
Owner

rt2zz commented Apr 2, 2016

Ah those recipes were out of date, I just updated them.

Your alternate method is perfect, but one note is you might want to be careful to make sure the keys are defined i.e.

if (action.payload.forms && action.payload.forms.newAppointmentForm) {
  const startedMoment = moment(action.payload.forms.newAppointmentForm.startedMoment)
}

@jwindridge
Copy link
Author

Very true, well spotted!

Thanks for getting back to me, docs look fine now. Love the library!

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

2 participants