flux-rails-assets
Flux and Node EventEmitter for Rails Asset Pipeline for use with react-rails gem
Doesn't use CommonJS instead it creates FluxDispatcher and EventEmitter on window to easily work with sprockets-rails Assets Pipeline.
Works well with react-rails server side rendering.
- Flux version: 2.1.0
Installation
Add this line to your application's Gemfile:
gem 'flux-rails-assets'
And then execute:
$ bundle
Or install it yourself as:
$ gem install flux-rails-assets
Usage
Require flux and the eventemitter in your application.js:
//= require flux
//= require eventemitter
This will create two globals you can use to create your application's dispatcher and stores:
var AppDispatcher = new Flux.Dispatcher();
var ExampleStore = new EventEmitter();
ExampleStore.dispatchToken = AppDispatcher.register(function (payload) {
var action = payload.action;
switch(action.actionType) {
case 'EXAMPLE_ACTION':
ExampleStore.emit('change');
break;
default:
// do nothing
}
});
Credits
Flux by Facebook Node EventEmitter by Joyent
Written by Stefan Ritter, released under the MIT license.