Observables are a popular reactive-programming paradigm to handle an asynchronous stream of push-based events. They can be thought of as Promises but for multiple events, and aim to do what Promises did for callbacks/nesting. That is, they allow ergonomic event handling by providing an Observable object that represents the asynchronous flow of events. You can "subscribe" to this object to receive events as they come in, and call any of its operators/combinators to declaratively describe the flow of transformations through which events go. This is in contrast with the imperative version, which often requires complicated nesting with things like `addEventListener()`. For more on this, see the examples in the explainer. The big selling point for native Observables is their integration with EventTarget — its proposed `when()` method that returns an Observable which is a "better" `addEventListener()`. See https://github.com/WICG/observable and https://twitter.com/domfarolino/status/1684921351004430336. See the spec https://wicg.github.io/observable/ and the design doc: https://docs.google.com/document/d/1NEobxgiQO-fTSocxJBqcOOOVZRmXcTFg9Iqrhebb7bg/edit.
Initially we proposed adding the `.on()` method to EventTarget, which was found to conflict with userland versions of the same method. The conflict was found to be too significant to justify shipping our native version of this API (see https://github.com/WICG/observable/issues/39) so we renamed it to `.when()` and we strongly believe this resolves any naming collision issues after searching through public libraries and performing developer outreach on X. See the discussion on that issue.
Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?
None
The developer experience of Observables might benefit from Observable-specific DevTools tracking of events and streams (see https://github.com/WICG/observable/issues/55). It is possible that the existing DevTools work that assists asynchronous task tracking and callstack tagging may be sufficient though. At the moment, however, our effort is focused on the platform implementation of Observables.
See https://wpt.fyi/results/dom/observable/tentative.
Shipping on desktop | 135 |
Open questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).
Issues with the "possible future enhancement" label [1] track possible changes to the feature that may come after we ship the initial API. One issue (https://github.com/WICG/observable/issues/200) is identified to have behavior changes that theoretically pose a compat risk, but only for developers that subclass the API. The behavior change proposed puts the implementation more inline with what subclass users want: the operators that return native Observable objects would instead return objects of `this.constructor` type, as to return instances of the subclass that the operators are called on. This is how JS built-ins like `Array` work, however, no other web platform feature works like this and it likely requires non-trivial Web IDL support. [1]: https://github.com/WICG/observable/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22possible%20future%20enhancement%22Link to entry on the Chrome Platform Status
https://chromestatus.com/feature/5154593776599040?gate=5141110901178368Links to previous Intent discussions
Intent to Prototype: https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAP-uykBH1%3DUoLN6%3DBRSEZE%2B1iUq6UdcTpo3qtTQ5T%3DSRxwnu5Q%40mail.gmail.com
This intent message was generated by Chrome Platform Status.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/67b8ef25.2b0a0220.38f609.0192.GAE%40google.com.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
https://codepen.io/jaffathecake/pen/raNWMmK?editors=0012 - it seems inconsistent that two of the calls to ob.map create a new subscriber, whereas the other picks up the observable half way through.
I guess the rule is: A new subscriber is created if the observer has closed, but isn't this really inconsistent?
How do you imagine developers adopting this before support is ubiquitous? Is there a "standard" polyfill developers are expected to use? Some feature-detection based patterns? Something else?
https://codepen.io/jaffathecake/pen/raNWMmK?editors=0012 - it seems inconsistent that two of the calls to ob.map create a new subscriber, whereas the other picks up the observable half way through.Right, the idea that a subscription doesn't have side effects if an existing subscription is in-flight was essentially the outcome of https://github.com/WICG/observable/issues/170 & https://github.com/WICG/observable/issues/178. The alternative, where producer:consumer are 1:1, made it easy to write performance foot-guns where what you actually want is to tap into an existing stream of values without paying the cost of setting it up each time if it already exists. Many userland Observables inevitably get `share()` slapped on them somewhere in the chain to alleviate this, but the inconsistency made it hard to judge whether your subscription would have side-effects or not. We also saw a lot of Observable learning material was taking pains to caveat right away, this unintuitive idea that the Observable type itself doesn't represent anything but a stateless subscription vendor. Now it basically represents the producer, and I think that matches peoples' mental models.I guess the rule is: A new subscriber is created if the observer has closed, but isn't this really inconsistent?I think it is consistent though, no? It's true that it's neither "only one call to the subscriber" nor "each call to the initial observable initiates a new subscription". But it is similar to what you wrote above: a subscriber is invoked/spun up if its subscription is closed (not observer). The pay-off is that you know you're never going to have "extra" side effects when subscribing. At most you will spin up a single producer (which you're OK with since you're subscribing), and at best you will listen in on an existing one.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAJ5xic-3d9ziBOmqHYiSGPxLmDzhu19vfbQHffqJSkprFcE%2Btg%40mail.gmail.com.
WebKit: Positive (https://github.com/WebKit/standards-positions/issues/292)
We've gotten good design feedback from TC39 members on many issues which we have implemented accordingly.
With the example in the codepen, as the holder of the observable, I don't think I have a way of knowing if I'm getting the start, or something in the middle. Isn't that a bit odd?
If it's ok to miss the start, why isn't it ok to miss the end?
LGTM3