Carbonium-Timer
Timer support for Carbonium.
Installation
$ npm install @byzanteam/carbonium-timer
Usage
Create Timer
import {createTimer} from '@byzanteam/carbonium-timer'
const timer = createTimer()
const timer = createTimer({delay: 0, duration: 1e3, easingFunction: 'easeInOut'})
Subscribe
timer.subscribe()
向 timer 中添加任务,返回退订函数。调用退订函数会从任务队列中移除相关的所有任务。该函数一共有三种调用形式,如下所示。
interface StateType {
width: number,
height: number,
}
const handler = (progress: number, startState: StateType, endState: StateType) => {
console.log(progress, startState, endState)
}
timer.subscribe<StateType>(handler, {
delay: 250,
startState: {width: 100, height: 100},
endState: {width: 200, height: 200},
})
timer.subscribe<StateType>({
handler,
duration: 2e3,
startState: {width: 100, height: 100},
endState: {width: 200, height: 200},
})
const unsubscribe = timer.subscribe<StateType>([
{
handler,
},
{
handler,
}
])
unsubscribe()