-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
{{on}}
Modifier
#471
{{on}}
Modifier
#471
Conversation
@pzuraq something that should be clarified in the design is that the |
shouldnt this deprecate the |
We generally don’t introduce new features and deprecate old features in the same RFC, so we don’t bikeshed unnecessarily about the deprecation when its a somewhat orthogonal question. |
v0.8 of the This is convenient as it alleviated the need to use the bind or action helper, but I'm assuming this feature is intentionally absent from this PR? Does anyone know why it was added to |
I want to bring one topic. When the passive listeners were added to browsers the dev relations in Google like @jakearchibald commented that if event listeners were designed today, passive=true should be the default as its better for performance and in most cases you don't need active listeners. As this is a new API perhaps we can afford to change the default in order to be performant by default. |
@cibernox I would say that we would not have any hash params set by default. This way we don't have to chase browsers default params (or have inconsistent behavior to what users would expect). |
@richard-viney that should probably be added to the alternatives section. In initial design for this RFC it was discussed that we would favor composition instead of increasing the surface of |
text/0000-on-modifier.md
Outdated
function, users should use a helper such as the [bind helper](https://github.com/emberjs/rfcs/pull/470): | ||
|
||
```hbs | ||
<div {{on "click" (bind this.addNumber 123)}}></div> |
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 like how well this correlates to JS semantics
We discussed this RFC a bit at the f2f on Friday, one concern that was brought up by @rwjblue and needs to be addressed was the interop story with the One option would possibly be to add a flag that causes The other option is to explicitly not support any interop, and instead focus on guides helping users to debug and convert forward toward |
Can you elaborate on this? I'm not seeing how the isn't an inherent cost of transitioning the ecosystem away from the many degrees of magic in Here's what I'm thinking: As long as there is a clear migration path for each current usage of What's important is that there be a clear upgrade path and a set of well-documented paths for each way people are using I'm strongly in favor of the simpler (and more correct!) model here. Here's why I'm thinking that: I tend to think "introduce the breaking API with a clear migration path and no deprecation of the old one" is the better path. It's possible to over-optimize for "smooth transition," usually by introducing additional framework complexity. Introducing that additional complexity to make a smoother path in initial transition seems—
Given that the point is to get rid of the problems (including with event delegation!) from |
During the development of |
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.
Should we update the bind helper reference to with-args based on updates to that RFC?
Co-Authored-By: pzuraq <[email protected]>
The core team met today and decided to move this into final comment period. |
|
||
1. The event name as a string as the first positional parameter | ||
2. The event listener function as the second positional parameter | ||
3. Named parameters as options |
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 is kinda late and I apologize for that, but what will be the behavior, if the event name or event listener are missing or have the wrong type? ember-on-modifier
currently checks for typeof eventName === 'string' && typeof callback === 'function'
and only then registers the listener. If the check fails, no error will be raised. We might want to make this a hard assertion instead.
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.
Agreed, I believe that we will validate name and listener via assertions. I suppose we could do something to allow null/undefined but it really seems more likely to be a bug than intentional.
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.
@richard-viney One solution would be using (optional)
from ember-composable-helpers
, which returns a no-op function, if the input is not a function:
<button {{on "click" (optional (if this.isListening this.listener))}}>
...
</button>
While this requires extra gymnastics, I agree with @pzuraq and @rwjblue, that it is probably safer to assert against missing eventName
and callback
to prevent accidental errors.
Would allowing a undefined listener be useful for conditional application
of this modifier? AFAIK it’s not possible to wrap the whole {{on}} in an
if, but the listener param could be set to undefined to disable adding the
event listener. There may be a better way to do this though.
…On Tue, 16 Apr 2019 at 02:56, Robert Jackson ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In text/0471-on-modifier.md
<#471 (comment)>:
> +modifier. This modifier will explicitly add event listeners using the
+`addEventListener` API.
+
+## Credits
+
+The design of this modifier is based on [ember-on-modifier](https://github.com/buschtoens/ember-on-modifier)
+by Jan Buschtöns, which is an excellent addon that has allowed us to test this
+design in real apps and get feedback about the design.
+
+## Detailed design
+
+The `{{on}}` modifier will recieve:
+
+1. The event name as a string as the first positional parameter
+2. The event listener function as the second positional parameter
+3. Named parameters as options
Agreed, I believe that we will validate name and listener via assertions.
I suppose we could do something to allow null/undefined but it really seems
more likely to be a bug than intentional.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#471 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAOcBoqzv96h0U32LtXABeJH8VtEGe66ks5vhJM1gaJpZM4cC1Wt>
.
|
Yep, building on that idea of not allowing null/undefined: Having a no-op
helper could be both more explicit and mean less nesting of helpers, e.g.
{{on “click” (if cond listener no-op)}}. In some cases this might be more
readable as the name of (optional) is less direct about what’s going on.
Apps can add a no-op helper themselves if desired.
Another question is are we concerned about the potential cost/overhead of
adding event listeners only to have them be no-ops? We could actually avoid
this with a no-op helper that returned the same function every time, as
{{on}} could check for it with === and if found then not add the listener.
This would require {{on}} and (no-op) to agree on the shared no-op function
though.
…On Tue, 16 Apr 2019 at 09:09, Jan Buschtöns ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In text/0471-on-modifier.md
<#471 (comment)>:
> +modifier. This modifier will explicitly add event listeners using the
+`addEventListener` API.
+
+## Credits
+
+The design of this modifier is based on [ember-on-modifier](https://github.com/buschtoens/ember-on-modifier)
+by Jan Buschtöns, which is an excellent addon that has allowed us to test this
+design in real apps and get feedback about the design.
+
+## Detailed design
+
+The `{{on}}` modifier will recieve:
+
+1. The event name as a string as the first positional parameter
+2. The event listener function as the second positional parameter
+3. Named parameters as options
@richard-viney <https://github.com/richard-viney> One solution would be
using (optional) from ember-composable-helpers, which returns a no-op
function, if the input is not a function:
<button {{on "click" (optional (if this.isListening this.listener))}}>
...
</button>
While this requires extra gymnastics, I agree with @pzuraq
<https://github.com/pzuraq> and @rwjblue <https://github.com/rwjblue>,
that it is probably safer to assert against missing eventName and callback
to prevent accidental errors.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#471 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAOcBi5XqGs8aqh_mzYqHoGAso_llmKCks5vhOqXgaJpZM4cC1Wt>
.
|
Rendered