⚠️ 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.

facebookarchive/flux

{
"props": {
"initialPayload": {
"allShortcutsEnabled": false,
"path": "/",
"repo": {
"id": 22046023,
"defaultBranch": "main",
"name": "flux",
"ownerLogin": "facebookarchive",
"currentUserCanPush": false,
"isFork": false,
"isEmpty": false,
"createdAt": "2014-07-20T23:33:08.000Z",
"ownerAvatar": "https://avatars.githubusercontent.com/u/7560860?v=4",
"public": true,
"private": false,
"isOrgOwned": true
},
"currentUser": null,
"refInfo": {
"name": "main",
"listCacheKey": "v0:1679378278.0",
"canEdit": false,
"refType": "branch",
"currentOid": "4ee8c50865c357e005cb40ea03cdd403533aad26"
},
"tree": {
"items": [
{
"name": ".github/workflows",
"path": ".github/workflows",
"contentType": "directory",
"hasSimplifiedPath": true
},
{
"name": "dist",
"path": "dist",
"contentType": "directory"
},
{
"name": "docs",
"path": "docs",
"contentType": "directory"
},
{
"name": "examples",
"path": "examples",
"contentType": "directory"
},
{
"name": "img",
"path": "img",
"contentType": "directory"
},
{
"name": "scripts",
"path": "scripts",
"contentType": "directory"
},
{
"name": "src",
"path": "src",
"contentType": "directory"
},
{
"name": "website",
"path": "website",
"contentType": "directory"
},
{
"name": ".gitignore",
"path": ".gitignore",
"contentType": "file"
},
{
"name": ".npmignore",
"path": ".npmignore",
"contentType": "file"
},
{
"name": ".prettierrc",
"path": ".prettierrc",
"contentType": "file"
},
{
"name": ".watchmanconfig",
"path": ".watchmanconfig",
"contentType": "file"
},
{
"name": "CHANGELOG.md",
"path": "CHANGELOG.md",
"contentType": "file"
},
{
"name": "CODE_OF_CONDUCT.md",
"path": "CODE_OF_CONDUCT.md",
"contentType": "file"
},
{
"name": "CONTRIBUTING.md",
"path": "CONTRIBUTING.md",
"contentType": "file"
},
{
"name": "Gulpfile.js",
"path": "Gulpfile.js",
"contentType": "file"
},
{
"name": "LICENSE",
"path": "LICENSE",
"contentType": "file"
},
{
"name": "README.md",
"path": "README.md",
"contentType": "file"
},
{
"name": "bower.json",
"path": "bower.json",
"contentType": "file"
},
{
"name": "index.js",
"path": "index.js",
"contentType": "file"
},
{
"name": "jest.config.js",
"path": "jest.config.js",
"contentType": "file"
},
{
"name": "package.json",
"path": "package.json",
"contentType": "file"
},
{
"name": "utils.js",
"path": "utils.js",
"contentType": "file"
},
{
"name": "yarn.lock",
"path": "yarn.lock",
"contentType": "file"
}
],
"templateDirectorySuggestionUrl": null,
"readme": null,
"totalCount": 24,
"showBranchInfobar": false
},
"fileTree": null,
"fileTreeProcessingTime": null,
"foldersToFetch": [],
"treeExpanded": false,
"symbolsExpanded": false,
"isOverview": true,
"overview": {
"banners": {
"shouldRecommendReadme": false,
"isPersonalRepo": false,
"showUseActionBanner": false,
"actionSlug": null,
"actionId": null,
"showProtectBranchBanner": false,
"publishBannersInfo": {
"dismissActionNoticePath": "/settings/dismiss-notice/publish_action_from_repo",
"releasePath": "/facebookarchive/flux/releases/new?marketplace=true",
"showPublishActionBanner": false
},
"interactionLimitBanner": null,
"showInvitationBanner": false,
"inviterName": null
},
"codeButton": {
"contactPath": "/contact",
"isEnterprise": false,
"local": {
"protocolInfo": {
"httpAvailable": true,
"sshAvailable": null,
"httpUrl": "https://github.com/facebookarchive/flux.git",
"showCloneWarning": null,
"sshUrl": null,
"sshCertificatesRequired": null,
"sshCertificatesAvailable": null,
"ghCliUrl": "gh repo clone facebookarchive/flux",
"defaultProtocol": "http",
"newSshKeyUrl": "/settings/ssh/new",
"setProtocolPath": "/users/set_protocol"
},
"platformInfo": {
"cloneUrl": "https://desktop.github.com",
"showVisualStudioCloneButton": false,
"visualStudioCloneUrl": "https://windows.github.com",
"showXcodeCloneButton": false,
"xcodeCloneUrl": "https://developer.apple.com",
"zipballUrl": "/facebookarchive/flux/archive/refs/heads/main.zip"
}
},
"newCodespacePath": "/codespaces/new?hide_repo_select=true&repo=22046023"
},
"popovers": {
"rename": null,
"renamedParentRepo": null
},
"commitCount": "506",
"overviewFiles": [
{
"displayName": "README.md",
"repoName": "flux",
"refName": "main",
"path": "README.md",
"preferredFileType": "readme",
"tabName": "README",
"richText": "<article class=\"markdown-body entry-content container-lg\" itemprop=\"text\"><div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"><g-emoji class=\"g-emoji\" alias=\"warning\">⚠️</g-emoji> The Flux project has been archived and no further changes will be made. We recommend using more sophisticated alternatives like <a href=\"http://redux.js.org/\" rel=\"nofollow\">Redux</a>, <a href=\"https://mobx.js.org/\" rel=\"nofollow\">MobX</a>, <a href=\"https://recoiljs.org/\" rel=\"nofollow\">Recoil</a>, <a href=\"https://github.com/pmndrs/zustand\">Zustand</a>, or <a href=\"https://github.com/pmndrs/jotai\">Jotai</a>.</h2><a id=\"user-content-️-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\" class=\"anchor\" aria-label=\"Permalink: ⚠️ 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.\" href=\"#️-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\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p align=\"center\" dir=\"auto\">\n <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://github.com/facebookarchive/flux/blob/main/website/static/img/flux-logo-color.svg\"><img src=\"https://github.com/facebookarchive/flux/raw/main/website/static/img/flux-logo-color.svg\" alt=\"logo\" width=\"20%\" style=\"max-width: 100%;\"></a>\n</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h1 align=\"center\" tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">\n Flux\n</h1><a id=\"user-content---flux\" class=\"anchor\" aria-label=\"Permalink: \n Flux\n\" href=\"#--flux\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p align=\"center\" dir=\"auto\">\n An application architecture for React utilizing a unidirectional data flow.<br>\n <a href=\"https://github.com/facebook/flux/blob/master/LICENSE\">\n <img src=\"https://camo.githubusercontent.com/162e74fb8c6b3aee3720f958a49db0f3362d908559a790eb3a4d554377e10c81/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4253442532302d626c75652e737667\" alt=\"Licence Badge\" data-canonical-src=\"https://img.shields.io/badge/License-BSD%20-blue.svg\" style=\"max-width: 100%;\">\n </a>\n <a href=\"https://www.npmjs.com/package/flux\" rel=\"nofollow\">\n <img src=\"https://camo.githubusercontent.com/67b7ebbe48c78d4f56ca1809fac81243b4623518bae8546bc9ed6ebc17cd6d46/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f666c75782e7376673f7374796c653d666c6174\" alt=\"Current npm package version.\" data-canonical-src=\"https://img.shields.io/npm/v/flux.svg?style=flat\" style=\"max-width: 100%;\">\n </a>\n</p>\n<hr>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"/facebookarchive/flux/blob/main/img/flux-diagram-white-background.png\"><img src=\"/facebookarchive/flux/raw/main/img/flux-diagram-white-background.png\" style=\"width: 100%; max-width: 100%;\"></a></p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Getting Started</h2><a id=\"user-content-getting-started\" class=\"anchor\" aria-label=\"Permalink: Getting Started\" href=\"#getting-started\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Start by looking through the <a href=\"/facebookarchive/flux/blob/main/examples\">guides and examples</a> on Github. For more resources and API docs check out <a href=\"https://facebookarchive.github.io/flux\" rel=\"nofollow\">facebook.github.io/flux</a>.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">How Flux works</h2><a id=\"user-content-how-flux-works\" class=\"anchor\" aria-label=\"Permalink: How Flux works\" href=\"#how-flux-works\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">For more information on how Flux works check out the <a href=\"/facebookarchive/flux/blob/main/examples/flux-concepts\">Flux Concepts</a> guide, or the <a href=\"https://facebookarchive.github.io/flux/docs/in-depth-overview\" rel=\"nofollow\">In Depth Overview</a>.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Requirements</h2><a id=\"user-content-requirements\" class=\"anchor\" aria-label=\"Permalink: Requirements\" href=\"#requirements\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Flux is more of a pattern than a framework, and does not have any hard dependencies. However, we often use <a href=\"https://nodejs.org/api/events.html#events_class_eventemitter\" rel=\"nofollow\">EventEmitter</a> as a basis for <code>Stores</code> and <a href=\"https://github.com/facebook/react\">React</a> for our <code>Views</code>. The one piece of Flux not readily available elsewhere is the <code>Dispatcher</code>. This module, along with some other utilities, is available here to complete your Flux toolbox.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Installing Flux</h2><a id=\"user-content-installing-flux\" class=\"anchor\" aria-label=\"Permalink: Installing Flux\" href=\"#installing-flux\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Flux is available as a <a href=\"https://www.npmjs.org/package/flux\" rel=\"nofollow\">npm module</a>, so you can add it to your package.json file or run <code>npm install flux</code>. The dispatcher will be available as <code>Flux.Dispatcher</code> and can be required like this:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const Dispatcher = require('flux').Dispatcher;\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-v\">Dispatcher</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'flux'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">Dispatcher</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">Take a look at the <a href=\"https://facebookarchive.github.io/flux/docs/dispatcher\" rel=\"nofollow\">dispatcher API and some examples</a>.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Flux Utils</h2><a id=\"user-content-flux-utils\" class=\"anchor\" aria-label=\"Permalink: Flux Utils\" href=\"#flux-utils\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">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 <strong>not</strong> 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.</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"import {ReduceStore} from 'flux/utils';\n\nclass CounterStore extends ReduceStore&lt;number&gt; {\n getInitialState(): number {\n return 0;\n }\n\n reduce(state: number, action: Object): number {\n switch (action.type) {\n case 'increment':\n return state + 1;\n\n case 'square':\n return state * state;\n\n default:\n return state;\n }\n }\n}\"><pre><span class=\"pl-k\">import</span> <span class=\"pl-kos\">{</span><span class=\"pl-v\">ReduceStore</span><span class=\"pl-kos\">}</span> <span class=\"pl-k\">from</span> <span class=\"pl-s\">'flux/utils'</span><span class=\"pl-kos\">;</span>\n\n<span class=\"pl-k\">class</span> <span class=\"pl-v\">CounterStore</span> <span class=\"pl-k\">extends</span> <span class=\"pl-v\">ReduceStore</span><span class=\"pl-c1\">&lt;</span><span class=\"pl-s1\">number</span><span class=\"pl-c1\">&gt;</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-c1\">getInitialState</span><span class=\"pl-kos\">(</span><span class=\"pl-kos\">)</span>: <span class=\"pl-s1\">number</span> <span class=\"pl-kos\">{</span>\n return <span class=\"pl-c1\">0</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-kos\">}</span>\n\n <span class=\"pl-s1\">reduce</span><span class=\"pl-kos\">(</span><span class=\"pl-s1\">state</span>: <span class=\"pl-s1\">number</span><span class=\"pl-kos\">,</span> <span class=\"pl-c1\">action</span>: <span class=\"pl-v\">Object</span><span class=\"pl-kos\">)</span>: <span class=\"pl-s1\">number</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-en\">switch</span> <span class=\"pl-kos\">(</span><span class=\"pl-s1\">action</span><span class=\"pl-kos\">.</span><span class=\"pl-s1\">type</span><span class=\"pl-kos\">)</span> <span class=\"pl-kos\">{</span>\n <span class=\"pl-s1\">case</span> <span class=\"pl-s\">'increment'</span>:\n <span class=\"pl-k\">return</span> <span class=\"pl-s1\">state</span> <span class=\"pl-c1\">+</span> <span class=\"pl-c1\">1</span><span class=\"pl-kos\">;</span>\n\n <span class=\"pl-s1\">case</span><span class=\"pl-kos\"></span> <span class=\"pl-s\">'square'</span>:\n <span class=\"pl-k\">return</span> <span class=\"pl-s1\">state</span> <span class=\"pl-c1\">*</span> <span class=\"pl-s1\">state</span><span class=\"pl-kos\">;</span>\n\n default:\n <span class=\"pl-k\">return</span> <span class=\"pl-s1\">state</span><span class=\"pl-kos\">;</span>\n <span class=\"pl-kos\">}</span>\n <span class=\"pl-kos\">}</span>\n<span class=\"pl-kos\">}</span></pre></div>\n<p dir=\"auto\">Check out the <a href=\"/facebookarchive/flux/blob/main/examples\">examples</a> and <a href=\"https://facebookarchive.github.io/flux/docs/flux-utils\" rel=\"nofollow\">documentation</a> for more information.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">Building Flux from a Cloned Repo</h2><a id=\"user-content-building-flux-from-a-cloned-repo\" class=\"anchor\" aria-label=\"Permalink: Building Flux from a Cloned Repo\" href=\"#building-flux-from-a-cloned-repo\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Clone the repo and navigate into the resulting <code>flux</code> directory. Then run <code>npm install</code>.</p>\n<p dir=\"auto\">This will run <a href=\"https://gulpjs.com/\" rel=\"nofollow\">Gulp</a>-based build tasks automatically and produce the file Flux.js, which you can then require as a module.</p>\n<p dir=\"auto\">You could then require the Dispatcher like so:</p>\n<div class=\"highlight highlight-source-js notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"const Dispatcher = require('path/to/this/directory/Flux').Dispatcher;\"><pre><span class=\"pl-k\">const</span> <span class=\"pl-v\">Dispatcher</span> <span class=\"pl-c1\">=</span> <span class=\"pl-en\">require</span><span class=\"pl-kos\">(</span><span class=\"pl-s\">'path/to/this/directory/Flux'</span><span class=\"pl-kos\">)</span><span class=\"pl-kos\">.</span><span class=\"pl-c1\">Dispatcher</span><span class=\"pl-kos\">;</span></pre></div>\n<p dir=\"auto\">The build process also produces de-sugared versions of the <code>Dispatcher</code> and <code>invariant</code> modules in a <code>lib</code> directory, and you can require those modules directly, copying them into whatever directory is most convenient for you. The <code>flux-todomvc</code> and <code>flux-chat</code> example applications both do this.</p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\">License</h2><a id=\"user-content-license\" class=\"anchor\" aria-label=\"Permalink: License\" href=\"#license\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>\n<p dir=\"auto\">Flux is BSD-licensed. We also provide an additional patent grant.</p>\n</article>",
"loaded": true,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": [
{
"level": 2,
"text": "⚠️ 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.",
"anchor": "️-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",
"htmlText": "⚠️ 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."
},
{
"level": 1,
"text": "\n Flux\n",
"anchor": "--flux",
"htmlText": "\n Flux\n"
},
{
"level": 2,
"text": "Getting Started",
"anchor": "getting-started",
"htmlText": "Getting Started"
},
{
"level": 2,
"text": "How Flux works",
"anchor": "how-flux-works",
"htmlText": "How Flux works"
},
{
"level": 2,
"text": "Requirements",
"anchor": "requirements",
"htmlText": "Requirements"
},
{
"level": 2,
"text": "Installing Flux",
"anchor": "installing-flux",
"htmlText": "Installing Flux"
},
{
"level": 2,
"text": "Flux Utils",
"anchor": "flux-utils",
"htmlText": "Flux Utils"
},
{
"level": 2,
"text": "Building Flux from a Cloned Repo",
"anchor": "building-flux-from-a-cloned-repo",
"htmlText": "Building Flux from a Cloned Repo"
},
{
"level": 2,
"text": "License",
"anchor": "license",
"htmlText": "License"
}
],
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2Ffacebookarchive%2Fflux"
}
},
{
"displayName": "CODE_OF_CONDUCT.md",
"repoName": "flux",
"refName": "main",
"path": "CODE_OF_CONDUCT.md",
"preferredFileType": "code_of_conduct",
"tabName": "Code of conduct",
"richText": null,
"loaded": false,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": null,
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2Ffacebookarchive%2Fflux"
}
},
{
"displayName": "LICENSE",
"repoName": "flux",
"refName": "main",
"path": "LICENSE",
"preferredFileType": "license",
"tabName": "License",
"richText": null,
"loaded": false,
"timedOut": false,
"errorMessage": null,
"headerInfo": {
"toc": null,
"siteNavLoginPath": "/login?return_to=https%3A%2F%2Fgithub.com%2Ffacebookarchive%2Fflux"
}
}
],
"overviewFilesProcessingTime": 0
}
},
"appPayload": {
"helpUrl": "https://docs.github.com",
"findFileWorkerPath": "/assets-cdn/worker/find-file-worker-1583894afd38.js",
"findInFileWorkerPath": "/assets-cdn/worker/find-in-file-worker-3a63a487027b.js",
"githubDevUrl": null,
"enabled_features": {
"code_nav_ui_events": false,
"overview_shared_code_dropdown_button": false,
"react_blob_overlay": false,
"copilot_conversational_ux_embedding_update": false,
"copilot_smell_icebreaker_ux": true,
"copilot_workspace": false
}
}
}
}
{
"accept-ranges": "bytes",
"cache-control": "max-age=0, private, must-revalidate",
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'; base-uri 'self'; child-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com api.githubcopilot.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com/v1/engines/github-completion/completions proxy.enterprise.githubcopilot.com/v1/engines/github-completion/completions *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/",
"content-type": "text/html; charset=utf-8",
"date": "Sat, 27 Jul 2024 03:24:51 GMT",
"etag": "b46b54bef5c64f9f0eff40a1ecfd18a2",
"referrer-policy": "no-referrer-when-downgrade",
"server": "GitHub.com",
"set-cookie": "logged_in=no; Path=/; Domain=github.com; Expires=Sun, 27 Jul 2025 03:24:51 GMT; HttpOnly; Secure; SameSite=Lax",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"transfer-encoding": "chunked",
"vary": "X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Encoding, Accept, X-Requested-With",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-request-id": "85C8:2641B2:4120B2:530418:66A46883",
"x-xss-protection": "0"
}