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
ReduxAction.reduceWithState not working #79
Comments
I was also using a lot of
But there is a difference for async reducers, returning
|
I should probably remove Can you create for me a runnable test, with minimum code, that demonstrates the problem you are having? (without using |
I'll try tomorrow. |
import 'package:async_redux/async_redux.dart';
import "package:test/test.dart";
class AppState {
final String name;
AppState(this.name);
AppState copyWith(final String name) => AppState(name);
}
class Action1 extends ReduxAction<AppState> {
@override
Future<AppState> reduce() async {
await dispatchFuture(Action2());
// Action2 wraps the thrown argument error in a UserException thus this reduce never fails.
// This may be intented but Action1 never knows what happened.
return AppState('Action1');
}
}
class Action2 extends ReduxAction<AppState> {
@override
Future<AppState> reduce() async {
await Future.delayed(const Duration(milliseconds: 100), () {
throw ArgumentError();
});
return AppState('Action2');
}
@override
Object wrapError(dynamic error) {
return const UserException('error');
}
}
void main() {
test('Action throws', () async {
final store = StoreTester(initialState: AppState('FOO'));
store.dispatchFuture(Action1());
final info = await store.waitUntilErrorGetLast(error: ArgumentError);
print(info);
expect(info.error, isNotNull);
expect(info.errors, hasLength(1));
expect(info.dispatchCount, 2);
expect(info.state.name, 'FOO');
});
} The error wrapping my also happen in the global |
Yes, Please get version: [2.12.1] (directly from GitHub), and try this: var action2 = Action2();
await dispatchFuture(action2);
if (!action2.hasFinished) throw UserExceptionError("Problems here."); I don't think this is a good solution, but at the moment I can't think of a good one. What do you think? |
I will try this but I am also not sure that it is a good idea. My main problem is the handling in the I just had the idea to create some custom BaseAction that has a bool Maybe this flag could also go into the Does this sound sane? Edit: Maybe the flag should be the other way around, like |
I can add the action to the global However, with the |
Yes I know about the I think it would help me a lot if the action is available in Something like this should work I guess: abstract class CustomReduxAction<St> extends ReduxAction<St> {
bool _isTopLevel = true;
bool get isTopLevel => _isTopLevel;
@override
DispatchFuture<St> get dispatchFuture {
return (ReduxAction<St> action, {bool notify}) {
if (action is CustomReduxAction<St>) {
action._isTopLevel = false;
}
return super.dispatchFuture(action, notify: notify);
};
}
@override
Dispatch<St> get dispatch {
return (ReduxAction<St> action, {bool notify}) {
if (action is CustomReduxAction<St>) {
action._isTopLevel = false;
}
return super.dispatch(action, notify: notify);
};
}
} Do you think this is something that makes sense to be added to the library? |
No, I don't really think it makes sense to add it to the library. I think that's too confusing to use, and nothing prevents the caller to call Please see version [2.12.2] (in GitHub, not pub.dev yet) for I'm going to close this issue, but feel free to come back here with other ideas, in case you find them. |
Sounds good, will try from master later. |
ReduxAction.reduceWithState
is not working as the_store
instance hasn't been set yet.It is also no longer mentioned in the docs so I am not sure if this is still intended to work.
I am currently working around the problem with a simple extension:
My main use case for using this is that I have an action
Action1
which dispatches other actions in their reducer like this:await dispatchFuture(Action2())
If
Action2
throws an exception which is wrapped in aUserException
thenAction1
does not get canceled.So instead I use
await Action2().reduceWith(store, state)
so that it throws but now I have to handle the wrapping of the exception also inAction1
.I am not sure what is the best way to tackle this.
The text was updated successfully, but these errors were encountered: