Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Datapiaのフロントエンドについて
Search
danny
November 12, 2020
Programming
550
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Datapiaのフロントエンドについて
danny
November 12, 2020
More Decks by danny
See All by danny
新規サービスの技術選定と設計
f96q
1
18k
Vue.jsとRailsで作るWebアプリケーション
f96q
0
840
開発環境でDocker使ってみた
f96q
1
2.4k
2013年を振り返って
f96q
0
790
Git勉強会@KRAY
f96q
1
2.2k
等強Ruby会議10に参加しての感想
f96q
2
970
Inside Tripclip
f96q
2
1.6k
Other Decks in Programming
See All in Programming
JRuby: Past, Present, and Future
headius
0
220
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
4.8k
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
140
Webの地図
yosuke_furukawa
PRO
6
5k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.1k
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
470
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
300
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
290
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
220
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Intent as Code
shoppingjaws
6
1.1k
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
Featured
See All Featured
From π to Pie charts
rasagy
1
380
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building Adaptive Systems
keathley
44
3.2k
KATA
mclloyd
PRO
35
16k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
590
Mind Mapping
helmedeiros
1
390
Skip the Path - Find Your Career Trail
mkilby
1
240
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Balancing Empowerment & Direction
lara
6
1.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
510
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
570
Transcript
Datapiaのフロントエンドについて 2020.11.12 コネヒトマルシェオンライン 宮城 史明
今日話すこと 2 ここ2年ほど開発してるDatapiaというプロ ダクトのフロントエンドについての話をし ます Datapiaとは • 複数クラウド(DB、ストレージ)に対 して、クエリ操作、データ転送、ワー クフロー、権限管理などをノンプログ
ラミングで実行できるクラウド型 iPaaSです
Datapiaについて 3 • フロントエンドがReactでバックエン ドがRuby on Rails • ログインページでログインした後は Single
Page Application構成 • フロントエンドの規模感 ◦ およそ3万4千桁 (TypeScript, TSX) ◦ React Component数は373
構成 フロントエンド • TypeScript • React • Redux ◦ React
Redux ◦ TypeScript FSA Reducers • React Router • styled-components • Apollo Client バックエンド • Ruby on Rails (GraphQL API Server)
Railsでwebpackを使う Webpackerを使わない理由 • フロントエンドエンジニアじゃなくても扱えるように整備された状態で使えるのはメ リットたが、その反面細かい部分まで調整したい場合はいじりずらい ◦ webpackの設定ファイルと書き方が違う ◦ webpackのあの設定、Webpackerだとどう設定するのかを調べないと分からない webpack-assets-pipleline
• webpackで生成したファイルのハッシュ値付きのURLが入ったmanifest.jsonを生成で きる ◦ Railsでassets precompileする必要がなくなる ◦ Railsでもwebpackを使って開発できるようになる 参考 • https://infinum.com/the-capsized-eight/squeezing-webpack-into-backend-fram eworks 5
Babelの設定 6 "presets": [ [ "@babel/preset-env", { "targets": { "chrome":
"75", "firefox": "68", "edge": "18" }, "useBuiltIns": "usage", "corejs": 3 } ], "@babel/preset-react", "@babel/preset-typescript" ] useBuildIns usage • 対応ブラウザのバージョンを定義して おくと、その定義をみて自動で必要な polyfillのみを使ってビルドされる
ESLintで禁止してるもの import/no-default-export • 任意の名前でインポートできるので後から名前を変えたり、使われてる箇所をさがすときに大変な ため no-restricted-syntax • TSEnumDeclaration ◦ 後から入ったエンジニアがenumかUnion型どっち使うのか混乱しないように
• TSInterfaceDeclaration ◦ 後から入ったエンジニアがtypeとinterfaceどっち使うのか混乱しないように ◦ interfaceは既存の定義されてる名前のまま拡張できるので公開するライブラリで使う方針 • ForInStatement, ForOfStatement, VariableDeclaration[kind='let'] ◦ 副作用が起きない書き方によせるため • LabeledStatement ◦ go to使われるとコード読みづらくなるため • WithStatement ◦ withで省略されると出どころが追いづらくなってコードが読みづらくなるため 参考 • https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base /rules/style.js#L339-L357 7
例外通知 8 componentDidCatch(error: Error, errorInfo: ErrorInfo): void { Sentry.withScope((scope) =>
{ scope.setExtras(errorInfo as any) Sentry.captureException(error) }) this.setState({ hasError: true }) } React Error Boundaryで補足した例外 をSentryに送る • Redux Storeの中身をsentryに送信 するような実装はしない ◦ 送ったほうがデバックはしやすくな るが、Redux Storeはバックエンド のAPIからユーザーの情報が入って いて、内容によっては外部のサービ スに送ってはまずいものが含まれて ることがあるため
React Hooksの使い方 9 const history = useHistory() const { id
} = useParams<{ id: string }>() const { currentOrganization, currentUser, user } = useSelector((state: RootState) => ({ currentOrganization: state.organization.currentOrganization, currentUser: state.user.currentUser, user: state.user.user, })) const dispatch = useDispatch() useEffect(() => { dispatch(actions.user.fetchUser({ id })) }, [id]) APIで取得した値をRedux Storeから取り出 して表示する • useHistory • useParams • useSelector • useDispatch
多言語化 10 <FormattedMessage id="models.organization.logo" /> 最初から多言語化することを前提で作って おく • 後から多言語化しようとすると、ほぼ すべての画面に影響が出るため手間が
大きい React Intl • ECMA Script標準の国際化APIのIntlを React Componentで扱える
アイコン、ロゴ画像 全てSVGで作成 • 同じ画像で@2xのような複数の画像サ イズの画像を用意する必要がなくなる • webpackでビルドした時のbundleサイ ズの軽量化 SVGR •
https://github.com/gregberge/svgr • SVGをReact Componentに変換
バックエンドとの通信 12 function errorLink(): ApolloLink { return onError((response: any) =>
{ if (response.networkError && response.networkError.statusCode === 401) { location.href = '/users/sign_in' } }) } Apollo Client • GraphQLクライアント SPA特有の問題 • ログインセッションが切れた状態で画 面を操作するとなにも反応がなくなっ てしまう ◦ ApploLinkでonErrorをハンドリングし てログインページにローケーション