watch-array

Watch any changes on arrays

npm install watch-array
20 downloads in the last month

watch-array

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')

Install

$ npm install watch-array

How It Works?

  • 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.

npm loves you