Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Atomic Architecture

Atomic Architecture

Dominic Barker

September 10, 2015
Tweet

More Decks by Dominic Barker

Other Decks in Programming

Transcript

  1. The best Single Page Application is the often the one

    that you were wise enough to not build.
  2. • Javascript is not the friendliest language in the world

    • Dynamic typing (ok that doesn’t have to be bad) • General weirdness, e. g. == vs === • No nice features, not even string interpolation • Awkward implementations of patterns, e.g. prototype based inheritance • protip: eschew inheritance altogether • Capricious run time environment, e. g. error handling
  3. • Browser compatibility. Still. • Immature tooling • grunt /

    gulp / broccoli / jake / ?? • Distributed • connectivity • failures • timeouts
  4. • huge numbers of possible interactions • all async! •

    feedback into the DOM • need to track all the data • need to maintain performance
  5. • Maps to a thing (REST resource) • Handles fetching

    and persistence • Serious business logic (like validation) Model / Collection
  6. • Actually called a View in Backbone (nice one) •

    Usually has an instance of a model • listens for events on the DOM (submit form) • listens for events on the model (change field) • decides what to do about them Controller
  7. • Actually called a Template in Backbone (nice one) •

    Renders html • Often accepts a model View
  8. Map

  9. • One great big blob of data - the atom

    / store • No models! • No behaviour, just data - hash, array, whatever • All in one place, no ambiguity • State is immutable (read only) • No classes, just pure functions
  10. • Use a reducer to handle the action • Reducers

    are pure functions • They accept the old state, and the action as parameters • They return a new version of the state, without modifying the original. • new state gets sent to the store, and an event is emitted
  11. • unidirectional dataflow • predictable state • action + data

    => new data • pure functions are easy to test • audit log of everything thats happened in the system • time travel! • restore state • debug • store on the server? • live collaboration