Very underrated channel on UA-cam for fronend. One day u are gonna have huge subscriber. Content are awesome here. Gonna recommend this channel to my friends
I think we don't need a setTimeout. we can create and update the start Time as we did before in setTimeout but not delete the timerId once time is elapsed function createTimeInterval(){ let intervalId = 1; let storedIntervals = {}; function myInterval(callback,delay,...args){ let id = intervalId++; let start = Date.now(); storedIntervals[id] = true; function recur(){ if(!storedIntervals[id]) return; if(Date.now() > start+delay){ callback.apply(this,...args); start = Date.now(); } requestIdleCallback(recur); } requestIdleCallback(recur); return id; } function myclearInterval(id){ if(storedIntervals[id]){ delete storedIntervals[id]; } } return {myInterval, myclearInterval}; } Please let me know if this is wrong
Very underrated channel on UA-cam for fronend. One day u are gonna have huge subscriber. Content are awesome here.
Gonna recommend this channel to my friends
Thanks 🙏🏻
This is a criminally underrated channel. There aren’t much resources for FE engineering like BE engineering.
Very good stuff. in clearInterval Poly shouldn't it be clearTimeoutPoly(intervalMap[id]) ?
yes, it worked because both id's were same, if we generated random number then it will break
How can we create polyfill of "new" keyword in Javascript? If possible could you please make video on this?
This is some great stuff... 😁🔥
Thanks ❤️
At line 23, it should be clearTimeoutPoly(intervalMap[id]) instead of clearTimeoutPoly(id)?
I also think so
Im getting a "requestIdleCallback is not defined" error. Coul not find solution anywhere
I think we don't need a setTimeout. we can create and update the start Time as we did before in setTimeout but not delete the timerId once time is elapsed
function createTimeInterval(){
let intervalId = 1;
let storedIntervals = {};
function myInterval(callback,delay,...args){
let id = intervalId++;
let start = Date.now();
storedIntervals[id] = true;
function recur(){
if(!storedIntervals[id]) return;
if(Date.now() > start+delay){
callback.apply(this,...args);
start = Date.now();
}
requestIdleCallback(recur);
}
requestIdleCallback(recur);
return id;
}
function myclearInterval(id){
if(storedIntervals[id]){
delete storedIntervals[id];
}
}
return {myInterval, myclearInterval};
}
Please let me know if this is wrong
This should actually work and in my opinion a cleaner solution.