Open RoyalIcing opened 7 years ago
export const load = {
items: '/api/photos'
}
Note the current approach may be fine!
export const load = async (props, prevProps) => {
if (!prevProps) {
return { items: await fetch('/api/photos').then(res => res.json()) }
}
}
Random thoughts after seeing this awesome framework:
I do similar things in https://github.com/LinasMatkasse/planck-state/blob/master/src/index.js#L16
There you have async actions called epics.
Each epic take one updater for loading state, one for success, and one for failure. In the future, the state will have some epic keys for loading
and errors
that will be set by the framework.
We follow jsonapi.org standards for error checking, so it's baked into the library. The error checker could be configurable in the future to allow different standards.
Also, a service is given that is supposed to be a promise. But since it comes from the outside, you can easily mock the service as a Promise.resolve(mockData)
call.
Usage is as simple as calling normal action, and only the loading updater is exposed to the react component.
I did not yet solve some standard for initially loading something when constructing/mounting a new component, but that would mostly mean one extra updater function under a special key like loaders
.
I have no clue if this helps or just confuses, but I'd really love to help a state management lib like this get popular to bring our community forward a bit :-)
Rant over! GLHF!