import Ember from "ember";
export default Ember.Component.extend({
actions: {
edit() {
this.attrs.submit(this.get('item'));
}
}
});
Should I send the item as parameter and then re-find it from the store on the route and finally save it to the server. Or should I send the submit function a parameter per each item field? Or is this all wrong? I’d like to know what’s the Ember way to handle actions now.
That looks all good except I’m not sure that the edit action in the component will be fired automatically as it is, to my knowledge, not a UI event.
Other than that, the way it is set up now, the saveItem action handler in your controller will receive the item that was edited/clicked/whatever and can then save it:
They are closed over the variables in their (template) scope including the scope.
// app/templates/application.hbs
{{! scope here is controller, the action helper creates a closure that binds the scope as oppose to...}}
{{#my-component do-things=(action "action")}}
{{/my-component}}
// app/templates/components/my-component.hbs
{{! the scope here is the component, the resulting closure binds the component as the action handler's "this" }}
{{yield (action "action")}}