Quantcast
Viewing all articles
Browse latest Browse all 4826

What is the best practice to pass action down?

@dimas09 wrote:

I have next line in my template

{{some-fancy-component mydata=mydata editAction=(action 'edit') deleteAction=(action 'delete') addAction=(action 'add')}}

And in my component some-fancy-component I have next lines:

    @action
    callEditAction(...attrs){
        if (this.editAction){
            this.editAction(...attrs);
        }
    }

    @action
    callDeleteAction(id){
        if (this.deleteAction){
            this.deleteAction(id);
        }
    }

    @action
    callAddAction(...attrs){
        if (this.addAction){
            this.addAction(...attrs);
        }
    }

Yes, I should avoid duplication of code but it’s to make the example more verbose. I think should be a possibility to avoid of creation these dummy action in some-fancy-component component.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles