Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor componentDidUpdate in ImageEditor.js #419

Merged

Conversation

kyoyadmoon
Copy link
Member

@kyoyadmoon kyoyadmoon commented Dec 18, 2023

Purpose

  • 為了更新 React 18,將原本的 UNSAFE_componentWillReceiveProps 的部分改成 componentDidUpdate,因為沒有改寫成 functional component,原本的 enzyme 測試就不需要改
  • 另外補充為什麼不改寫成 functional component 的原因:原本的 ImageEditor 程式碼似乎有刻意利用 class component 的特性去提供 getCroppingRectgetImageCanvas 等方法讓外部調用,由於此次目的不在重構成 functional component,想盡可能減少 API 變動的風險,所以決定維持 class component,只替換掉 unsafe lifecycle 就好

Copy link

sonarcloud bot commented Dec 18, 2023

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Merging #419 (9fefd36) into refactor/remove-unsafe-lifecycles-part3 (225ff52) will increase coverage by 0.01%.
Report is 2 commits behind head on refactor/remove-unsafe-lifecycles-part3.
The diff coverage is 100.00%.

Additional details and impacted files
@@                             Coverage Diff                             @@
##           refactor/remove-unsafe-lifecycles-part3     #419      +/-   ##
===========================================================================
+ Coverage                                    88.18%   88.20%   +0.01%     
===========================================================================
  Files                                          151      151              
  Lines                                         1600     1602       +2     
  Branches                                       278      278              
===========================================================================
+ Hits                                          1411     1413       +2     
  Misses                                         189      189              
Files Coverage Δ
packages/imageeditor/src/ImageEditor.js 98.33% <100.00%> (+0.02%) ⬆️

... and 1 file with indirect coverage changes

@kyoyadmoon kyoyadmoon marked this pull request as ready for review December 18, 2023 06:56
Copy link
Contributor

@chenesan chenesan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 記得如果是 functional component 要用 useImperativeHandle 之類的方式才能從 ref 呼叫方法的事,覺得維持 class 也很好

Base automatically changed from refactor/remove-unsafe-lifecycles-part3 to project/upgrade-react-v18 December 19, 2023 06:32
@kyoyadmoon kyoyadmoon merged commit 50c9b26 into project/upgrade-react-v18 Dec 19, 2023
7 checks passed
@kyoyadmoon kyoyadmoon deleted the refactor/remove-unsafe-lifecycles-part4 branch December 19, 2023 10:15
@zhusee2 zhusee2 added this to the v7 milestone Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants