node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Detect changes in the return values of a list of functions. Useful for memoizing functions with multiple dependencies: e.g. only updating a visualization when specific values have changed.



change = seechange(functions)

Takes an array of functions that return a value and returns a change function.


Returns true if the return values of any of the previously supplied functions have changed since it was last called.

arrayChanged = seechange.array(array)

Takes an array of values and returns a change function.


Returns true if any elements in the array have changed since the function was last called. May also be supplied as a function in seechange, and changes will propogate upwards as expected.


const seechange = require('see-change')
var highlighted = 0
var viewport = [0, 0, 0, 0]
var selected = 0
const change = seechange([
  () => highlighted,
  () => selected,
// When any of the functions return a different value, 
// `change()` will return `true`: 
change() // false 
selected = 20
change() // true 
change() // false 
// seechange.array will check to see if an array has changed 
viewport[0] = 2
change() // true 
change() // false 

This makes it easy to transparently check for changes at the beginning of each frame in a render loop, e.g.:

function render () {
  if (!change()) return
  // shiny render code... 


MIT. See for details.