Slide 1

Slide 1 text

From App Architecture to Brewing Coffee: Unidirectional Data Flow By Jacqueline Sloves @jacquelionroars @jacquelion

Slide 2

Slide 2 text

Who am I? ● Lead iOS Engineer at Vida Health ● Originally studied Philosophy at UC Berkeley ● Turned to learning to code after returning from Peace Corps Ukraine ● Began with JavaScript, and then specialized in iOS mobile development ● When I'm not coding, I enjoy running, biking, and skiing (weather permitting) @jacquelionroars

Slide 3

Slide 3 text

Who are you? ● Web vs Mobile developers? ● # of years of experience? ● Size of company? @jacquelionroars

Slide 4

Slide 4 text

Agenda for today I. What is MVC, and what challenges it presents II. What is MVVM unidirectional data flow, and what problems does it solve III. A Vida case study: how we began changing our app's architecture @jacquelionroars

Slide 5

Slide 5 text

Objectives of the talk today ● High-level understanding of MVVM unidirectional data flow ● Benefits of incorporating MVVM unidirectional data flow ● Concrete tips on how to begin changing your app's architecture @jacquelionroars

Slide 6

Slide 6 text

When it clicked... I was brewing coffee, and had just acquired new appliances (fancy grinder and milk steamer, and set them up like so: Milk steamer Coffee brewer Coffee Grinder I was going back-and-forth to each of these appliances, and then I realized… if I had unidirectional way to manage this process, my life would be so much better! @jacquelionroars

Slide 7

Slide 7 text

@jacquelionroars

Slide 8

Slide 8 text

What is non unidirectional data flow? and where you may have seen it… Classic Model-View-Controller Architecture @jacquelionroars

Slide 9

Slide 9 text

When MVC Works @jacquelionroars

Slide 10

Slide 10 text

When MVC goes wrong... @jacquelionroars

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Problems with classic MVC Architecture MVC is fondly referred to as... Massive View Controller ● Difficult to test ● There is no longer a separation of concerns ○ view controller maintains application state, ○ and acts a mediator between the view and model ● Difficult to manage state between view controllers ○ If you have an if statement, you're managing state @jacquelionroars

Slide 13

Slide 13 text

Do not fear the unknown @jacquelionroars

Slide 14

Slide 14 text

Proponents of Unidirectional Data Flow @jacquelionroars

Slide 15

Slide 15 text

Unidirectional MVVM architecture explained @jacquelionroars

Slide 16

Slide 16 text

Unidirectional MVVM architecture explained 1. The ViewController is purely the View 2. The ViewModel doesn't know the View exists, but is bound to it 3. The View owns the ViewModel, which in turn owns the Model (no tight coupling between the View and the Model) 4. The ViewModel is responsible for updating the Model 5. Thus, when a property is updated on the Model, it notifies the ViewModel, which invokes a callback function that updates the View @jacquelionroars

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Benefits of Unidirectional data flow ● Improved separation of concerns ● Declarative statements ● Expected results ● Testable ● Can manage state across view controllers ● Extendable @jacquelionroars

Slide 20

Slide 20 text

How to change an existing architecture @jacquelionroars

Slide 21

Slide 21 text

A Case Study ● New engineers ● Developing a new end-to-end feature ● Hammock-Driven Development ● Came to consensus on 3 things: ○ Incorporating tests ○ Single Responsibility Principle ○ Dividing the project into smaller tasks @jacquelionroars

Slide 22

Slide 22 text

A Case Study (cont'd) Our 3 Mini-Projects: 1. Isolate the networking layer from the ViewController 2. Separate routing logic from ViewController 3. Bind data through ViewModels ● Don't break anything that already works ● Take one new end-to-end user-facing feature as a starting point @jacquelionroars

Slide 23

Slide 23 text

A Case Study (cont'd) Challenges: ● Agreeing on how to implement each project ● Writing tests ● Being OK with making mistakes ● Timeline @jacquelionroars

Slide 24

Slide 24 text

Take-aways ● Challenges of multiple states being managed by a single ViewController ● Benefits of MVVM unidirectional data flow ● Implications for testability and extensibility ● Strategy to implement something new ● You can do it! @jacquelionroars

Slide 25

Slide 25 text

Further Reading & Resources https://www.exclamationlabs.com/blog/the-case-for-unidirectional-data-flow/ https://realm.io/news/benji-encz-unidirectional-data-flow-swift/ https://teamtreehouse.com/library/unidirectional-data-flow https://medium.com/@AdamRNeary/unidirectional-data-flow-yes-flux-i-am-not-so-sure-b4acf988196c @jacquelionroars

Slide 26

Slide 26 text

Keep in Touch! [email protected] @jacquelionroars @jacquelion Thanks for attending. Happy Coding :)