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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Benedikt Terhechte
October 13, 2017
Programming
990
3
Share
Simplifying State by partially introducing unidirectional data flow in your codebase
Benedikt Terhechte
October 13, 2017
More Decks by Benedikt Terhechte
See All by Benedikt Terhechte
Back to the Future: Let me tell you about the ACP protocol
terhechte
0
270
NSSpain 2023: An overview of different approaches to share code across platforms
terhechte
0
470
Dependency Management with Swift
terhechte
0
35
NSSpain 2020: GeometryReader, View Preferences and Anchors - SwiftUI tales from the Hyperdeck
terhechte
0
19
FrenchKit 2020: Hyperdeck. What can go wrong on a multiyear side project
terhechte
0
18
SwiftUI & UIKit, a match made in heaven or match made in hell?
terhechte
0
97
Learnings from building Design Systems at XING
terhechte
1
550
Introduction to Swift Keypaths
terhechte
15
21k
Sharing Code between iOS and Android with Rust
terhechte
8
2.6k
Other Decks in Programming
See All in Programming
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
150
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
460
Firefoxにコントリビューションして得られた学び
ken7253
2
170
Kubernetesを使わない環境にもCloud Nativeなデプロイを実現する / Enabling Cloud Native deployments without the complexity of Kubernetes
linyows
3
430
iOS26時代の新規アプリ開発
yuukiw00w
0
160
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
260
tsserverとは何だったのか_これからどうなるのか
nowaki28
1
250
柔軟なPDFレイアウトエディタを支える型システム設計 — Discriminated UnionとConditional Typeの実践
minako__ph
2
220
色即是空、空即是色、データサイエンス
kamoneggi
1
130
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
4
410
Cloudflare で始める Data Platform
ta93abe
0
200
要はバランスからの卒業 #yumemi_grow
kajitack
0
170
Featured
See All Featured
Chasing Engaging Ingredients in Design
codingconduct
0
190
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Being A Developer After 40
akosma
91
590k
A Tale of Four Properties
chriscoyier
163
24k
RailsConf 2023
tenderlove
30
1.4k
Ruling the World: When Life Gets Gamed
codingconduct
0
230
How GitHub (no longer) Works
holman
316
150k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
700
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
370
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