This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const makeDeepClone = (obj) => { | |
let newObject = {}; | |
Object.keys(obj).map(key => { | |
if(typeof obj[key] === 'object'){ | |
newObject[key] = makeDeepClone(obj[key]); | |
} else { | |
newObject[key] = obj[key]; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let timerId = setTimeout(function tick() { | |
timerId = setTimeout(tick, 2000) // here you can pass any timeout and dynamically change next calls | |
}, 1000); | |
// Example | |
let call = 1; | |
let timerId = setTimeout(function tick() { | |
timerId = setTimeout(tick, 2000 * call); | |
call++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Timer { | |
name: string; | |
delay: number; | |
interval: boolean; | |
cb: Function; | |
} | |
interface TimerForCalling { | |
name: string; | |
interval: boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function will wait until needed time but will block your eventloop | |
function sleep(time = 0) { | |
const wakeUpTime = Date.now() + time | |
while (Date.now() < wakeUpTime) {} | |
} |