Skip to content

boxofmattwire/flux-rails-assets

 
 

Repository files navigation

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 FluxDispatcher();

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.

About

flux-rails-assets gem

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%