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
290
NSSpain 2023: An overview of different approaches to share code across platforms
terhechte
0
480
Dependency Management with Swift
terhechte
0
41
NSSpain 2020: GeometryReader, View Preferences and Anchors - SwiftUI tales from the Hyperdeck
terhechte
0
22
FrenchKit 2020: Hyperdeck. What can go wrong on a multiyear side project
terhechte
0
22
SwiftUI & UIKit, a match made in heaven or match made in hell?
terhechte
0
100
Learnings from building Design Systems at XING
terhechte
1
560
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
Android CLI
fornewid
0
110
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
230
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
210
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
630
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.6k
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
490
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
140
自作OSでスライド発表する
uyuki234
1
3.9k
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
530
act1-costs.pdf
sumedhbala
0
240
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.2k
Featured
See All Featured
sira's awesome portfolio website redesign presentation
elsirapls
0
310
WCS-LA-2024
lcolladotor
0
740
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Why Our Code Smells
bkeepers
PRO
340
58k
Accessibility Awareness
sabderemane
1
160
The Limits of Empathy - UXLibs8
cassininazir
1
530
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
340
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
A Modern Web Designer's Workflow
chriscoyier
698
190k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
420
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