Comments (3)
requestIdleCallback 就是在浏览器的空闲时段内调用的函数排队。deadline是为了保证cpu没有空闲的时间执行。document.visibilityState === 'hidden'是为了不在页面运作的时候执行
from nemetric.
@WarrenJones 但是我在你的代码中看到,虽然声明了全局的 requestIdleCallback
,但是实际上并没有用到这个API,而是自己写的:
const requestIdleCallbackShim = (callback: any) => {
const deadline = new IdleDealine(now());
return setTimeout(() => callback(deadline), 0);
};
这样写难道是能模拟原生 requestIdleCallback
的效果吗?换个方式问就是,你自定义的这个垫片到底是怎么检测到 cpu 空闲的呢?
谢谢作者的耐心回答,我真的非常疑惑,就这部分代码读不懂~
from nemetric.
是的,模拟requestIdleCallback。然后不断轮询处理任务
from nemetric.
Related Issues (2)
- 你好,请问在什么时候调用? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nemetric.