A reactive state in just 269 bytes raw!
import state from '@nuff-said/state'
const state = observable({ x: 0, y: 0 });
let callCount = 0;
state(['x', 'y'], () => { callCount++; });
state('x', (val) => console.log('x changed'))
state.y = 2;
state.x = 1;
// => x changed
console.log(callCount)
// => 2$ npm i @nuff-said/stateCreates an observable. Can be used as a simple object, but can also be called to set listeners.
keys: Array<string> | string: A single key or a list of keys for which the callback will runcallback: (key, value, deleted) => {}: A callback function that is provided the name of the key changed, the new value, and whether the change is a deletion of the key from the object.
All contributions are welcome! Feel free to file an issue, point out an optimization or even push a PR!
This project uses the GPL-3.0 license.