jeudi 8 octobre 2015

Structuring a list of components that have to remove themselves in Ember

I'm not sure if this belongs on SO because it's more about design than programming.

I have an array of models and each model has a corresponding component. The components can delete their models. However, when the model is deleted, they should also be removed from the array.

Here are 2 ways I'm approaching this problem:

{{#each item in items}}
  {{item-row item=item items=items}}
{{/each}}

In this case, I'm passing the entire array to the child component. The child component can remove its own item from the items array.

Here's the second way:

{{#each item in items}}
  {{item-row item=item removeItem="removeItem"}}
{{/each}}

Here, the child component sends a removeItem action. When the parent component receives the removeItem action, it removes the item from the array.

Which is the better way to do this in Ember? Is there a better way?




Aucun commentaire:

Enregistrer un commentaire