Avoid repetition of method name in actions

44 Views Asked by At

How do I avoid the following repetition of my foo method in my ember component?

Ember.Component.extend({
  ...

  foo(val) {
    this.set('baz', val);
  },

  actions: {
    bar() {
      this.foo(this.get('val'));

      // .. other code
    },
    foo(val) {
      this.foo(val);
    }
  }
});
1

There are 1 best solutions below

0
On BEST ANSWER

Your code looks okay. If you really want to change something you could make foo method an action:

Ember.Component.extend({
  ...

  actions: {
    bar() {
      this.send('foo', this.get('val'));

      // .. other code
    },
    foo(val) {
      this.set('baz', val);
    }
  }
});