microcosm
Advanced tools
Changelog
12.8.0
Changelog
12.7.0
teardown
method to the Microcosm
prototype. This behaves similarly to teardown
methods on other
Microcosm classes.repo.push
is passed into the open
state of
actions that return promises.batch
as an option when instantiating Microcosm. When set to
true
, high frequency change events will be batched together using
requestIdleCallback
. When not available, it falls back to setTimeout.Action status methods like action.resolve()
and action.reject()
are auto-bound. They can be passed directly into a callback without
needing to wrap them in an anonymous function.
This is particularly useful when working with AJAX libraries. For
example, when working with superagent
:
Instead of:
import superagent from 'superagent'
function getPlanets() {
return action => {
let request = superagent.get('/planets')
request.on('request', data => action.open(data))
request.on('progress', data => action.update(data))
request.on('abort', data => action.cancel(data))
request.then(data => action.resolve(data), error => action.reject(error))
}
}
You can do:
import superagent from 'superagent'
function getPlanets() {
return action => {
let request = superagent.get('/planets')
request.on('request', action.open)
request.on('progress', action.update)
request.on('abort', action.cancel)
request.then(action.resolve, action.reject)
}
}