chore(Notification): transform ticker and timer plugins to useTimer composable

This commit is contained in:
Benjamin Canac
2021-12-14 17:54:02 +01:00
parent 9dd4d69841
commit 175b8c9dba
5 changed files with 150 additions and 120 deletions

View File

@@ -1,19 +0,0 @@
import { defineNuxtPlugin } from '#app'
function Ticker (callback, interval) {
let id
this.start = function () {
id = window.setInterval(callback, interval)
}
this.stop = function () {
window.clearInterval(id)
}
this.start()
}
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide('ticker', Ticker)
})

View File

@@ -1,34 +0,0 @@
import { defineNuxtPlugin } from '#app'
function Timer (callback, delay) {
let timerId
let start
let remaining = delay
this.pause = function () {
window.clearTimeout(timerId)
remaining -= new Date() - start
}
this.resume = function () {
start = new Date()
window.clearTimeout(timerId)
timerId = window.setTimeout(callback, remaining)
}
this.reset = function () {
start = new Date()
window.clearTimeout(timerId)
timerId = window.setTimeout(callback, delay)
}
this.stop = function () {
window.clearTimeout(timerId)
}
this.resume()
}
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide('timer', Timer)
})