-
-
Notifications
You must be signed in to change notification settings - Fork 517
fn & on #912
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
fn & on #912
Conversation
@NullVoxPopuli |
@@ -297,7 +297,7 @@ import { action } from '@ember/object'; | |||
|
|||
export default class SendMessage extends Component { | |||
@action | |||
sendMessage(messageType) { | |||
async sendMessage(messageType) { |
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 know some work supporting async
/await
landed into backburner and Ember in 3.x, but I'm not sure if FW core is encouraging this in app code yet. I've queried a few people for clarification.
Regardless, I'm not sure why this action is async
... Simply to provide an example that it is possible?
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've been using async/await everywhere in emberclear, and haven't ran into issues. 🤷♂️
I think the the name implies that there is going to be some interaction with a backend, so I would expect it to be async :)
Note that while Ember currently permits you to add an action to any DOM element, not all DOM elements are eligible to receive focus, according to HTML standards. | ||
Note that while Ember currently permits you to add an action to any DOM | ||
element, not all DOM elements are eligible to receive focus, according to | ||
HTML standards. |
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 Note
is pretty confusing. As a reader I'm not sure what this comment (something something focus) has to do with actions on non-clickable elements.
This is likely trying to nudge the user to think about accessibility? Can it be structured so that a first time using coming to this section can get the information they expected before that consideration distracts them?
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 Note is pretty confusing.
yeah, I struggled with it a bit, too.
This is likely trying to nudge the user to think about accessibility?
I think so. I've primarily only used Chrome and FireFox, so I haven't run in to any issues with browsers not letting things be clickable. I wonder if this text is counting a screen reader or other a11y tool as a browser.
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.
Not sure what to do about these notes -- kinda out of scope for this Pr, but if someone else wants to tackle it / open an issue for it, be my guest!
Could/should the docs provide a migration guidance for the For example, given this code: <input onclick={{action "update" value="target.checked"}} type="checkbox">
<input oninput={{action "update" value="target.value"}}> actions: {
update(value) {
console.log(value);
}
} Is this the recommended replacement? <input {{on "click" this.update}} type="checkbox">
<input {{on "input" this.update}}> @action
update({ target: { checked, value } }) {
console.log(checked || value);
} And is there a path for <input oninput={{action (mut this.query) value="target.value"}}> You'd have to create an action in the component that updates AFAICT, the {{on}} RFC didn't touch on that? @pzuraq |
@CvX I believe the first few examples should be the preferred form. Currently, we don't have a path to a direct replacement for
Basically, these APIs are convenient in that they are terse, but they are not easy to teach, and do not have much utility unless they are used together. We realized through the design process that what we really want here is some form of closures: <input {{on "input" (|event| (set this.query event.target.value))}} /> Something along these lines. However, this is a huge lift, and adds a large amount of complexity to both Glimmer from an implementation perspective and templates from a language design persective, so I'm not sure if this is a direction we want to go yet. I think in the meantime, it would be best to make a custom helper that handles common use cases like this, where it would be inconvenient to create an action handler. call it <input {{on "input" (pickAndSet this "query" "target.value")}} /> This would pick the value off of whatever is passed to it and set it. Then at least the two actions are related to each other lexically, and can tell the users that they are related just by reading it. You could use a template transform to mimic the
|
guides/release/templates/actions.md
Outdated
@@ -21,22 +21,30 @@ export default class Post extends Component { | |||
} | |||
``` | |||
|
|||
You can then add this action to an element using the | |||
[`{{action}}`](https://api.emberjs.com/ember/release/classes/Ember.Templates.helpers/methods/action?anchor=action) | |||
`@action` binds the `this` of `toggleBody()` to the instance of the class, allowing access the component's other properties when invoked. Without the decorator, `this.isShowingBody` in `toggleBody()` is undefined. For more information on `this` [Understanding Javascript Function Invocation and this](https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/) |
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.
Thanks @NullVoxPopuli and @locks for talking this through with me. I think this hits the key terms (binds
, class
) while also, with the second sentence, explaining in a more quotidian way why @action
is needed!
around as values, and allow them to be invoked in different locations. |
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.
that comma before "and" is not needed and causes confusion.
guides/release/components/index.md
Outdated
@@ -142,4 +142,5 @@ In the following guides we'll talk about: | |||
which Ember fully supports |
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.
While at it, this should have a period at the end to follow the style of the rest of this list.
Thank you @NullVoxPopuli and reviewers! If anyone wants to extend upon this work or make additional fixes, I'm happy to help get more PRs merged in! |
related info: https://www.pzuraq.com/ember-octane-update-action/