mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-15 04:29:37 +01:00
chore(Notification): transform ticker and timer plugins to useTimer composable
This commit is contained in:
@@ -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)
|
||||
})
|
||||
@@ -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)
|
||||
})
|
||||
Reference in New Issue
Block a user