You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a redux store that exists briefly and sometimes it can be disposed of while a long running middleware server call is in flight. If I try to dispatch another action to set store state following that async call, there's an exception thrown because the store's change stream has been closed. To prevent those exceptions caused by calling dispatch on a torn-down store, it would be nice to be able to ask the store if it's still open to change.
Right now I have the following extension for this, but it requires getting tricky with the onChange stream.
extensionStoreSafeAsyncDispatchonStore {
/// if a store is closed it can not dispatch actions or apply changesFuture<bool> get isClosed async {
var closed =false;
await onChange.listen((_) {}, onDone: () => closed =true).cancel();
return closed;
}
/// only dispatch if the store is not closedFuture<dynamic> asyncDispatch(dynamic action) async {
if (await isClosed) return;
returndispatch(action);
}
}
Thanks for your time and consideration!
The text was updated successfully, but these errors were encountered:
But when do you close the state? Where do you do store.teardown();? Also I don't think we should ever call this, because we need the Store as long as pe app is alive.
Docs say:
Closes down the Store so it will no longer be operational. Only use this
if you want to destroy the Store while your app is running. Do not use
this method as a way to stop listening to [onChange] state changes. For
that purpose, view the [onChange] documentation.
HI 👋 Redux Team,
I've got a redux store that exists briefly and sometimes it can be disposed of while a long running middleware server call is in flight. If I try to dispatch another action to set store state following that async call, there's an exception thrown because the store's change stream has been closed. To prevent those exceptions caused by calling dispatch on a torn-down store, it would be nice to be able to ask the store if it's still open to change.
Right now I have the following extension for this, but it requires getting tricky with the onChange stream.
Thanks for your time and consideration!
The text was updated successfully, but these errors were encountered: