hamahama
hamahama

Reputation: 393

What is the purpose of this Emberjs component's "update" action

I am looking at some legacy code from a previous EmberJS v2.16 project, the person responsible is not longer around, so I'm hoping for some advice here.

export default Component.extend({
  // ...

  actions: {
    update(value) {
      this.get('update')(value);
    },

  // ...
});

I'm not sure how much code is required, but let me know if it's too abstract and I'll try to provide more context.

Is this.get('update') referring to the update(value) function? In what situation will someone have to do this?

Upvotes: 0

Views: 30

Answers (1)

Karl-Johan Sjögren
Karl-Johan Sjögren

Reputation: 17532

Your developer probably wanted to execute an action outside of your component. When the component is invoked in your template I'm guessing it looks something like this.

{{awesome-component update=(action 'outer-update-action')}}

So then in your component this.get('update') would get the function that was passed in so you can call it with your value.

It's described in the Ember Guide on the component page under "Triggering Changes with Actions".

Upvotes: 3

Related Questions