see-change
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.
Usage
change = seechange(functions)
Takes an array of functions
that return a value and returns a change
function.
change()
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.
arrayChanged()
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.
Example
const seechange =var highlighted = 0var viewport = 0 0 0 0var selected = 0const change =// When any of the functions return a different value,// `change()` will return `true`:// falseselected = 20// true// false// seechange.array will check to see if an array has changedviewport0 = 2// true// false
This makes it easy to transparently check for changes at the beginning of each frame in a render loop, e.g.:
{if ! return// shiny render code...}
License
MIT. See LICENSE.md for details.