A thin layer on top of flux and riotjs, to bring flux architecture to your riot apps.
$ git clone https://github.com/mingliangfeng/flux-riot.git
$ cd flux-riot
$ npm install
$ npm test
$ npm start
$ cd flux-riot/examples/todo
$ npm install
$ npm test
$ npm start
Observable base store to be extended. Exposes addChangeListener, removeChangeListener, and emitChange functions. e.g.
Create new store:
var TodoStore = assign(new flux_riot.BaseStore(), {
dispatchToken: Dispatcher.register(function(payload) {
var action = payload.action
switch (action.type) {
case ActionTypes.TASK_SAVE
...
TodoStore.emitChange()
}
})
})
Register and unregister store listener from view:
# inside riot tag
...
this.on('mount', function() {
store.addChangeListener(this.storeChanged)
})
this.on('unmount', function() {
store.removeChangeListener(this.storeChanged)
})
Helper to mixin store to a riot tag, exposes method storeMixin(tag, store, storeChangeHandler) and does 3 things:
- assign store to store property of tag instance;
- listen to mount event and register store listener;
- listen to unmount event and unregister store listener.
e.g.
# inside riot tag
...
flux_riot.storeMixin(this, opts.store, this.updateFromStore)
A thin layer on top of riot.router, provides a declarative way to define routes.
- flux_riot.BaseRouter.routes(root_action, [path, action, [..]])
e.g.
BaseRouter.routes(list,
'todos/add', edit,
'todos/edit/:id', edit
)
- flux_riot.BaseRouter.start()
Study the current hash “in place” using previously defined routes. An optional callback can be passed in to override the defined routes.
Adds handleServerAction and handleViewAction methods to flux.Dispatcher for convinience. e.g.
# inside action creators
...
Dispatcher.handleViewAction(type: ActionTypes.TASK_SAVE, data: data)
flux-riot is licensed under the MIT license.