-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Support target
option for closure actions
#14469
Comments
Looking back at more Slack chat, Robert provided even more direction which is great! https://embercommunity.slack.com/archives/-help/p1476381597028760
/CC @sukima since you were involved with that particular convo. |
This makes sense to me. If I understand the suggestion -- basically we would change the AST plugin to check for a |
/cc @sukima |
The /* usage:
*
* {{my-button click=(action 'funcName' target=someService)}}
*/
export default Ember.Service.extend({
actions: {
funcName() {
/* something */
}
}
}); I'm a little wary of making I agree we can improve the ergonomics of the |
@mixonic I thought the issue here was that there is an inconsistency between closure actions and modifier actions in how In any case, if |
I agree with @zackthehuman in that I thought the issue was to fix an inconsistency. The actions hash + string usage is something I didn't know worked at first, until troubleshooting further for this issue/case. While I could refactor to make that usage work, I think this should still be fixed. |
Written as That @zackthehuman @Panman8201 you both sounds like you have use-cases for the binding behavior though- can you provide an example of how you use it in an application today, or would like to be able to use it? |
@mixonic Say I have an Ember data model which has helper functions on it: import Ember from 'ember';
import DS from `ember-data`;
const { Model, attr } = DS;
const { get } = Ember;
export default Model.extend({
foo: attr({defaultValue() { return []; }}),
addNewFoo() {
get(this, 'foo').pushObject({bar: 'bar'});
},
moveFooUp(index) {
let foo = get(this, 'foo');
let orig = foo.objectAt(index);
foo.removeAt(index);
foo.insertAt(index - 2, orig);
},
moveFooDown(index) {
let foo = get(this, 'foo');
let orig = foo.objectAt(index);
foo.removeAt(index);
foo.insertAt(index, orig);
}
}); So in a view I might have: {{#each model as |myModel|}}
{{#each myModel.foo as |theFoo index|}}
<div>{{theFoo.bar}}</div>
<div class="user-actions">
<button onclick={{action (action model.moveFooUp target=model) index}}>^</button>
<button onclick={{action (action model.moveFooDown target=model) index}}>V</button>
<button onclick={{action (action theFoo.removeAt target=theFoo) index}}>X</button>
</div>
{{/each}}
<button onclick={{action (action model.addNewFoo target=model)}}>Add another foo</button>
{{/each}} |
@mixonic Here is a twiddle to illustrate what I mean: https://ember-twiddle.com/#/a61ed2dedc6e6e0729b4a2d7b60e5ad9 Edit: I don't have a horse in this race, if this is the intended behavior I'm happy to close my PR. |
@mixonic - This is not related to adding a new functionality (as you seem to be implying), it is related to making One small example: Additionally, take a look at the following docs which suggest that
Perhaps, your position is that we should never have supported All of that being said, this PR also has merits on its own. Removing the "maybe implicit or explicit target" behavior in |
Right. I totally understand there is an inconsistency between element-space action and closure actions as regards However I strongly believe the use-case outlined above (addressing methods on a model) is an anti-pattern in Ember app development. In this light, the behavior of classic actions can be considered something of a bug, and I would not like to copy that behavior forward into closure actions. In the medium-term element-space actions will be deprecated in Ember and in the long term they will be removed, however the closure action API will remain with Ember for what I expect to be a long time. Let's only bring with us what we want. There is no documentation suggesting
|
I agree that we should fix the implicit binding and use |
Do you agree on @zackthehuman last comment? |
Yup, we are on the same page. Much of @zackthehuman's PR was cleanup that I think still should be applied. |
@Panman8201 @zackthehuman @mixonic @rwjblue is this still an issue, perhaps we should close or create a new reproduction of this, what do you think? |
Per our triage policy I'll close this out for now, feel free to reopen if the issue persists on the current release. |
It seems when using a closure
(action)
thetarget
option is not respected in the same way as with the "traditional" helper{{action}}
. My main need is for the called action/function to have thethis
context of object itself, not the caller. The most common use case is when you're trying to pass in an action into an ember component. Ex:However, at the same time if you're able to use the "traditional" helper, then it works. Ex:
I have a working example in an Ember Twiddle. But for reference here, the called function would look something like:
In chatting with @rwjblue and company in the Slack community, apparently this can be handled in the action AST file, which should then be able to eliminate some "ugly code" in the action modifier. I'm still trying to wrap my head around the internals and AST stuff, but at least there is direction in where to start.
The text was updated successfully, but these errors were encountered: