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

fix: optimize onChange index #181

Merged
merged 5 commits into from
Feb 16, 2023
Merged

Conversation

kiner-tang
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Jan 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
image ❌ Failed (Inspect) Feb 15, 2023 at 3:06AM (UTC)

@codecov
Copy link

codecov bot commented Jan 20, 2023

Codecov Report

Merging #181 (24f15d7) into master (6187069) will decrease coverage by 0.92%.
The diff coverage is 93.54%.

❗ Current head 24f15d7 differs from pull request most recent head f790c6c. Consider uploading reports for the commit f790c6c to get more accurate results

@@             Coverage Diff             @@
##            master     #181      +/-   ##
===========================================
- Coverage   100.00%   99.08%   -0.92%     
===========================================
  Files            7        7              
  Lines          312      329      +17     
  Branches        95       99       +4     
===========================================
+ Hits           312      326      +14     
- Misses           0        3       +3     
Impacted Files Coverage Δ
src/Image.tsx 96.42% <83.33%> (-3.58%) ⬇️
src/Operations.tsx 100.00% <100.00%> (ø)
src/Preview.tsx 100.00% <100.00%> (ø)
src/PreviewGroup.tsx 100.00% <100.00%> (ø)
src/hooks/useImageTransform.ts 100.00% <100.00%> (ø)
src/previewConfig.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@kiner-tang
Copy link
Contributor Author

@MadCcc 帮忙再看看

tests/previewGroup.test.tsx Outdated Show resolved Hide resolved
src/PreviewGroup.tsx Outdated Show resolved Hide resolved
Co-authored-by: MadCcc <1075746765@qq.com>
prevCurrent.current = prev;
}
});
const [isShowPreview, setShowPreview] = useMergedState(!!previewVisible, {
value: previewVisible,
onChange: (val, prevVal) => {
onPreviewVisibleChange?.(val, prevVal);
onChange?.(current, prevCurrent.current);
onPreviewVisibleChange?.(val, prevVal, getSafeIndex(previewUrlsKeys, current));
Copy link
Member

Choose a reason for hiding this comment

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

这个 boolean 有 prevVal 还挺奇怪的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

主要是考虑到会不会有用户有打开预览时获取当前索引的情况

@@ -30,19 +31,20 @@ describe('PreviewGroup', () => {
act(() => {
jest.runAllTimers();
});
expect(onChange).toHaveBeenCalledWith(1, undefined);
expect(onChange).not.toHaveBeenCalled();
expect(onVisibleChange).toBeCalledWith(true, false, 0);
Copy link
Member

Choose a reason for hiding this comment

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

要不加一下 onChange 在打开时不触发的情况

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个就是呀

expect(onChange).not.toHaveBeenCalled();

@MadCcc MadCcc merged commit 5616f8d into react-component:master Feb 16, 2023
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.

2 participants