-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
🚀 Handle Outputs more reactively #40872
Comments
Hey, Maybe extending So we would have |
@criskrzysiu Your suggestion definitely works, however, it couples the component's logic (TS) to its presentation (HTML) which is usually to be avoided. It's also error-prone, just as you wrote some examples. Extending those decorators won't make it less coupled. |
Another question: what happens in this case below? If the source is an <button (click.next)="output$">Click me</button> |
Another thing. Angular builds heavily on streams. Currently, both Angular-oriented things (HTTP, Forms, etc.) and downward data flow (parent -> children) can be done properly with streams. However, the upward direction is not that stream-friendly. If one wants proper stream-based event flow upwards, then they shall use NgRx or something similar. NgRx is kinda complicated and it does not fit to every use-case. So in "vanilla Angular" we lack the convenient tools to create fully stream-oriented applications, despite the fact that Angular APIs are heavily stream-oriented. I find this somewhat discrepant. |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
I'm going to close this as a conceptual twin of #5689. As @mgechev summarizes there, we are interested in exploring ways to increase the ergonomics of using Angular in a reactive context, without introducing additional required RxJS to |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🚀 Handle Outputs more reactively
Relevant Package
This feature request is for @angular/core.
Description
Currently, dealing with an
@Output
of a component is quite imperative from the parent component's side. I'd like to have a more reactive, stream-oriented approach.The issue is originally described here, I summarize it below.
We have a parent component (template and TS below). A child component emits an
output
event, which we want to process as a stream. Now we can do this the following way:What happens here:
output
as anEventEmitter
(or some other Observable, because we love to live dangerously).output
inonOutput
(imperative)output$
and fire it inonOutput
output$
inonNgDestroy
Practically we walk a few extra lines just to make a stream out of another stream. This could be done much better.
Describe the solution you'd like
Eliminate the overhead as much as possible: stream-callback-stream to be simplified.
I'm not quite sure of the exact implementation though. But I have a wild guess. Please be gentle on me. 😄
LVL 1
Handle events from components via
(eventname.next)="subject"
, where thesubject
must be an RxSubject
/BehaviorSubject
. This will pipe the next stream to the target subject. We may handleerror
andcomplete
streams similarly, perhaps all 3 with the(eventname.subscribe)
syntax.LVL 2
I think there could be a way to eliminate the manual creation and completion of the
output$
stream. Something like this:Here we have 3 extra things with
@ComponentStream
(provided by Angular):output$
is auto-instantiated as aSubject
/EventEmitter
. (When??)output$
is auto-completed duringngOnDestroy
.Subject
s are not accepted officially.)And ✨ a metric ton of boilerplate disappeared. Or at least a few lines and quite a few bug-spawners. Furthermore, it would be an awesome new reactive tool in our toolbox.
Describe alternatives you've considered
There are a few workarounds at the original StackOverflow issue for LVL 1:
<child-component (output)="output$.next($event)">
next
shouldn't be the responsibility of the template.@ViewChild
or its friends to access the child component directly (from @criskrzysiu)Workarounds for LVL 2:
The text was updated successfully, but these errors were encountered: