-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: add leftTime for useCountDown #1737
Conversation
有点问题,jest没跑过,我先close掉 |
calcLeftTime 函数最好使用时间戳计算,因为 手机黑屏或者页面失焦的时候,有可能setInterval会暂停执行,当界面重新恢复的时候,pre -interval 计算出来的剩余时间就偏大了
calcLeftTime函数里 上面写法可获取到正确的剩余时间 |
用时间戳的话会出现比较严重的精度问题,时间间隔不一定能和 |
Math.round(3998 / 1000) * 1000 这样可以吧? |
这样理论上来说对毫秒是可以的,但是不知道会不会影响到 |
|
我改一下 |
@crazylxr @hchlq @brickspert 根据砖家的建议又双叒改了一版,把 leftTime 和 target 统一转化成 targetDate了,麻烦再 review 一下,辛苦! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
close #1727
📝 Changelog
useCountDown
增加leftTime
参数,支持剩余时间的倒计时,同时优化了一些代码细节:TDate
类型替换成dayjs.ConfigType
,因为dayjs已经定义过了,感觉没必要重复定义new Date().getTime()
更新为ES6中的Date.now()
,性能更好Math.floor()
方法取整更新为位运算,性能更好onEnd
回调,现在考虑到要不要加一个onStart
回调?但是好像没啥必要,onStart
好像直接用useEffect
即可实现?☑️ Self Check before Merge