Define engine key at load() time rather than createEngine()? #140
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MichaelContento/redux-storage#140
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm running into a situation where I need to define the engine's save key after creating the redux store. I have a web app which serves different content for different 'shortcodes', i.e.
example.com/<shortcode>, and I'm persisting only shortcode-specific state slices via redux-storage. In order to prevent different shortcodes' persistent state from conflicting, I'd like to use a different engine key for each shortcode.For example, if I have
/shortcodeAand/shortcodeB, and each shortcode has its own uniquestate.widgetsslice, I want to be able to load & save shortcodeA'sstate.widgetsusing an engine key'shortcodeA'so it doesn't conflict with shortcodeB's state under a'shortcodeB'engine key.Is this something that could be supported by redux-storage? Maybe the API could look something like
I'm going to play around with a few options and make a PR; anyone have any thoughts on how this should work?
redux-storageis heavily built towardsreduxand it's sematics / behaviour. So how do you switch thereduxbetween thoseshortcodes? Is there a default case (e.g. no data loaded) and how is it handled? Or let me go through this in a few steps:shortcodedata for the given page, right?So why can't you use the right
shortcodewhile creating the initialredux-storageengine?My original reasoning for this change was that, while I can easily access the shortcode via
window.locationwhen constructing the store, I wanted to read URL params only via react-router (to be consistent about how I read URL params). My original rootrendercall rendered something like this:However I realized that I don't actually need to construct the store up front; I can instead just create it in a component once react-router determines the shortcode. So now I have this:
AppContainerconstructs the store incomponentWillMount(with access toshortcodeto use as the engine key), then callsthis.setState({ store, loadStorage })and rendersLong story short: I no longer need to define the engine key at
load()time, so I think this can be closed 😄