state-object
v0.0.4
Published
`state-object` creates objects that each encapsulate a single mutable state value. In addition to getter/setter methods, a `guardedTimeout` method is also provided, allowing future conditional execution of callbacks predicated on the state value.
Downloads
3
Readme
state-object
state-object
creates objects that each encapsulate a single mutable state value. In addition to getter/setter methods, a guardedTimeout
method is also provided, allowing future conditional execution of callbacks predicated on the state value.
Installation
Browserify
Install:
$ npm install state-object
Require:
var stateObject = require('state-object');
API
var so = stateObject(initialState)
Create a new state object whose state is set to initialState
.
so.get()
Returns the current state of so
.
so.set(newState)
Sets state of so
to newState
.
so.guardedTimeout(fn, timeout)
Schedule fn
to be called after timeout
milliseconds, if and only if so.set()
has not been called in the intervening period.
so.guardedTimeout(onlyInState, fn, timeout)
Schedule fn
to be called after timeout
milliseconds if and only if the state's value after the timeout equals onlyInState
.
Copyright & License
© 2014 Jason Frame [ @jaz303 / [email protected] ]
Released under the ISC license.