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
这是干什么的?Flux 是一种应用架构,用于配合 React 构建用户界面,核心是单向数据流。
Flux 是框架还是库?严格说都不算——README 把它称为一种模式(pattern)而非框架,没有任何硬性依赖。npm 包主要提供 Dispatcher 以及一些工具类。
怎么把它装到我的项目里?运行 npm install flux,或者把它加到你的 package.json 里;之后就可以通过 Flux.Dispatcher 使用 dispatcher。文档和 API 参考在 facebook.github.io/flux。
使用它还需要别的东西吗,比如 React?没有硬性要求——Flux 只是一种模式。实际使用中,它通常把基于 EventEmitter 的 Store 和 React 视图搭配使用,而这个包本身依赖 fbjs 和 fbemitter。
Flux 还在积极开发吗?没有了——项目已经归档,不会再有任何改动。你仍然可以安装它,但团队建议改用更新的替代方案。
我可以在商业项目中使用 Flux 吗?可以——Flux 采用 BSD 许可证,Facebook 还在此基础上额外提供了专利授权。
Dispatcher 是什么?为什么它来自这个包?它是 Flux 中你在别处很难找到的那一部分,所以 npm 包把它作为 Flux.Dispatcher 提供,并附带其他工具,凑齐你的 Flux 工具箱。
Flux Utils 类是什么?一些基础类,为一个简单的 Flux 应用提供扎实的起点。它们刻意不做功能完备的框架——如果需要更多功能,README 指向了其他 Flux 框架和示例。
有可以学习的示例应用吗?有——仓库里包含 flux-todomvc 和 flux-chat,GitHub 页面上还链接了更多指南和示例。Flux Concepts 指南和 In Depth Overview 会讲解它的整体原理。
新项目我应该改用什么?归档通知点名了 Redux、MobX、Recoil、Zustand 和 Jotai 作为更成熟的替代方案——凡是新项目,选它们更稳妥,因为 Flux 不会再更新了。
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