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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
yayoc
April 24, 2018
Programming
0
280
optional chainingの話
2018/04/24 Roppongi.js
yayoc
April 24, 2018
Tweet
Share
More Decks by yayoc
See All by yayoc
Proxy's Black Magic
yayoc
0
190
What I did to improve performance score on Lighthouse
yayoc
2
2.7k
Practical Flow Type
yayoc
1
780
Other Decks in Programming
See All in Programming
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
高速開発のためのコード整理術
sutetotanuki
1
390
CSC307 Lecture 07
javiergs
PRO
0
550
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
500
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
Implementation Patterns
denyspoltorak
0
280
組織で育むオブザーバビリティ
ryota_hnk
0
170
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
970
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.8k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
180
How to train your dragon (web standard)
notwaldorf
97
6.5k
The SEO identity crisis: Don't let AI make you average
varn
0
64
For a Future-Friendly Web
brad_frost
182
10k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
440
Optimizing for Happiness
mojombo
379
71k
Fireside Chat
paigeccino
41
3.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
230
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
130
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