flux README

The project's README from github.com/facebookarchive/flux. As one markdown file: README.md.

⚠️ The Flux project has been archived and no further changes will be made. We recommend using more sophisticated alternatives like Redux, MobX, Recoil, Zustand, or Jotai.

logo

Flux

An application architecture for React utilizing a unidirectional data flow.
Licence Badge Current npm package version.


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 for Stores and React for our Views. 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 run npm install flux. The dispatcher will be available as Flux.Dispatcher and can be required like this:

const Dispatcher = require('flux').Dispatcher;

Take a look at the dispatcher API and some examples.

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.

import {ReduceStore} from 'flux/utils';

class CounterStore extends ReduceStore<number> {
  getInitialState(): number {
    return 0;
  }

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

      case 'square':
        return state * state;

      default:
        return state;
    }
  }
}

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:

const Dispatcher = require('path/to/this/directory/Flux').Dispatcher;

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.

flux (facebookarchive/flux)

Searching Database…

17.4K ·GitHub
archived
What is this?Flux is an application architecture for building user interfaces with React, centered on a unidirectional data flow.
Is Flux a framework or a library?Neither exactly — the README calls it more of a pattern than a framework, with no hard dependencies. The npm package mainly contributes the Dispatcher plus a few utility classes.
How do I get it into my project?Run npm install flux or add it to your package.json; the dispatcher then becomes available as Flux.Dispatcher. Docs and API references live at facebook.github.io/flux.
Do I need anything else, like React, to use it?Nothing is a hard requirement — Flux is a pattern. In practice it pairs EventEmitter-based Stores with React views, and the package itself depends on fbjs and fbemitter.
Is Flux still actively developed?No — the project is archived and no further changes will be made. You can still install it, but the team recommends newer alternatives instead.
Can I use Flux in commercial projects?Yes — Flux is BSD-licensed, and Facebook provides an additional patent grant on top of that.
What is the Dispatcher and why does it come from this package?It is the one piece of Flux you cannot easily find elsewhere, so the npm package ships it as Flux.Dispatcher along with other utilities to complete your Flux toolbox.
What are the Flux Utils classes?Basic base classes that give a simple Flux application a solid starting point. They are deliberately not a feature-complete framework — for more than that, the README points to other Flux frameworks and the examples.
Are there example apps to learn from?Yes — the repo includes flux-todomvc and flux-chat, and the GitHub page links to more guides and examples. The Flux Concepts guide and the In Depth Overview explain how it all works.
What should I pick instead for a new project?The archived notice names Redux, MobX, Recoil, Zustand, and Jotai as more sophisticated alternatives — for anything new, those are the safer choice since Flux will not change.
What are similar projects?Recoil, redux-form, nuqs, material, immer, hyperapp, normalizr, velocity
Size
5.4 MB
Stars
17.4K
Age
12y
Commits · 90 Days