array-watch
Track additions and deletions from an array
Usage
To track changes to an array, pass it to the watch
function. The result is a Proxy
to the array with on
and removeListener
functions for listening to changes. When a change is made, the following events will be fired:
add
- thevalues
array contains values added to the arrayremove
- thevalues
array contains values removed from the arraychange
- theadded
array contains values added to the array, and theremoved
array contains values removed from the array
const proxy = ; proxy; proxy; proxy; // => Added values: pushproxy1 = 'set'; // => Added values: setproxy // => Added values: splice,test // => Removed values: push
Changes are tracked regardless of whether they are the result of setting an indexed value, length
or calling a mutating function. Only changes that occur as the result of operations on the Proxy
can be tracked. The following will not call the add
handler:
const original = proxy = ; proxy; original;