watch-array

Watch any changes on arrays

Lets you subscribe to any changes on native JavaScript arrays.

watchArray = require('watch-array')
 
people = ['Joe', 'Smith']
 
watchArray(people, function(update){ // or watchArray.once(people, function(update){ 
 
    update.add
    // => { 1: Taylor, 2: Brown } 
 
    update.remove
    // => [0] 
 
})
 
people.shift()
people.push('Taylor', 'Brown')
$ npm install watch-array
  • It mixes the given array with new-pubsub. So you actually have a minimalistic pub/sub API in the array.
  • It doesn't add new methods or change the behaviour of existing ones.
  • It overrides mutable methods like push, splice etc to emit the changes.