- Notifications
You must be signed in to change notification settings - Fork3.4k
Application Architecture for Building User Interfaces
License
facebookarchive/flux
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
⚠️ The Flux project has been archived and no further changes will be made. We recommend using more sophisticated alternatives likeRedux,MobX,Recoil,Zustand, orJotai.
An application architecture for React utilizing a unidirectional data flow.
Start by looking through theguides and examples on Github. For more resources and API docs check outfacebook.github.io/flux.
For more information on how Flux works check out theFlux Concepts guide, or theIn Depth Overview.
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.
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.
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.
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.
Flux is BSD-licensed. We also provide an additional patent grant.
About
Application Architecture for Building User Interfaces