disto
(this api might change)
- follows the original flux architecture
- a simple api, with no new concepts
- leans heavily on regular functions
- stores have no setters or ajax / async calls
- shorthand notation for action creators, with async function / promise support
- live editing experience across action creators / stores / views
- timetravel helper
- includes mixin to polyfill sideloading data on components
- browser / server / react-native compatible, because apparently that's a thing now
- really tiny - base ~2k, another 2k for dev goodies.
- tests
- i love you
npm install disto --save
var Dis = ;// Dispatcher class.
dispatcher
The dispatcher uses the fb dispatcher under the hood, but the api is tweaked for our stores / actions
var dispatcher = ; dispatcher dispatcher dispatcher dispatcher dispatcher
actions
Action creators can be however you choose. This is how I write them.
The action creator helper takes a map of key/values, and generates a collection of functions that, when each are called, dispatches a unique action along with passed arguments further calling any optional function passed in the map.
Indeed, we use the action creator itself as the 'actionType' to much convenience
What this means, is that you'll likely never have to dispatch a raw action by yourself.
Also, since these are unique objects (with readable string representations), you also don't have to worry about global namepace clashes.
var $ = dispatcher; // $.a is now a function $; // dispatches [$.a, 1, 2, 3] to all stores console // baconium:~:a $; // dispatches [$.b], and then logs "possibly fire..." $; // dispatches [$.c], then [$.b], and then logs "possibly fire..." $; // dispatches [$.d], later [$.d.done, 'any', 'args', 'you', 'like'] $; // dispatches [$.e], then [$.e.done, 'success!'] $; // dispatches [$.f], later [$.f.done, response] $; // dispatches [$.g], then [$.g.error, Error:disto] // these actions are consumed by stores,// which hold all the 'state'
stores
Stores are represented as initial state + a 'reduce' function that get called on every [actions, ...args] message that passes through the "system".
While this might seem terse, it's a fully open system, and you should be able to build any abstraction on top of it.
var initialState = q: '' res: // initial state err: null; { } var store = dispatcher; store // returns current value // you can optionally pass in a custom 'compare' function// which decides when to trigger 'change' events// analogous to 'shouldComponentUpdate' // eg, with immutable-js (https://facebook.github.io/immutable-js/)// we'd use immutable.is to compare states var iStore = dispatcher; // stores are also lightweight 'observables', store // we use this to hook on to react components via the .observe() polyfill var mix = mix; var Component = React
hot loading
to enable hot loading of stores/actions, use hot versions of the dispatcher register/act functions
var register act = ; var store = ; // etc etc
(there are quirks around this that I'll document soon)
works well with react-hot-loader
time travel!
(compatible with hot mode)
// run this before registering any other storesvar r = ; var i = r // takes a snapshot of current stater // 'goes' to a particular snapshot r // start recordingr // stop recordingr // replay the session