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
1k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
300
NSSpain 2023: An overview of different approaches to share code across platforms
terhechte
0
490
Dependency Management with Swift
terhechte
0
42
NSSpain 2020: GeometryReader, View Preferences and Anchors - SwiftUI tales from the Hyperdeck
terhechte
0
23
FrenchKit 2020: Hyperdeck. What can go wrong on a multiyear side project
terhechte
0
30
SwiftUI & UIKit, a match made in heaven or match made in hell?
terhechte
0
100
Learnings from building Design Systems at XING
terhechte
1
570
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
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
400
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
49
31k
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
110
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
270
Press start. Python's next generation.
willingc
PRO
3
300
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
XHTMLが残したもの
yosuke_furukawa
PRO
0
150
信頼性の目標を誰も求めてない
shubox
0
460
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
200
Go 1.27 における memory allocation の高速化
andpad
0
360
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.3k
ALB ログから Trace を気合で繋げる技術
fohte
7
840
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
180
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
640
The Curious Case for Waylosing
cassininazir
1
490
A designer walks into a library…
pauljervisheath
211
24k
Tell your own story through comics
letsgokoyo
1
1.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
300
Amusing Abliteration
ianozsvald
1
280
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
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