-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
feat(bloc)!: add support for strongly typed errors on Emitter.onEach
/Emitter.forEach
#4133
Comments
Emitter.onEach
/Emitter.forEach
Emitter.onEach
/Emitter.forEach
Hey @narcodico 👋 It seems a bit risky to do this because if I'm understanding correctly, this change could result in runtime type exceptions since bloc would be casting the object to type What would be the benefit of that as opposed to: await emit.onEach(
_repository.watchData(),
onData: (data) => add(DataChanged(data)),
onError: (failure, stackTrace) => add(DataFailed(failure as MyFailure, stackTrace)),
); The other issue is As a result, I don't think it's safe to do this because the underlying subscription mechanism operates on Let me know what you think and thanks again for taking the time to file this issue! 🙏 |
Hey @felangel 👋
The benefit would be that it would save the developer from manually having to do the cast. It's if the current
I completely agree with this, but at the same time, a developer opting out of the default
but is also aware of how the stream is being used.
This feature would be great for developers that want to take full control over error handling. I think the usage it's pretty much in the hands of the developer. And the great thing is that not specifying a custom error type would continue operating on |
Description
The
Emitter
methods are currently allowing for a standard error handling involving anObject
and aStackTrace
:Function(Object error, StackTrace stackTrace)
.There's no simple solution at the moment to strongly type your incoming error/exception/failure, in order to make use of
onError
with your custom type.Desired Solution
I would like to be able to use
onError
with my custom type, e.g.:or
Alternatives Considered
Handling/manipulating the error directly on the incoming stream or in the error handler, both adding too much overhead.
Additional Context
Ideally, the signature would look like
onEach<T, E extends Object>
.BREAKING CHANGE: due to signature change, this feature could result in breaking changes in certain situations, like when the data type is explicitly specified. To solve this, the developer would have to either remove the type and rely on type inference, pass
Object
for the second generic type, or move the type toonData
handler, e.g.:onData: (int i) => i
.The text was updated successfully, but these errors were encountered: