-
Notifications
You must be signed in to change notification settings - Fork 16
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
Drawbacks of when
#190
Comments
Hi @noamr, this makes total sense. I would also add the ability to set up the listener in two steps, as follows: // step 1:
const stream = new ObservableEventListener()
.filter(conditions)
.map(stuff)
;
// step 2:
eventTarget.when('click', stream, { capture: true });
// step 3:
stream.subscribe(sink); This way frameworks and UI libraries could take care of and abstract away steps 2 and 3, leaving applications able to define the whole stream and its logic as step 1 in a component, before mounting (problem also surfaced in #186). Additionally, in this form, the same stream could be reused and attached to multiple sources? |
Perhaps That could also be paired with a convenient |
This still has the same issues as when, as described in the OP, albeit with a cleaner choice of name. |
Maybe, but I would still avoid adding new functions to observableListener.listen(target, event, options) |
Even if the only benefit was "avoid needing to use |
So adding a property with a short common name to almost all DOM classes out there, including the global object, some of which might be overriding it somehow today (eg custom elements), and making the resulting class less extendable as a result is better than typing |
Note that I don't think that's the only benefit of But yes, because |
For users of
This is an exaggeration. |
That ambiguity will be resolved, like with It's not an exaggeration, although it is perhaps subjective. |
More important than avoiding As for the discussion about |
Thanks for the discussion, happy to close this. I realized that this was a surface-level comment while something entirely different was bothering me here, I'll think it over and see if a meaningful discussion point comes up. |
Busy weekend here apparently! Thanks for the discussion everyone. A few closing thoughts below, but nothing substantive to add:
I'm pretty sympathetic to this, and the related:
I feel the current design is the simplest, and regarding name choice, well, I would just point to the previous discussion where authors, framework folks, and others felt that landing on On the other hand, I do feel like there's some merit to:
On the surface, our current proposal does feel out of step with how other
I guess the difference is that the other
So maybe the analogy between |
Choosing
EventTarget.when
as the way to tie observables to event targets feels more modern than some other DOM APIs, however, I think it has some drawbacks, as opposed to a more conservative alternative, perhapsnew ObservableEventListener({target, event, ...})
or some such.The main drawback is that in order to extend
ObservableEventListener
, or change its semantics (e.g. the whole ref-counting hot/cold thing),when
is going to require more options. The same if we ever extend the genericObserver
constructor with more options.On a more minor note, the
when
word doesn't fit grammatically with how it's used. It's more of anon
.button.when("click", { capture: true})
doesn't sound correct. I get that there were many discussions about this in the past andon
would have backwards-compat issues.Perhaps
new ObservableEventListener({ target: button, event: "click", capture: true })
is both extendable, discoverable, and consistent with how you construct existing similar platform primitives? (e.g.PerformanceObserver
,ResizeObserver
,IntersectionObserver
).Looking at https://wicg.github.io/observable/#dom-eventtarget-when, there's nothing to it except for constructing something and returning it, so perhaps that's how it should look like to the outside world?
Disclaimer: I wasn't here in past conversations so it's possible I'm missing something major.
@domfarolino we've discussed this offline, but wanted to have this documented here :)
The text was updated successfully, but these errors were encountered: