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

Why unidirectional architecture matter for iOS.

DAloG
June 29, 2017

Why unidirectional architecture matter for iOS.

In this talk, I am trying to discover what factors make the unidirectional architectures more efficient for day to day development.

Screencast(Russian language): https://vimeo.com/224279675

DAloG

June 29, 2017
Tweet

More Decks by DAloG

Other Decks in Programming

Transcript

  1. DEBUGGING IS TWICE AS HARD AS WRITING A PROGRAM IN

    THE FIRST PLACE. Brian Kernighan "The Elements of Programming Style" (1980)
  2. SO?

  3. struct Quiz { struct Question { let text: String let

    answer: String? } let questions: [Question] }
  4. struct Quiz { struct Question { let text: String let

    answer: String? } let questions: [Question] let current: Question }
  5. struct Quiz { struct Question { let text: String let

    answer: String? } let previousQuestions: [Question] let current: Question let nextQuestions: [Question] }
  6. class APIClient { func requestQuiz() -> Future<Quiz> } let apiClient

    = APIClient() // or DI var quiz: Quiz? func refreshQuiz() { apiClient.requestQuiz().onComplete { quiz = $0 } }
  7. enum Effects { case requestQuiz((Quiz) -> Void) } func refreshQuiz()

    -> Effects { return Effects.requestQuiz { quiz = $0 } }
  8. func perform(effect: Effects) { switch effect { case .requestQuiz(let callback):

    apiClient.requestQuiz() .onComplete(action: callback) } }
  9. enum Effects { case requestQuiz((Quiz) -> Effects) case updateQuiz(Quiz) }

    func refreshQuiz() -> Effects { return Effects.requestQuiz(Effects.updateQuiz) }
  10. func perform(effect: Effects) { switch effect { case .requestQuiz(let callback):

    apiClient.requestQuiz().onComplete { perform(effect: callback($0)) } case .updateQuiz(let newQuiz): quiz = newQuiz } }
  11. struct Quiz { struct Question { let text: String let

    answer: String? } let previousQuestions: [Question] let current: Question let nextQuestions: [Question] }
  12. extension ViewController.Props { init(quiz: Quiz) { let allQuestions = quiz.previousQuestions

    + [quiz.current] + quiz.nextQuestions self.questions = allQuestions.map { ($0.text, $0.answer != nil) } } }