Flux

Application Architecture for Building User Interfaces

README

Flux


  An application architecture for React utilizing a unidirectional data flow.


Getting Started


Start by looking through the guides and examples on Github. For more resources and API docs check out facebook.github.io/flux.

How Flux works


For more information on how Flux works check out the Flux Concepts guide, or the In Depth Overview.

Requirements


Flux is more of a pattern than a framework, and does not have any hard dependencies. However, we often use EventEmitter as a basis forStores and React for ourViews. The one piece of Flux not readily available elsewhere is the Dispatcher. This module, along with some other utilities, is available here to complete your Flux toolbox.

Installing Flux


Flux is available as a npm module, so you can add it to your package.json file or runnpm install flux. The dispatcher will be available as Flux.Dispatcher and can be required like this:

  1. ```javascript
  2. const Dispatcher = require('flux').Dispatcher;
  3. ```


Flux Utils


We have also provided some basic utility classes to help get you started with Flux. These base classes are a solid foundation for a simple Flux application, but they are not a feature-complete framework that will handle all use cases. There are many other great Flux frameworks out there if these utilities do not fulfill your needs.

  1. ```js
  2. import {ReduceStore} from 'flux/utils';

  3. class CounterStore extends ReduceStore<number> {
  4.   getInitialState(): number {
  5.     return 0;
  6.   }

  7.   reduce(state: number, action: Object): number {
  8.     switch (action.type) {
  9.       case 'increment':
  10.         return state + 1;

  11.       case 'square':
  12.         return state * state;

  13.       default:
  14.         return state;
  15.     }
  16.   }
  17. }
  18. ```

Check out the examples and documentation for more information.

Building Flux from a Cloned Repo


Clone the repo and navigate into the resulting flux directory. Then run npm install.

This will run Gulp-based build tasks automatically and produce the file Flux.js, which you can then require as a module.

You could then require the Dispatcher like so:

  1. ```javascript
  2. const Dispatcher = require('path/to/this/directory/Flux').Dispatcher;
  3. ```

The build process also produces de-sugared versions of the Dispatcher and invariant modules in a lib directory, and you can require those modules directly, copying them into whatever directory is most convenient for you. The flux-todomvc and flux-chat example applications both do this.

License


Flux is BSD-licensed. We also provide an additional patent grant.