Skip to content

nuff-said/state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Installation

$ npm i @nuff-said/state

Documentation

observable(object) => observedObject

Creates an observable. Can be used as a simple object, but can also be called to set listeners.

observedObject(keys, callback)

  • keys: Array<string> | string: A single key or a list of keys for which the callback will run
  • callback: (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.

Contributing

All contributions are welcome! Feel free to file an issue, point out an optimization or even push a PR!

License

This project uses the GPL-3.0 license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors