
A variant of Flux with
central, isolated state.
Microcosm makes it easier to control and modify state in a pure,
centralized way. It uses stateless, singleton Stores and Actions, keeping
all data encapsulated in one place. This design seeks to achieve a
reasonable trade off between the simplicity of singletons and the
privacy of class instances.

Overview
Within the context of the Flux model, Microcosm treats actions and
stores as singletons, however they do not contain any state.
Actions are called within the context of a particular instance of Microcosm:
let Action = function(params) {
return params
}
app.push(Action, params)
Stores hold no state. Stores are collections of functions that transform
old data into new data, with a hook that register
s them with the Microcosm.
let Store = {
register() {
return {
[Action] : this.add
}
},
add(state, params) {
return state.concat(params)
}
}
Opinions
- Action CONSTANTS are automatically generated by assigning
each Action function a unique
toString
signature under the hood. - Actions dispatch parameters by returning a value or a promise (only
dispatching when it is resolved)
- Actions handle all asynchronous operations. Stores are
synchronous.
- Stores do not contain data, they transform it.
What is it trying to solve?
- State isolation. Requests to render applications server-side should
be as stateless as possible. Client-side libraries (such as
Colonel Kurtz) need easy
containment from other instances on the page.
- Singletons are simple, but make it easy to accidentally share
state. Microcosm keeps data in one place, operating on it
statelessly in other entities.
- Easy extension of core API and layering of features out of the
framework's scope.
Tutorials
Hello, Microcosm is a great place to
start. With that background, Design may help to
provide an additional high level overview of how things work. Beyond
that, check out the example apps.
Documentation
There is documentation here. This includes high level
overviews of framework architecture, guides, and API documentation for
the individual components of Microcosm.
Inspiration