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
Refactoring, from AngularJS to React
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Alex Tzeng
November 03, 2018
Programming
1
110
Refactoring, from AngularJS to React
Alex Tzeng
November 03, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
200
「ブロックテーマでは再現できない」は本当か?
inc2734
0
550
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
250
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
Package Management Learnings from Homebrew
mikemcquaid
0
210
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
AgentCoreとHuman in the Loop
har1101
5
220
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.2k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
91
How to make the Groovebox
asonas
2
1.9k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
Into the Great Unknown - MozCon
thekraken
40
2.2k
Chasing Engaging Ingredients in Design
codingconduct
0
110
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
910
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
280
BBQ
matthewcrist
89
10k
Transcript
W 重構 從 AngularJS 到 React Alex Tzeng fb.me/alxtz.tw
W About Senior-ish frontend developer Often credited as a good
storyteller ( not what I expected )
Story Time
None
A desktop app that stimulates effects unit
Built on an eletron-like desktop framwork Use AngularJS as UI
framework
2 months after joining New 2.0 project
Main problems Rewrite from a 5-year-old codebase Recompile time >
40s Outdated abstraction Several 3000+ line behemoths Legacy tooling Chaos coding style
Turing point
Our frontend team lead Promoted to be the product owner
Tips on bringing in the concepts of enginneering health into
your team.
Always communicate Transparency is one of the most important values
in Agile Tip A Only if you express the problems, then you can solve them
If you expected the codebase will at least last 1
year Tip B Caring about enginneering health will save your time in the long run
Most managers want good code, even when they are obsessing
about the schedule. Tip C They may defend the schedule and requirements with passion; but that’s their job. It’s your job to defend the code with equal passion.
3 main problems
1. DI & $events aren’t scalable
AngularJS uses a modularization system called Depedency Injection
It actually works fine
The problem is we usually mess it in global
And auto inject with angularJS magic Makes it hard to
find where the depedency come from
For larger projects, nested dependency would have less pain to
maintain
Solution: replace Angular1 module with CommonJS / ES6 import
Before After
Problems with AngularJS $events
Hard to trace / debug when event grows No established
pattern, just broadcast
Replacement for $events Redux
Reasons to use Redux Relatively easy to debug Completely framework-agnostic
( works well when migrating ) Well known enough for newcomers
Great choice when working with multiple frameworks
Components in AngularJS Combo
Angular 1.5 introduces Components Combo Works similar to the Web
Components Standard
Combo
Combo template / render()
Combo template / render() props
Combo template / render() props lifecycles ComDidMount ComShldUpdate
Combo template / render() props lifecycles ComDidMount ComShldUpdate Methods
None
Ok, maybe not.
None
Components + CommonJS = Scalable AngularJS
2. Build tools
Most legacy projects uses Gulp as its task runner
Reasons to move from Gulp to npm + webpack Supports
CommonJS module, url rewrite out of the box Better dev experience with dev-server Easier to audit module size, compile time
Build JavaScript using Gulp
Build JavaScript using Gulp Entry files
Build JavaScript using Gulp Entry files Preprocessor
Build JavaScript using Gulp Entry files Preprocessor Output path
Build JavaScript using Webpack Entry files Preprocessor Output path
3. Migrate to React
Why migrate to React More mature ecosystem Easier to hire
/ get in project Familiar with team member
How to migrate Total rewrite Progressively rewrite Rewrite per page
Total rewrite ( rm -rf ./ ) Too risky for
production project Only apply for core components Hard to estimate time
Progressively rewrite React & AngularJS coexist Value backward compatibility Only
rewrite when code change
Progressively rewrite actually simple
Progressively rewrite Follows web component standards Easy to reuse component
design
Summary (Story) Care more about engineering health Self-aware is the
key to clean code Refactoring using the scrum way
Summary (3 problems) Nested dependency is more scalable Redux for
cross-framework state Gulp -> Webpack Progressively migrate to React