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
源码-react-compound-timer #166
Labels
Comments
|
|
|
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
分析react-compound-timer
lib
目录1.
lib/helpers/getTimeParts.ts
将毫秒数转成时间格式的,写法比较高大尚,简直吊炸天。
之前项目里也看过类似功能的API,但实现方式是:
可以视为
getTimeParts(time, 'd')
的一个特例。但是利用的是减法方式。2.
lib/helpers/now.ts
在浏览器端优先使用
performance.now()
代替Date.now()
。为啥?->performance.now PK Date.now3.
lib/models/TimerModel.ts
计时器。并且可以解决页面切到后台后定时器暂停带来的问题。
setInterval
实参函数执行的事件间隔来计算剩余时间,而不是通过实参函数执行次数计算,这样有两个好处:setInterval
会被暂停的,此时通过此时计数就不正确了。onChange
,但是跟滴答触发的回调实参不一样?The text was updated successfully, but these errors were encountered: