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
yayoc
April 24, 2018
Programming
0
240
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
140
What I did to improve performance score on Lighthouse
yayoc
2
2.5k
Practical Flow Type
yayoc
1
670
Other Decks in Programming
See All in Programming
エラーレスポンス設計から考える、0→1開発におけるGraphQLへの向き合い方
bicstone
5
1.5k
2024 컴포즈 정원사
jisungbin
0
150
Prolog入門
qnighy
4
1k
o1モデルのプロンプトエンジニアリングって?
ktc_wada
0
290
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
210
REXML改善のその後
naitoh
0
190
GraphQLとGigaViewer for Apps
numeroanddev
2
110
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
530
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
4
90k
What you can do with Ruby on WebAssembly
kateinoigakukun
0
170
Google Sign-inの移行から始めるCredential Manager活用
clockvoid
0
350
Architecture Decision Record (ADR)
nearme_tech
PRO
1
690
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
28
1.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
24
610
How STYLIGHT went responsive
nonsquared
93
5.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
158
15k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
Debugging Ruby Performance
tmm1
72
12k
Adopting Sorbet at Scale
ufuk
73
8.9k
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
Agile that works and the tools we love
rasmusluckow
327
20k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
RailsConf 2023
tenderlove
28
810
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
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