Comments (2)
keep in mind this code was from before I noticed the initialize method but: I have a list of key state parameters that I serialize to the session state object in the browser and/or pull from an API:
middleware: [
(context) => { // save select values into session
console.log('context state = ', context.state);
if (sessionStorage && context.state) {
if (!context.state.backgrounds) {
console.log('no backgrounds');
}
for (let def of LOAD_STATES) {
if (!def.loadFromAPI) {
putInSession(def.name, context.state[def.name] || null, def.type);
}
}
}
return context;
} ,
(context) => { // load values from API
for (let def of LOAD_STATES) {
if (def.loadFromAPI && (!def.loadStart)) {
def.loadStart = true;
axios.get(`${config.API_ROOT}choices/${def.name}`)
.then((result) => {
let value = result.data;
context.effects.fromAPI(def.name, value);
def.loadDone = true;
});
}
//putInSession(def.name, context.state[def.name] || null, def.type);
}
return context;
}
]
from freactal.
initialState
would definitely be a natural place to do this. The docs call out SSR scenarios as the prime example, but it is really intended for any case where you need to set state when the stateful component is originally loaded. In the case of an app-wrapper, it would make sense to pull in saved state there.
hydrate
does some special work to match server-rendered components with their locally-rendered stateful counterparts. You shouldn't need to use it here.
Sorry for very delayed reply, but hope you were able to work things out. Going to close this as resolved, but please do feel free to re-open if you'd like additional help.
from freactal.
Related Issues (20)
- state and effects
- middleware not executing in Jest
- Calculated states giving me the blues HOT 1
- A State Factory for Freactal
- Freactal doesn't work well with recursive state provider components. HOT 13
- A "Freactal Manager" module: Freactal Seed HOT 3
- effects.initialize executed version is unpatched through middleware.
- Putting up a Starter Kit with Freactal
- effects can't access parent scope
- Jumping cursor with controlled input HOT 1
- Looking for a new maintainer! HOT 15
- An alternative: looking glass engine
- Type codebase with flow HOT 3
- Any intention to support decorators? HOT 6
- effects with async/await functions HOT 4
- Published package (v2.0.0) is out of sync with the actual code? HOT 15
- (Re-)Publish Freactal intro on Hacker Noon? HOT 3
- Injecting new state asynchronously HOT 6
- middleware
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freactal.