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
optional chainingの話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
yayoc
April 24, 2018
Programming
280
0
Share
optional chainingの話
2018/04/24 Roppongi.js
yayoc
April 24, 2018
More Decks by yayoc
See All by yayoc
Proxy's Black Magic
yayoc
0
200
What I did to improve performance score on Lighthouse
yayoc
2
2.8k
Practical Flow Type
yayoc
1
800
Other Decks in Programming
See All in Programming
The free-lunch guide to idea circularity
hollycummins
0
400
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
2
480
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.2k
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
3
440
Feature Toggle は捨てやすく使おう
gennei
0
400
AIと共にエンジニアとPMの “二刀流”を実現する
naruogram
0
110
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
1
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
1.3k
20260320登壇資料
pharct
0
140
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
420
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
500
Leo the Paperboy
mayatellez
6
1.6k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
230
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
160
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
The Limits of Empathy - UXLibs8
cassininazir
1
280
Producing Creativity
orderedlist
PRO
348
40k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
250
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Practical Orchestrator
shlominoach
191
11k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
240
Transcript
Optional chainingの話 Roppongi.js @yayoc
Hello! I am 弥吉修英 I am software engineer at Fast
Retailing. Twitter: @yayoc_ Github: @yayoc
なにをやっているか? ◦ SPAの実装 ◦ BFFの実装 ( 今日はここについての話など ) CDN router
SPA BFF Micro-service A Micro-service B Micro-service C Micro-service D
Micro serviceとの付き合い ◦ 10個以上のmicro serviceとREST APIでのやり取り ◦ APIがnullやundefinedを返すことはよくある □ データの不整合だったり・・
□ API仕様がPF間で若干違っていたり・・ □ バグだったり・・
結果、TypeError Cannot read propertyが頻出度の高いエラーであるという話 https://rollbar.com/blog/top-10-javascript-errors/ 肌感としてもよく分かる
解決策? 1. && operator 2. Ternary operator 3. Try catch
どれも冗長さが否めない・・
optional-chainingの proposal ◦ .? の左側を計算して、undefined もしくは nullの場合は、 undefinedを返す。そうでない場合は、素直にプロパティアク セスや関数実行を行う ◦
冗長な繰り返し記述やテンポラリな変数格納を避ける ◦ ステータスはStage1 ◦ Swift, C#などにはある ◦ https://tc39.github.io/proposal-optional-chaining/ ◦ TSにもまだない。( 議論は3年以上前からあるが・・ https://github.com/Microsoft/TypeScript/issues/16
optional-chain ◦ optional-chainというライブラリを作ってみた https://github.com/yayoc/optional-chain ◦ TSで書いたOption Typeを使った実装
optional-chain ◦ 間違ったプロパティアクセスに対しては、エラーを返す ◦ この辺の実装は@utatti氏のlens実装をかなり参考に
optional-chain ◦ パターンマッチ, getOrElseなどのAPIも一応ある
結論 ◦ JSにおける、プロパティアクセスは悩みのタネ ◦ optional chainingはスマートに解決してくれるので期待 ◦ optional-chainも解決してくれるかもしれない
THANKS! ありがとうございました。 Twitter: @yayoc_ Github: @yayoc
Appendix ◦ https://github.com/paypal/api-standards/blob/master /api-style-guide.md#null ◦ https://github.com/tc39/proposal-optional-chaining ◦ https://github.com/yayoc/optional-chain ◦ https://medium.com/@n_yayoshi/optional-chain-pro
xy-brings-optional-chaining-75fff102acbd ◦ https://developer.apple.com/library/content/docume ntation/Swift/Conceptual/Swift_Programming_Langu age/OptionalChaining.html
CREDITS Special thanks to all the people who made and
released these awesome resources for free: ◦ Presentation template by SlidesCarnival ◦ Photographs by Unsplash ◦ Backgrounds by SubtlePatterns