Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MVI (Model-View-Intention)
Search
Kapil Rathore
February 29, 2020
Programming
1
73
MVI (Model-View-Intention)
Presented on 29 February 2020 at Swift India.
https://www.meetup.com/Swift-Delhi/events/268573479/
Kapil Rathore
February 29, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
620
童醫院敏捷轉型的實踐經驗
cclai999
0
200
Benchmark
sysong
0
270
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
150
Rubyでやりたい駆動開発 / Ruby driven development
chobishiba
1
490
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
340
XP, Testing and ninja testing
m_seki
3
210
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
140
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
230
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
660
Is Xcode slowly dying out in 2025?
uetyo
1
210
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
1.3k
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
The Invisible Side of Design
smashingmag
300
51k
Six Lessons from altMBA
skipperchong
28
3.9k
A designer walks into a library…
pauljervisheath
207
24k
Visualization
eitanlees
146
16k
Adopting Sorbet at Scale
ufuk
77
9.4k
Balancing Empowerment & Direction
lara
1
380
BBQ
matthewcrist
89
9.7k
Music & Morning Musume
bryan
46
6.6k
4 Signs Your Business is Dying
shpigford
184
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Producing Creativity
orderedlist
PRO
346
40k
Transcript
Kapil Rathore iOS @ Tokopedia MVI (Model-View-Intention) Reactive Unidirectional Architecture
for your Apps @krkapilrathore @krkapilrathore @kapilrathore
What are you doing this weekend ? ♂
♂ I’m attending Swift Delhi Meetup
♂ Should I also join ?
♂ Sure, it’ll be fun !!
♂
♂ ⌨ INPUT OUTPUT OUTPUT INPUT
♂ ⌨ View ( ) User ( ) Model (
) Intention ( )
user ( )
intention ( user ( ) )
model ( intention ( user ( ) ) )
view ( model ( intention ( user ( ) )
) )
view ( model ( intention ( ) ) )
Pure Functions
Pure Functions ✅ ❌
Intention • Take the inputs from the user • Map
the user inputs to Model friendly events • Eg - button click events, text input events etc.
Model • Take the inputs from Intention • Processes a
particular business Usecase based on the input • Produces a New State as an output • Only piece of code that is allowed to change the State
• Immutable data structure • Holds all the important information
required to change the dynamic data on the UI layer • Acts as the single source of truth State
• Takes the output State produced by the Model as
input • Contains the rendering logic for the emitted state View
Rx Operators that we are going to use
Observable Sequence
None
None
None
Talk is cheap. Show me the code. - Linus Torvalds
Example App Counter MVI
Planning Intentions • Increment • Decrement • Reset Counter •
Interval Change
Code Intentions
Planning State • Count Value • Interval
Code State
Planning Model Usecases • Increment Usecase • Decrement Usecase •
Reset Counter Usecase • Interval Change Usecase
Code Increment Usecase
Code State
Code Decrement Usecase
Code Reset Counter Usecase
Code Interval Change Usecase
Intention View Different Model Usecases
BIND function - Model
Code View
Glue Code Outlets
Glue Code Initialize MVI Components
Glue Code Binding the MVI Components
Glue Code Implement the View Layer
Live Preview in Simulator
Summary Pros • Unidirectional & Cyclic Flow of Data •
Decoupled Code • Predictable (Pure functions + Immutable States) • Highly Testable & Debuggable (Encourages TDD) • User Centric (User drives the architecture) • Reactive (Handles the async code) • Platform Agnostic (Cross platform collaboration)
Summary Cons • Lots of Boilerplate • Where to place
navigation logic • Complexity (Learning Curve)
What’s Next + Combine Cook MVI using SwiftUI and Combine
References • What if the user was a function? by
Andre Staltz at JSConf Budapest 2015 • Managing State with RxJava by Jake Wharton • Mobius by Spotify • MVI Series: A Pragmatic Reactive Architecture for Android
Kapil Rathore iOS @ Tokopedia Questions @krkapilrathore @krkapilrathore @kapilrathore
Kapil Rathore iOS @ Tokopedia Thank You @krkapilrathore @krkapilrathore @kapilrathore