A very lightweight data store with action reducers and state change listeners.
Hoverboard now has a compose function!
For more details, check out #16.
This is the second major version for Hoverboard, and makes some major API changes and simplifications.
Hoverboard now only takes an object of actions, with the following changes:
function action (state, arg1, .., argN) { return newState }
store.action(arg1, .., argN);
There are some other things that are new:
setState
otherwise.getInitialState
method. Instead, you'll need to create an action that sets the initial state and then trigger that action on the store before using the store.this.getState
, this.setState
or this.replaceState
methods.this
with Hoverboard at all, so your actions can be pure functions.Here's an updated example:
var ClickCounter = Hoverboard({
click: function(state, text) {
return {
value: state.value + 1,
log: state.log.concat(text)
};
},
reset: function() {
// go back to defaults
return {
value: 0,
log: []
};
}
});
// initialize with defaults
ClickCounter.reset();
// listen to changes to the state
var unsubscribe = ClickCounter(function (clickState) {
document.write(JSON.stringify(clickState) + "<br>");
});
ClickCounter.click('first');
ClickCounter.click('second');
// reset back to empty state
ClickCounter.reset();
unsubscribe();
ClickCounter.click("This won't show up");
Check out the README for updated documentation and examples.
Two big changes here that make things more flexible:
Object.assign
, or some other immutability library to protect your state by writing a custom getState
method. If you want to use the old way Hoverboard did mutation protection, add this getState
method to your stores:var Store = Hoverboard({
getState: function(state){
return JSON.parse(JSON.stringify(state));
}
});
These are the last changes I have planned for a while. Hoverboard is now only 769 bytes minimized and gzipped!
EventEmitter is no longer a dependency. This means Hoverboard has zero dependencies, and is only 800 bytes minified and gzipped! See #1
This release eliminates the dependency on Facebook's Dispatcher. See issue #1.
Finalized the API, and documentation is done. It's ready to be used in the wild. Looking forward to any and all feedback.