fluttercommunity / redux.dart

Redux for Dart
https://pub.dev/packages/redux
MIT License
515 stars 61 forks source link

async middleware and reducers - start, success, fail - doesn't seem to achieve its purpose #84

Closed leobastin closed 11 months ago

leobastin commented 1 year ago

After we start a fetch action: store.dispatch(FetchCustomerStartAction()); We expect the reducer for this action to kickstart immediately to change inProgress to true, while middleware is awaiting response from server. However, the middleware pattern will not pass control to the reducer (next(Action)) until server call returns in the middleware (await completes). This means the transition of state.inProgress is not useful. (Apologies if its because I've gotten it all wired wrongly)

brianegan commented 1 year ago

If you're using an async function, you need to call next(Action) before you await any futures.

muhammadmateen027 commented 1 year ago

If you are using redux_epics with flutter_redux, I can provide you an example to handle such scenarios.

With only flutter_redux, I didn't try.