ember-composable-helpers icon indicating copy to clipboard operation
ember-composable-helpers copied to clipboard

invoke vs invoke-each

Open jondayton opened this issue 8 years ago • 0 comments

This is commented in https://github.com/DockYard/ember-composable-helpers/pull/121, but warrants another mention. invoke checks for an array, so there's no way to call it on the array itself. This doesn't cause many issues as there are lot of array helpers like append, but there are cases that don't work. append returns a new array, so if you want to modify the array itself, as with a related model:

{{#each playlist1.songs as |song|}}
  <a {{action (pipe (invoke 'addObject' song playlist2.songs) (invoke 'save' playlist2))}}>Add {{song.title}}</a>  
{{/each}}

it will tryInvoke addObject on each song. It would be nice to clarify by having an invoke-each helper, especially because at first glance at the documentation it appears as though invoke is only an array method, even though it can be used with arrays and objects.

jondayton avatar Jul 30 '16 15:07 jondayton