Harris
A predictable State Container inspired by Redux; in an OOP style.
Installation
// First, we define our model. In our case,// a simple number is fine. // Here we have a corresponding decrement// action. Note also that these actions are// classes, and can contain context data// which can be conveniently injected in// the constructor. // We declare a union of all the different// action types for future reference. // Here is an Update. Updates describe the// transitions from one state to another,// given an action object. // Using an initial state and an update function// we can create a `Store`, which is a mutable// object containing the state of the app. // We can access the current state like sostore.state // === 0 // The only way to mutate a `Store` is by dispatching// an `Action`. Like this:store.dispatchnew IncrementAction // The Store then uses the `Update` function to// figure out the next state.store.state // === 1 // We can get notified of updates automatically by// subscribing to the store:store.subscribe
First Class Tweed Support
If you're using Tweed, the Store
class will automatically
update the UI when a command is dispatched:
rendernew Root, document.querySelector'#root'