Skip to content

Easy data manipulation to get, emit, set, compute and observe

License

Notifications You must be signed in to change notification settings

zaclummys/gesco

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gesco npm version npm downloads

Easy data manipulation to get, emit, set, compute and observe.

Installing

$ npm install gesco

API

gesco.get<T = any>(path: PathLike): T

Get the value stored in the path.

gesco.get('foo.bar');

gesco.delete(path: PathLike, silently: boolean = false)

Delete the value stored in the path. See silence.

gesco.delete('foo.bar');

gesco.emit<T = any>(path: PathLike: callback?: EmitCallback<T>)

Bubbles the value changes. See bubbles.

gesco.emit('foo.bar')
gesco.emit('foo', foo => {
    foo.push('bar');
})

Since changing a property directly or using array methods won't bubble, this allows you to indicate to Gesco that there has been a change/transformation. Use callback to perform operations like that.


gesco.set<T = any>(path: PathLike, value: any, silently: boolean = false): void

Stores a value in the path. See silence.

gesco.set('foo', 'bar');

gesco.observe<T = any>(from: PathLike, callback: ObserverCallback<T>): void

Observe the path and the descending paths.

gesco.observe('foo.bar', bar => {
    console.log('bar has changed:', bar);
});

gesco.compute<T = any>(to: PathLike, from: PathLike, callback: ComputerCallback<T>): void

Compute the path and the descending paths.

gesco.compute('newBar', 'foo.bar', bar => bar.toUpperCase());

gesco.link(from: PathLike, to: PathLike, bidirectional: boolean = false)

Links two different paths.

gesco.link('path1', 'path2');

Bubbles

This term refers to triggering the direct and indirect observers/computers of a path.

The methods set, delete and emit bubble the value changes automatically when invoked.

Silence

This term refers to prevent bubbling the value changes.

Propagation

When a value is changed, the change propagates to the path itself and its descendants. For example, changing foo will trigger:

  • foo
  • foo.bar
  • foo.bar.quux

License

MIT © Isaac Ferreira zaclummys@gmail.com