Adding/removing non-last array elements leads to a chain of update changes, before the actual delete/add change is reported on the last array element. I can understand this behaviour from the proxy’s perspective (and I know that you try to be close to the Proxy behaviour), however as a developer I’d prefer to get the high-level perspective of which array element was actually affected.
Library version tested against: 0.0.8
Repro:
const ObservableSlim = require('observable-slim');
const proxy = ObservableSlim.create([0, 1, 2, 3]);
ObservableSlim.observe(proxy, changes => changes
.forEach(change => console.log(change.currentPath, change.type)));
console.log(proxy);
proxy.splice(0, 1); // delete “0” from index 0
console.log(proxy);
proxy.splice(0, 0, 0); // add “0” at index 0
console.log(proxy);
Result:
[ 0, 1, 2, 3 ]
0 update
1 update
2 update
3 delete
length update
[ 1, 2, 3 ]
3 add
2 update
1 update
0 update
[ 0, 1, 2, 3 ]
Expected:
The library should either report the actual affected index for delete/add changes on arrays or introduce a new (additional) change type addElement/deleteElement that reports the actual index. Interestingly, there seems to be no change fired on the length property when you add items to an array (I tried it with both splice and push).
Adding/removing non-last array elements leads to a chain of update changes, before the actual delete/add change is reported on the last array element. I can understand this behaviour from the proxy’s perspective (and I know that you try to be close to the Proxy behaviour), however as a developer I’d prefer to get the high-level perspective of which array element was actually affected.
Library version tested against: 0.0.8
Repro:
Result:
Expected:
The library should either report the actual affected index for delete/add changes on arrays or introduce a new (additional) change type
addElement/deleteElementthat reports the actual index. Interestingly, there seems to be no change fired on thelengthproperty when you add items to an array (I tried it with bothspliceandpush).