Skip to content

download13/emitting-primitive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emitting-primitive

A store that holds a single primitive value (string, number, boolean). It emits events to registered listeners when the value changes.

Example

var EmittingPrimitive = require('emitting-primitive');

// Initial state can be passed during construction, or it will be null
var counter = new EmittingPrimitive(0);

// The handler will be called once with the value 0 when it is registered
// and again with the value 1 when the value is set down below
counter.onChange(function(value) {
	// Update view
	view.render({count: value});
});

counter.set(counter.get() + 1);

Methods

  • .get() - Gets the current value
  • .set(value) - Sets the current value
  • .onChange(fn) - Registers fn as a handler that will be called once when it is registered, and again whenever the stored value changes.

About

A primitive value store that makes it easy to keep dependencies in sync

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published