microcosm
Advanced tools
Changelog
3.1.0
Microcosm::getInitialState()
now accepts an options
argument. This argument is passed down from the constructor.Changelog
3.0.0
Microcosm::merge
has been replaced with
Microcosm::swap
. Additionally, Microcosm::reset
has been added
to completely obliterate old state.Microcosm::addStore
now only accepts one store at a time. It was
not being utilized, gives poorer error handling, and makes let less
clear the order in which Stores will process data.Heartbeat
was replaced with pulse
. Pulse is a
function that can act as a factory or decorator. When given an
argument, it extends an object with emitter functionality, otherwise
it returns a new object that implements the same API. This
eliminates the possibility that the private _callbacks
member of
Heartbeat
was overridden. It also reduces the use of classical
inheritance, which yields some minor file size benefits by
polyfilling less of the class
API.Changelog
2.0.0
Microcosm::send
currying with partial application
using Microcosm::prepare
Microcosm::set
has been replaced with Microcosm::merge
, so far
set
has only been used internally to Microcosm
and merge
dries
a couple of things upCurrying has been removed Microcosm::send
. This was overly clever
and somewhat malicious. If an action has default arguments, JavaScript
has no way (to my knowledge) of communicating it. One (me) could get into a
situation where it is unclear why an action has not fired properly
(insufficient arguments when expecting fallback defaults).
In a language without static typing, this can be particularly hard to debug.
In most cases, partial application is sufficient. In light of this,
actions can be "buffered up" up with Microcosm::prepare
:
// Old
let curried = app.send(Action)
// New
let partial = app.prepare(Action)
Microcosm::prepare
is basically just fn.bind()
under the
hood. Actions should not use context whatsoever, so this should be a
reasonable caveat.
Changelog
1.4.0
Store.deserialize
returns the result of getInitialState
if no
state is givenMicrocosm.swap
to perform diffing and emission on changeMicrocosm.seed
will now trigger a change eventHeartbeat.js
now invokes callbacks with callback.call(this)
Changelog
1.3.0
set
the result of getInitialState
when adding a storedeserialize
on stores when running seed
./src/Store.js
for details.Changelog
1.2.0
serialize
method which allows them to
shape how app state is serialized to JSON.Changelog
1.1.0
Microcosm::seed
which accepts an
object. For each known key, Microcosm will the associated store's
getInitialState
function and set the returned value.Microcosm::getInitialState
to configure the starting value
of the instance. This is useful for those wishing to use the
immutable
npm package by Facebook.Microcosm::shouldUpdate
Microcosm::send
is now curried.Changelog
1.0.0
This version adds many breaking changes to better support other libraries such as Colonel Kurtz and Ars Arsenal.
In summary, these changes are an effort to alleviate the cumbersome nature of managing unique instances of Actions and Stores for each Microcosm instance. 1.0.0 moves away from this, instead relying on pure functions which an individual instance uses to operate upon a global state object.
microcosm/tag
. For the time being,
this is to provide a unique identifier to each Action. It would be
nice in future versions to figure out a way to utilize WeakMap
.Store
base
class.toString
method which returns a unique id.microcosm.get(Store)
addActions
, actions are fired with
microcosm.send(Action, params)
Microscope
container component. Just use listen