Jesseskinner Hover Versions Save

A very lightweight data store with action reducers and state change listeners.

v2.3.0

8 years ago

Hoverboard now has a compose function!

For more details, check out #16.

v2.0.0

8 years ago

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:

  • Each action method is essentially a reducer with the signature: function action (state, arg1, .., argN) { return newState }
  • When you call the action, you call it with just the arguments, eg. store.action(arg1, .., argN);
  • If the action reducer returns an object, it will be shallow merged into the state if the state is also an object.
  • The state passed to the action or to subscribers will be a shallow copy of the state, if it is an object, to prevent mutations.
  • Action method names are unchanged, ie. Hoverboard no longer prepends "on" to actions.

There are some other things that are new:

  • You can no longer pass a function to Hoverboard, nor return one from the actions.
  • Anything async response needs to go through an action, there is no way to setState otherwise.
  • You can no longer use a 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.
  • There are no longer this.getState, this.setState or this.replaceState methods.
  • You no longer have any need to use this with Hoverboard at all, so your actions can be pure functions.
  • Hoverboard is now only 555 bytes minimized and gzipped!

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.

v1.3.0

9 years ago

Two big changes here that make things more flexible:

  • State can now be any value, not just objects. If objects are used, they will still be merged via setState, but you can now use anything as your state.
  • Hoverboard no longer uses serializing to copy state. In fact, Hoverboard no longer prevents mutation at all. It's up to you whether to use serialization, 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!

v1.2.0

9 years ago

EventEmitter is no longer a dependency. This means Hoverboard has zero dependencies, and is only 800 bytes minified and gzipped! See #1

v1.1.0

9 years ago

This release eliminates the dependency on Facebook's Dispatcher. See issue #1.

v1.0.0

9 years ago

Finalized the API, and documentation is done. It's ready to be used in the wild. Looking forward to any and all feedback.