lazy load certain state #107

Closed
opened 2016-03-04 00:13:40 +00:00 by pke · 2 comments
pke commented 2016-03-04 00:13:40 +00:00 (Migrated from github.com)

I have some arrays in my state that I don't need at app start right away. I'd rather load them when I first need to display them. Does redux-storage support that?

I have some arrays in my state that I don't need at app start right away. I'd rather load them when I first need to display them. Does redux-storage support that?
michaelcontento commented 2016-03-04 08:35:16 +00:00 (Migrated from github.com)

Yes, this is possible although there is no official support for splitting the state. Just have a look at this example gist.

The current solution is quite simple but also rather cumbersome if you want to split the state even further. I haven't thought about this problem for very long but maybe a special engine-decorator could be a better (and reusable) solution? Maybe a API that looks something like this:

const primaryEngine = /* create your primary engine as usual */
const primaryEngineFiltered = splitStateDecorator(primaryEngine,
    // name: a simple name to referr to
    // paths: everything this split should include
    //        NOTE: this is added to the primaryEngine blacklist!
    // engine: where to save this split
    { name: 'expensive', paths: ['numbers'], engine: secondaryEngine },
    { name: 'archive', paths: ['archive', 'user.backup'], engine: archiveEngine }
);

// Load some parts
primaryEngineFiltered.load('archive', store);

// Or everthing at all
primaryEngineFiltered.loadAll(store);

Does this answer your question? If so, please close this issue or keep on asking 😃

Yes, this is possible although there is no official support for splitting the state. Just have a look [at this example gist](https://gist.github.com/michaelcontento/fa1cde84e982efe7b7e7). The current solution is quite simple but also rather cumbersome if you want to split the state even further. I haven't thought about this problem for very long but maybe a special engine-decorator could be a better (and reusable) solution? Maybe a API that looks something like this: ``` js const primaryEngine = /* create your primary engine as usual */ const primaryEngineFiltered = splitStateDecorator(primaryEngine, // name: a simple name to referr to // paths: everything this split should include // NOTE: this is added to the primaryEngine blacklist! // engine: where to save this split { name: 'expensive', paths: ['numbers'], engine: secondaryEngine }, { name: 'archive', paths: ['archive', 'user.backup'], engine: archiveEngine } ); // Load some parts primaryEngineFiltered.load('archive', store); // Or everthing at all primaryEngineFiltered.loadAll(store); ``` Does this answer your question? If so, please close this issue or keep on asking :smiley:
pke commented 2016-03-08 00:42:29 +00:00 (Migrated from github.com)

I will try this out. If I have more questions I will open this again. Thanks!

I will try this out. If I have more questions I will open this again. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MichaelContento/redux-storage#107
No description provided.