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
260
NSSpain 2023: An overview of different approaches to share code across platforms
terhechte
0
470
Dependency Management with Swift
terhechte
0
26
NSSpain 2020: GeometryReader, View Preferences and Anchors - SwiftUI tales from the Hyperdeck
terhechte
0
15
FrenchKit 2020: Hyperdeck. What can go wrong on a multiyear side project
terhechte
0
16
SwiftUI & UIKit, a match made in heaven or match made in hell?
terhechte
0
94
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.5k
Other Decks in Programming
See All in Programming
セグメントとターゲットを意識するプロポーザルの書き方 〜採択の鍵は、誰に刺すかを見極めるマーケティング戦略にある〜
m3m0r7
PRO
0
560
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
140
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
110
Angular Signal Forms
debug_mode
0
110
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
110
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
160
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
0
150
実用!Hono RPC2026
yodaka
2
240
AIエージェントで業務改善してみた
taku271
0
540
iOS機能開発のAI環境と起きた変化
ryunakayama
0
190
PDI: Como Alavancar Sua Carreira e Seu Negócio
marcelgsantos
0
120
Don't Prompt Harder, Structure Better
kitasuke
0
770
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.9k
Utilizing Notion as your number one productivity tool
mfonobong
4
290
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
210
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How to Talk to Developers About Accessibility
jct
2
180
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The Spectacular Lies of Maps
axbom
PRO
1
710
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
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