Skip to content

Instantly share code, notes, and snippets.

@braden-w
Created May 18, 2021 04:02
Show Gist options
  • Save braden-w/b5305401db0b81a51d5710fa2d6b91dc to your computer and use it in GitHub Desktop.
Save braden-w/b5305401db0b81a51d5710fa2d6b91dc to your computer and use it in GitHub Desktop.
A method of storing and clearing timers
const timeout = {}
const updateUserProfileInformation = (updateKey, updateValue) => {
if (signedIn.value) {
clearTimeout(timeout?.[updateKey])
console.log("timeout :>> ", timeout)
console.log("payload :>> ", updateKey, updateValue)
timeout[updateKey] = setTimeout(async () => {
await updateToFirestore($fire, userProfileInformation, {
[updateKey]: updateValue,
})
}, 2000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment