optimizely / nuclear-js

Reactive Flux built with ImmutableJS data structures. Framework agnostic.
https://optimizely.github.io/nuclear-js/
MIT License
2.23k stars 141 forks source link

Syncing NuclearJS state with React Router Query Params #166

Open mindjuice opened 9 years ago

mindjuice commented 9 years ago

Has anyone done any work to sync NuclearJS state to React Router query parameters?

I currently do router.transitionTo() with the new URL query params whenever an action changes some state that is associated with a query param. The way I currently did it though, I need to put all my related state in the same module, which is not great (pretty sure I can fix this though).

Going the other way, when the URL changes for any reason (e.g., user presses Back, or types in a new URL) I hook off of React Router's willTransitionTo() and fire an action to update the state from the current URL parameters. I have a check in there to avoid making any changes if the URL parameters match the current state so I don't get an infinite cycle of changes.

Has anyone done any work to use this sort of pattern (or similar) in a cleaner way?