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

pipe-action does not coalesce property notifications

Open mwpastore opened this issue 8 years ago • 0 comments

This is a weird one, so forgive me for going off-issue-template with this report. I'm using ember-composable-helpers 2.0.1 with Ember 2.14-beta.

I have two actions: one that removes an element from an array, and one that updates a property indicating which element of the array is currently selected. The return value of the remove action is the new index to select. For example, consider an array with three elements at indexes 0, 1, and 2. The last element (index 2) is currently selected. The user clicks a button to remove the middle element (index 1). After this operation is completed, the last element (now index 1) should still be selected.

To accomplish this, I am piping the result of the remove action to the select action, like so:

{{my-button click=(pipe-action
    (action 'removeItem' index)
    (action 'selectItem')
)}}

Now consider a computed property that has two dependent keys: the array.[] and the selected index. The problem I'm experiencing with pipe-action is that this sequence of actions results in two notifications to this property, when I would only expect one. Unfortunately, this can result in a situation where Ember tries to select an array index that is out of bounds.

The kicker is that it all works fine (i.e. property notifications are coalesced as one might expect) if I change the invocation to this:

{{my-button click=(action (pipe
    (action 'removeItem' index)
    (action 'selectItem')
))}}

Given that I have a workaround, this isn't an urgent issue, but considering that (pipe-action) is intended to be syntactic sugar for and semantically equivalent to (action (pipe)), it would be nice if it had the same "magic". I'll try to put together a Twiddle that demonstrates this behavior.

mwpastore avatar May 20 '17 00:05 mwpastore