Skip to content

Instantly share code, notes, and snippets.

@MatthewRDodds
Created November 16, 2015 14:31
Show Gist options
  • Save MatthewRDodds/b331a0fc0ad839eb93a8 to your computer and use it in GitHub Desktop.
Save MatthewRDodds/b331a0fc0ad839eb93a8 to your computer and use it in GitHub Desktop.
flux architecture review + comparison to redux

Redux Architecture Research

Researching patterns and components composing a flux architecture, and how they can be integrated current development processes.

Flux Architecture Review

Flux is the application architecture that Facebook uses for building client-side web applications. It complements React's composable view components by utilizing a unidirectional data flow.

Hint: Flux is more of an architecture pattern for managing the flow of data throughout a react application, rather than a framework

One popular implementation / extension of this architecture is DataFlux.

Components of an application that uses flux architecture:

Flux applications have three major parts: the dispatcher, the stores, and the views (React components).

Controller Views

Components at the top of the React Component hierarchy can often be called 'controller views' because they are usually the components responsible for retrieving data from the stores and passing them to children components.

When a controller-view receives an event from the store, it first requests the new data it needs via the stores' public getter methods. It then calls its own setState() or forceUpdate() methods, causing its render() method and the render() method of all its descendants to run.

Dispatcher

The dispatcher is the central hub that manages all data flow in a Flux application. It is essentially a registry of callbacks into the stores and has no real intelligence of its own — it is a simple mechanism for distributing the actions to the stores. Each store registers itself and provides a callback. When an action creator provides the dispatcher with a new action, all stores in the application receive the action via the callbacks in the registry.

Functions basically to translate actions into state changes in the stores.

Stores

Stores contain the application state and logic. A store manages the application state for a particular domain within the application.

Actions

The dispatcher exposes a method that allows us to trigger a dispatch to the stores, and to include a payload of data, which we call an action.

Introducing Redux

Comparison to Base Flux Architecture
  • Redux does not have an explicit Dispatcher you must interact with
  • Redux does not support many stores. Instead, there is just a single store with a single root reducing function. (As your app grows, instead of adding stores, you split the root reducer into smaller reducers independently operating on the different parts of the state tree.)

API

Redux exposes the following functions:

subscribe, dispatch, and getState

When defining actions, action functions essentially serve to provide nice wrappers around dispatch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment