⚠️ The Flux project has been archived and no further changes will be made. We recommend using more sophisticated alternatives likeRedux,MobX,Recoil,Zustand, orJotai.
Flux
An application architecture for React utilizing a unidirectional data flow.
Getting Started
Start by looking through theguides and examples on Github. For more resources and API docs check outfacebook.github.io/flux.
How Flux works
For more information on how Flux works check out theFlux Concepts guide, or theIn Depth Overview.
Requirements
Flux is more of a pattern than a framework, and does not have any hard dependencies. However, we often useEventEmitter as a basis forStores
andReact for ourViews
. The one piece of Flux not readily available elsewhere is theDispatcher
. This module, along with some other utilities, is available here to complete your Flux toolbox.
Installing Flux
Flux is available as anpm module, so you can add it to your package.json file or runnpm install flux
. The dispatcher will be available asFlux.Dispatcher
and can be required like this:
constDispatcher=require('flux').Dispatcher;
Take a look at thedispatcher 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 arenot 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';classCounterStoreextendsReduceStore<number>{getInitialState():number{ return0;}reduce(state:number,action:Object):number{switch(action.type){case'increment':returnstate+1;case'square':returnstate*state; default:returnstate;}}}
Check out theexamples anddocumentation for more information.
Building Flux from a Cloned Repo
Clone the repo and navigate into the resultingflux
directory. Then runnpm install
.
This will runGulp-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:
constDispatcher=require('path/to/this/directory/Flux').Dispatcher;
The build process also produces de-sugared versions of theDispatcher
andinvariant
modules in alib
directory, and you can require those modules directly, copying them into whatever directory is most convenient for you. Theflux-todomvc
andflux-chat
example applications both do this.
License
Flux is BSD-licensed. We also provide an additional patent grant.
Package Sidebar
Install
npm i flux
Repository
Homepage
Weekly Downloads
801,579
Version
4.0.4
License
BSD-3-Clause
Unpacked Size
260 kB
Total Files
29