DockYard / ember-route-action-helper

Bubble closure actions in routes
MIT License
329 stars 48 forks source link

Invoking an action from `this.attrs` seems different in 2.10 #44

Closed shyshy closed 7 years ago

shyshy commented 7 years ago

Not sure if this is a bug, but noticed after upgrading to Ember 2.10 in our app, we were getting errors where we were calling an action the following way:

// template.hbs
{{my-component onclick=(route-action 'clicked')}}

// my-component.hbs
{{action-link action=onclick}}

// action-link.js
click() {
  this.attrs.action()
}

The error was this.attrs.action is not a function, and after digging through Ember's and this addon's internals, the source of the problem seemed to be here: https://github.com/DockYard/ember-route-action-helper/blob/master/addon/-private/internals.js#L5

The registry doesn't seem to include 'ember-htmlbars/keywords/closure-action' anymore, so ClosureActionModule.ACTION is undefined, and inside here: https://github.com/emberjs/ember.js/blob/c8c6b521b3102b13f4c77dc4ff4dcc504f02caef/packages/ember-glimmer/lib/utils/process-args.js#L101, the attr we pass in ends up as a MutableCell.

There were a couple fixes that arose from that:

  1. Wrapping onclick with (action onclick)
  2. Using this.get instead of this.attrs
  3. Adding ember-htmlbars/keywords/closure-action as another code path inside -private/internals to load from the registry.

1 and 2 were things we agreed stylistically we should have been doing to begin with which solve our issue, but, did want to know if anyone had any information about the 3rd solution.

poteto commented 7 years ago

Don't use this.attrs is the correct answer. See @locks' famous post for more context.