Scaling Flux

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Scaling Flux

Flux is a great for managing data across your React application; however, when apps grow in complexity Flux can become unruly. Stores quickly develop messy dependencies with each other and it becomes extremely difficult to reason about your application. While developing a highly extensible email client we found an extremely effective way to manage Store complexity was to consolidate data into singular Centralized Data Store. It became a single source of truth that made our app easier to reason about, more robust, and scalable.

This was a talk for the React NYC Meetup on May 28, 2015.

Evan Morikawa

May 28, 2015

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

48 slides
  1. MessageStore = Reflux.createStore init: -> @listenTo Actions.expandMessage, @onExpandMessage @listenTo DraftStore,

    @updateAndTrigger @listenTo ThreadStore, @updateAndTrigger updateAndTrigger: -> … @trigger()
  2. MessageStore = Reflux.createStore init: -> @listenTo Actions.expandMessage, @onExpandMessage @listenTo DraftStore,

    @updateAndTrigger @listenTo ThreadStore, @updateAndTrigger @listenTo websocket, @updateAndTrigger updateAndTrigger: -> … @trigger()
  3. class MessageList extends React.Component render: -> … @state.messages.map (msg) ->

    <MessageItem msg={msg} /> componentDidMount: -> MessageStore.listen @onStoreChange
  4. class MessageList extends React.Component render: -> … @state.messages.map (msg) ->

    <MessageItem msg={msg} /> componentDidMount: -> MessageStore.listen @onStoreChange onStoreChange: -> @setState @getStateFromMessageStore()
  5. class MessageList extends React.Component render: -> … @state.messages.map (msg) ->

    <MessageItem msg={msg} /> componentDidMount: -> MessageStore.listen @onStoreChange onStoreChange: -> @setState @getStateFromMessageStore() getStateFromMessageStore: -> messages: MessageStore.messagesFor(@props.threadId)
  6. class MessageList extends React.Component render: -> … @state.messages.map (msg) ->

    <MessageItem msg={msg} /> componentDidMount: -> MessageStore.listen @onStoreChange onStoreChange: -> @setState @getStateFromMessageStore() getStateFromMessageStore: -> messages: MessageStore.messagesFor(@props.threadId) constructor: (@props) -> @state = @getStateFromMessageStore()

More Decks by Evan Morikawa

Other Decks in Technology