New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trigger action at begin of async main alias action #11
Comments
There's different approaches to this. // reducer
const initialState = {
userData: {},
isFetched: false,
};
function myReducer(state = initialState, action) {
switch (action.type) {
case FETCH_USER: {
// fall back to previous state on error
if (action.error) return {...state, isFetched: true});
return {...state, ...action.payload, isFetched: true};
}
default:
return state;
}
}
export default myReducer; Also check out the discussions redux-utilities/redux-promise#12 and redux-utilities/flux-standard-action#7. There's also https://github.com/pburtchaell/redux-promise-middleware, which does seem to trigger separate actions during loading, but I've never used that, nor tested it against electron-redux (but can't see why it wouldn't work). |
Looks like |
Thanks a lot. redux-promise-middleware looks interesting or "promsing", will give it a try later and report back here. About redux-promise@^0.6.0-alpha, is that the |
Ups, yes, it is the sequence branch. Will try that as well. |
It's actually in master. I wouldn't judge redux-promise by its activity, though. The Promise interface has been stable for a few years now, so there's not much reason for change. If you do end up playing with redux-promise-middleware, please let me know how it goes. Out of curiosity, what are you building? |
I just tried redux-promise@^0.6.0-alpha. It doesn't work (yet). On the main thread, the promise actions created with About what I am building, it is static site generator, to be used by non-technical folks, therefore all baked into electron and only a Prosemirror editor exposed to the user. But it is not usable yet ... |
No, that seems strange. I've added some debugging to the middleware in the redux-thunk ticket. If you run your electron app with P.S.: Substitute |
ok, here is what I get at the main process:
I guess, this explains it: validateAction is too picky! But would it work without Ups, just checked about FSA:
so, this sequence props are not FSA compliant, they should be in the meta property P.S.: I just read the discussions to make the sequence stuff part of FSA, which happened more than a year ago. Maybe better to give https://github.com/pburtchaell/redux-promise-middleware at try next, hoping it will just work out of the box ... |
Yeah, looks like That does obviously break FSA specs (which is slightly surprising), and hence validation doesn't pass. Let me know how you get along with |
after adding |
I've played around with
* this will rarely be the case, but is worth knowing |
ok, now I see what I did wrong, registered the middleware as |
It all works now perfectly with the promise middleware, thanks again, gonna close this. |
My aliased actions (main process) are async and need some time to fulfill. The state change occurs when the action has fulfilled, and I am fine with that of course, but I would also like to have an additional state change at the begin of such an async action (for progress indicators and disabling buttons while the main async action is executing). Right now I am just using an additional sync action for that. Does there exist a way to bake in such an additional action into the alias action ? That would reduce boilerplate code for this type of usage pattern.
The text was updated successfully, but these errors were encountered: