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
2020-11-05-side-effects-composition__1_.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nkowne63
November 05, 2020
460
1
Share
2020-11-05-side-effects-composition__1_.pdf
Nkowne63
November 05, 2020
More Decks by Nkowne63
See All by Nkowne63
TypeScriptのコード生成をつらくしないために
neutron63zf
1
790
vueで中規模以上のフロントエンドを組んでいて 役に立ったtips
neutron63zf
5
3.4k
20200128_nkowne63
neutron63zf
0
46
Vueで「見た目」「振る舞い」を分離してみよう
neutron63zf
0
620
20190523_nkowne63zf_1.pdf
neutron63zf
0
420
「つなぎこみ」を自動化する
neutron63zf
0
520
for文禁止縛り in JS
neutron63zf
0
770
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
710
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
340
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.8k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
280
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
230
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Transcript
Reduxに依存しない 副作用の合成
背景
背景 • Mobx、Recoilなどの、Reduxに代わりうる状態管理ライブラリが普及してきた • 一方で、Redux-Sagaのような複雑な副作用合成システムを使いたければ、 Reduxしか選択することが (実質)できない • Redux-Sagaとは違う、「状態管理システムとは独立した副作用合成システム 」が必要
関数合成による 副作用の合成 https://github.com/neutron63zf/weakref-function-composer-sample
シンプルな合成 APIはinject/wrappedの2つのみ 副作用を合成したい関数と同じ型の値を返す関数を 受け取り、副作用を実行する関数 (g1, g2) injectは第一引数の関数に副作用を結びつける wrappedは副作用が結びついた関数を返す
多段合成 wrappedは実行された時点での合成された関数を返 すので、 右のように記述すれば副作用の関数の中でさらに 別の副作用を呼び出す事もできる。
特徴と課題
特徴(Pros) • 小さい(40行程度) • 関数に副作用となる関数をラップしていくだけの直感的な動作(シンプル) • 型フレンドリーである • 使う側が「副作用を発生させるかどうか」を制御可能 •
副作用をRedux-Sagaのように仮想的な別プロセスで回すのではなく、関数の合成をしているだけなの で、「次の行に移ったときには副作用の実行は終わっている 」(実行タイミングがわかりやすい)
課題(Cons) • Redux-Sagaほど表現力は高くない(yieldによるチャンネルの合成など) ◦ 書けない事もないが結局 Redux-Sagaの再実装になってしまう • コールスタックを消費するので、無限ループができない ◦ trampolineなどのテクニックを使う事で回避可能
まとめ
まとめ • Reduxに依存しない副作用の合成の仕方が求められている • シンプルな関数合成で副作用を合成するというやり方がある • 一定の課題はあるものの、特定の局面では力を発揮するかもしれない