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
980
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
250
NSSpain 2023: An overview of different approaches to share code across platforms
terhechte
0
470
Dependency Management with Swift
terhechte
0
21
NSSpain 2020: GeometryReader, View Preferences and Anchors - SwiftUI tales from the Hyperdeck
terhechte
0
14
FrenchKit 2020: Hyperdeck. What can go wrong on a multiyear side project
terhechte
0
15
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
Kubernetesでセルフホストが簡単なNewSQLを求めて / Seeking a NewSQL Database That's Simple to Self-Host on Kubernetes
nnaka2992
0
200
アーキテクチャモダナイゼーションとは何か
nwiizo
15
3.8k
ファインチューニングせずメインコンペを解く方法
pokutuna
0
270
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
250
Java 21/25 Virtual Threads 소개
debop
0
320
Go_College_最終発表資料__外部公開用_.pdf
xe_pc23
0
120
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
840
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.8k
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
190
Spec Driven Development: The End Of Vibe Coding | DevLand 2026
danielsogl
PRO
0
110
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
170
AIと共にエンジニアとPMの “二刀流”を実現する
naruogram
0
130
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
First, design no harm
axbom
PRO
2
1.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
880
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
330
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
310
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
170
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
450
Exploring anti-patterns in Rails
aemeredith
3
310
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
99
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