@byzanteam/timer
v0.2.0
Published
Timer for Carbonium
Downloads
14
Readme
timer
Timer support for Carbonium.
Installation
$ npm install @byzanteam/timer
Usage
Create Timer
import { createTimer } from '@byzanteam/timer'
const timer = createTimer()
// Create timer with given defaults.
const timer = createTimer({ delay: 0, duration: 1e3, easingFunction: 'easeInOut' })
Subscribe
timer.subscribe()
向 timer 中添加任务,返回退订函数。调用退订函数会从任务队列中移除相关的所有任务。该函数一共有两种调用形式,如下所示。
const handler = (progress: number) => {
// Do something with the progress...
}
// 单个任务配置对象。
timer.subscribe({ duration: 2e3, handler })
// 多个任务配置对象数组。
const unsubscribe = timer.subscribe([
{
delay: 250,
handler,
},
{
duration: 250,
handler,
}
])
// 调用 unsubscribe 函数会移除订阅的所有任务。
unsubscribe()