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
Simplifying State by partially introducing unid...
Search
Benedikt Terhechte
October 13, 2017
Programming
3
970
Simplifying State by partially introducing unidirectional data flow in your codebase
Benedikt Terhechte
October 13, 2017
Tweet
Share
More Decks by Benedikt Terhechte
See All by Benedikt Terhechte
Back to the Future: Let me tell you about the ACP protocol
terhechte
0
210
NSSpain 2023: An overview of different approaches to share code across platforms
terhechte
0
460
Dependency Management with Swift
terhechte
0
12
NSSpain 2020: GeometryReader, View Preferences and Anchors - SwiftUI tales from the Hyperdeck
terhechte
0
10
FrenchKit 2020: Hyperdeck. What can go wrong on a multiyear side project
terhechte
0
9
SwiftUI & UIKit, a match made in heaven or match made in hell?
terhechte
0
86
Learnings from building Design Systems at XING
terhechte
1
530
Introduction to Swift Keypaths
terhechte
15
20k
Sharing Code between iOS and Android with Rust
terhechte
8
2.5k
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
640
Developing static sites with Ruby
okuramasafumi
1
340
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
470
クラウドに依存しないS3を使った開発術
simesaba80
0
220
.NET Conf 2025 の興味のあるセッ ションを復習した / dotnet conf 2025 quick recap for backend engineer
tomohisa
0
110
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
38k
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
160
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
420
Graviton と Nitro と私
maroon1st
0
160
Python札幌 LT資料
t3tra
7
1.1k
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
4
1.1k
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
1k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Side Projects
sachag
455
43k
Typedesign – Prime Four
hannesfritz
42
2.9k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
2
280
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
76
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
530
Game over? The fight for quality and originality in the time of robots
wayneb77
1
74
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The SEO Collaboration Effect
kristinabergwall1
0
320
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
110
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
220
Thoughts on Productivity
jonyablonski
73
5k
Transcript
1
2
3
4
5
6
7
8
9
None
10
11
12
13
14
None
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// Model struct Cinnamon { let value: Int = 0
} enum Event { case increase } 45
/// Model struct Cinnamon { let value: Int = 0
} enum Event { case increase } func reducer(state: Cinnamon, event: Event) -> Cinnamon { var newState = state if event == .increase { newState.value += 1 } return newState } /// UI let builder = Form(state: Cinnamon(), reducer: reducer) 46
47
48
49
struct AddressBook { var contacts: [Person] var searchTerm: String var
scrollPosition: Int } 50
struct AddressBookApp { struct Data { var contacts: [Person] }
var data: Data struct UI { var searchTerm: String var scrollPosition: Int } var ui: UI } 51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
private var subscribers: [String: (State)->Void] = [:] public func subscribe(_
subscriber: @escaping (State)->Void) -> String { let token = UUID().uuidString subscribers[token] = subscriber subscriber(state) return token } 66
67
protocol FormComponent { associatedtype State func setup(with state: State) func
update(state: State) -> Void } public func subscribe<Component: FormComponent> (_ subscriber: Component) -> String where Component.State == State {... 68
69
func subscribe<Type: Equatable>( path: KeyPath<Data, Type>, action: @escaping (_ oldValue:
Type, _ newValue: Type) -> Void ) -> String struct Person { let name: String } form.subscribe(path: \Person.name) { (old, new) in ... } 70
private var history: [State] = [] func apply(_ change: (inout
State) -> Void) { states.append(state) change(&state) notifySubscribers() } func undo() { state = history.popLast() notifySubscribers() } 71
72
73
74
75
76
77
78
79
80