Ember invoking closure action

有些话、适合烂在心里 提交于 2020-01-25 00:21:11

问题


In Ember JS, say I have a component defined as below (HBS/JS)

parent.hbs

{{longclaw-sword attack=(action swing)}}

app/components/longclaw-sword.js

export default Ember.Component.extend({
  click() {
    this.attack();
  }
});

Is there any difference between calling the closure action using this.attack() V/s this.attr.attack()?

In which cases is "attr" used ? Can it be used for reference to normal properties OR is it only for actions ?


回答1:


attr is kinda unofficially deprecated afaik.

in the upcoming edition of Ember, Octane, attributes will mean specifically HTML-only attributes, and args will be what is in ember-land.

In the future / Now (if you want to play with the octane blueprint (https://github.com/ember-cli/ember-octane-blueprint), the above would be this:

@action swing() {
  // whatever this does :)
}

<LongclawSword @attack={{this.swing}} />

// in longclaw-sword:
import Component from '@glimmer/component';

export default LongclawSword extends Component {
  @action click() {
    this.args.attack();
  }
}
// or, if you don't need to wrap attack, you can do this inside longclow's template:
<button {{on 'click' this.args.attack}}>click</button>


来源:https://stackoverflow.com/questions/55657493/ember-invoking-closure-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!