You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
When items are added or removed from array being watched by ArrayReduction, all the PathObservers that watched items indexed AFTER the add/remove index are out of sync.
Let's look at an example...
varvalues=['a','b','c'];varcalls=[];varreduction=newArrayReduction(values,'',function(sum,cur){sum.push(cur);returnsum;},calls);calls.splice(0);// Internal view of observers.path for each item by index:// array index observer.path// ----------- -------------// 0 0// 1 1 <---- To be spliced// 2 2values.splice(1,1);reduction.deliver();// Internal view of observers.path for each item by index:// array index observer.path// ----------- -------------// 0 0// 1 2 <---- INCORRECT PATH, SHOULD BE 1// == EXPECTED ==// > Calls to reduce function: ["a", "c"]// === ACTUAL ===// > Calls to reduce function: ["a", "c", "a", "c", undefined]console.log('Calls to reduce function:',calls);
... Notice the difference in EXPECTED and ACTUAL output.
What appears to be happening is the PathObserver that was watching the [2] element (which is now the [1] element), incorrectly causes a another reduce() because it sees a change in value ('c' -> undefined).
When items are added or removed from array being watched by ArrayReduction, all the PathObservers that watched items indexed AFTER the add/remove index are out of sync.
Let's look at an example...
... Notice the difference in
EXPECTED
andACTUAL
output.What appears to be happening is the PathObserver that was watching the
[2]
element (which is now the[1]
element), incorrectly causes a anotherreduce()
because it sees a change in value ('c'
->undefined
).I believe the problem is that ArrayReduction's
handleSplice()
does not loop over and update the paths inobservers
. https://github.com/rafaelw/ChangeSummary/blob/08cb2c69b5daba0cbd5e806820311a76ea279858/util/array_reduction.js#L56The text was updated successfully, but these errors were encountered: