Re-architecting the client with Flux

@alex.n.moldovan

medium.com/@alexnm

Presentation vs State

Enemies of separation

Two-way Binding

View-Models / Controllers

"Code behind"

Enter Flux

Event

Emitter

State

Presentation

Stores

Dispatcher

Actions

Views

Simple Counter

Dispatcher.dispatch( { type: "INCREMENT" } );
Dispatcher.register( function( action ) {
    switch ( action.type ) {
        case "INCREMENT":
            counter++;
            Store.emitChange( );
            break;
        case "DECREMENT":
            counter--;
            Store.emitChange( );
    }
}

Demo app: https://github.com/alexnm/counter-flux

React.js

Thinking in React

Product Store

Cart Store

Dispatcher

dispatch

emit

emit

dispatch

dispatch

Handling async events

Dispatcher

Stores

Action Creators

ADD_TO_CART

API Endpoint

request

response

ADD_TO_CART_COMPLETED

Evolution of flux

Reflux

X

Store

Dispatcher

Action

View

Stores

Redux

Store

Action

View

Reducer

Benefits

Separation of Concerns

One-way Flows

Visibility

Scalability

Pitfalls

Synchronizing Events

Server Side Rendering

Over-engineering

Changing Standards

"Not only are things changing quickly, the rate at which things are changing is changing quickly.", Eric Elliott

Angular 2 on Flux

Ember on Flux

Flux is part of the future

Thank you!

Questions?

@alex.n.moldovan

medium.com/@alexnm

Hello.js 2016 - Re-architecting the client with Flux

By Alex Moldovan

Hello.js 2016 - Re-architecting the client with Flux

Deck for hello.js conference

  • 1,571