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
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
「速くなった気がする」をデータで疑う
senleaf24
0
120
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
270
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
230
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
500
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
310
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
420
AI 開発合宿を通して得た学び
niftycorp
PRO
0
190
Java 21/25 Virtual Threads 소개
debop
0
320
仕様漏れ実装漏れをなくすトレーサビリティAI基盤のご紹介
orgachem
PRO
8
4k
モダンOBSプラグイン開発
umireon
0
190
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
6.8k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
160
Game over? The fight for quality and originality in the time of robots
wayneb77
1
150
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
350
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
230
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Utilizing Notion as your number one productivity tool
mfonobong
4
280
A Tale of Four Properties
chriscoyier
163
24k
Designing for humans not robots
tammielis
254
26k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.1k
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