-
Notifications
You must be signed in to change notification settings - Fork 129
Add Observable API #2863
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
base: main
Are you sure you want to change the base?
Add Observable API #2863
Conversation
name: Observable | ||
description: TODO | ||
description: The `Observable` API provides a composable, ergonomic way of handling an asynchronous stream of events. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is directly from the spec, because I don't understand the API well enough to describe it myself.
@domfarolino how would you describe this to a web developer in more objective terms? In particular I think we shouldn't claim it's ergonomic here, that's up to developers to judge I think.
I'm thinking something like:
The
Observable
API allows you to subscribe to events in a new way. Thewhen()
method does something that is different thanaddEventListener()
.
Help? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention the when
method earlier in the description.
description: The `Observable` API provides a composable, ergonomic way of handling an asynchronous stream of events. | |
description: The `when()` method of an `EventTarget` object, such as a DOM element, returns an `Observable` API instance which allows to ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Developers telling us it was ergonomic1 is what led me to ship the API and write the spec, so I feel like that description isn't a declaration as much as it is a response. But something like:
An Observable is an object representing a stream of events that you can operate on declaratively, even before it emits any events. `EventTarget#when()` returns an Observable that you can immediately subscribe to and direct with native operators, providing an ergonomic, composable alternative to `addEventListener()`.
Maybe something like that?
Footnotes
-
In a way that Promise ergonomics compare to callbacks. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be OOO for a week so if anyone wants to make a decision and land this, that's totally OK and appreciated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, doing my best here to synthesize everyone's comments here. How about this?
description: The `Observable` API provides a composable, ergonomic way of handling an asynchronous stream of events. | |
description: The `when()` method on a event target returns an `Observable` object, which provides a declarative API for subscribing to and operating on events. It's an alternative to `addEventListener()` callbacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
No description provided.