flux-rails-assets gem
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
vendor/assets/javascript
.gitignore
Gemfile
LICENSE.txt
README.md
Rakefile
flux-rails-assets.gemspec

README.md

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.

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.