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

ReSwift / Unidirectional State Flow - Programmi...

ReSwift / Unidirectional State Flow - Programming Without Paradox

Avatar for Karl Bowden

Karl Bowden

March 17, 2016
Tweet

Other Decks in Programming

Transcript

  1. Unidirectional State Flow in Swift programming without paradox ! @KarlBowden

    " @MezzanineAU # karlbowden.com/reswift-prezzo @karlbowden
  2. What is Unidirectional State Flow Principles of state flow: •

    State only travels in one direction • State is immutable • State is modified by pure functions Source: redux.js.org/docs/introduction/ThreePrinciples.html @karlbowden
  3. What is State state, noun • the particular condition that

    someone or something is in at a specific time. • at a specific time @karlbowden
  4. What is an Application? Application: A set of instructions for

    interacting with a stream of states through time @karlbowden
  5. What is the problem? Maintainability • State (sources) in your

    View • State (streams) in your View Controller • STATE IN ALL THE THINGS @karlbowden
  6. Manages State Through Time FRP + Unidirectional State Flow +

    Swift = ReSwift • Store • State • Actions • Dispatch • Subscription • Reducers @karlbowden
  7. How does this fit into an application? Each application component

    is divided into: • Input and Output ~ State and Actions • Side effects ~ pushed to the edges • into Action Creators, Middleware and Services • State mutation: performed by Reducers @karlbowden
  8. This sounds messy ! and over complicated Karl! Why are

    you even still talking? ! My application handles state just fine because I'm a ! @karlbowden
  9. HERE BE DRAGONS ! Not applicable to every application First,

    try building your application without ReSwift Will a simple DIY store implementation suffice? @karlbowden
  10. When is ReSwift a good fit? • Applications where portions

    of state are used or changed in multiple components. • Ie, Battleships. One set of rules. Multiple different views of the same state. Multiple inputs. • Side effect handling • Dealing with one or more API's • External sources of actions • Push API's & WebSockets @karlbowden
  11. NOPES? • Simple applications that can already be reasoned about

    and tested • Large state. Ie, don't store images in the state tree, just use references • High performance gesture interactions • Don't create unthrottled actions for every touch event @karlbowden
  12. Common pitfalls • Reducers need to be fast • Avoid

    sorting arrays • Reducer should not cause side effects • I've got 99 problems, but globals ain't one of them • Globals / Singletons / Shared Instances still cause Coupling • Use coordinator + presenters @karlbowden
  13. HERE BE DRAGONS ⚔ OF AWESOME! • Routing • ReSwift-Router

    • Featherweight Router • Devtools / time travel • ReSwift-Recorder • Code injection • Injection4Xcode • KZPlayground @karlbowden
  14. Charter by Matthew Palmer Swift mailing list client for iOS

    Available in the App Store Open source by default, h/t Artsy github.com/matthewpalmer/Charter @karlbowden
  15. YOU CAN HALP! Join the discussion. Quick wins: Documentation. Know

    Japanese? Other implementations: Delta by Jake Craige at thoughtbot SwiftFlux by Kenichi Yonekawa @karlbowden
  16. Resources: github.com/ReSwift/ReSwift ReSwift documentation Benjamin Encz: Unidirectional Data Flow in

    Swift / Realm presentation Redux Dan Abramov: Getting Started with Redux on Egghead Special Thank You to: Aleksander Rendtslev - @ARendtslev Benjamin Encz - @benjaminencz @karlbowden
  17. Alternative titles Big in Japan Make state great again Hot

    State Time Machine Big Trouble in Little Gallifrey ALL YOUR STATE ARE BELONG TO US @karlbowden