Frame-based & native timer based timers managed by 1 class
Helps us to normalize the api between requestAnimationFrame(), setTimeout() and setInterval by providing us with 1 api and many options. Start, stop, reset and reuse timers as you want in the simplest of ways. V3 is a ES6 rewrite of V2 keeping most of its api and structure.
Class type: Manager
- EventDispatcher 1.0.0
There are 2 ways to init a ticker and set up a timer. Classes may also extend from Ticker to add an extra layer of complexity.
// set up instance
let timer = new Ticker({
timeout: 100
});
// start timer
timer.start();
// stop timer
timer.stop();
// reset
timer.reset();
// Quick timer => setTimeout-like, setInterval-like
Ticker.quick(100, (e) => {
console.log('ticked');
})
Type: Object
Default: {}
Settings to set parameters at construction time
Type: String
Default: Ticker
Object name that will be used as recognisable identifier and as prefix in logs
Type: Number
Default: 0
Waiting time for the instance to trigger a timout/interval vent. 0 = next frame.
Type: Boolean
Default: false
Turns the ticker instance into an interval timer that will trigger ‘interval’ events every time the timeout is reached. Timeout events are replaced by Interval events.
Type: Boolean
Default: false
Auto-destructs the instance when the timeout callbacks have run.
Type: Boolean
Default: false
Auto-starts the instance once the constructor is done.
Type: Object
Default: {}
Data to keep and add to the event.data object when events are dispatched.
Type: Boolean
Default: false
Sets the instance to use setTimeout or setInterval instead of requestAnimationFrame.
Type: Boolean
Default: false
Auto-resets the time property when the timeout callbacks have run. Will be ignored if isInterval = true.
Type: Number
Default: 0
Waiting time for the instance to trigger a timout/interval vent. 0 = next frame.
Type: Boolean
Default: false
Turns the ticker instance into an interval timer that will trigger ‘interval’ events every time the timeout is reached. Timeout events are replaced by Interval events.
Type: Boolean
Default: false
Auto-destructs the instance when the timeout callbacks have run.
Type: Boolean
Default: false
Auto-starts the instance once the constructor is done.
Type: Object
Default: {}
Data to keep and add to the event.data object when events are dispatched.
Type: Boolean
Default: false
Sets the instance to use setTimeout or setInterval instead of requestAnimationFrame.
Type: Boolean
Default: false
Auto-resets the time property when the timeout callbacks have run. Will be ignored if isInterval = true.
Type: Number
Default: 0
Timer id returned by the native timer methods.
Type: Number
Default: 0
Time passed since start of the timer. Resets when reset has run or at the end of ta timeout/interval.
Type: Number
Default: 0
Last time in ms a tick has taken place. Used together with time to know if a timeout limit is reached.
Type: Boolean
Default: false
Flag determining if the instance is running a timer or not.
Type: Boolean
Default: ''
Version number of current class definition.
Parameters: reset:boolean
Return: undefined
Starts the timer, resets the instance before it starts if true is passed.
Parameters: reset:boolean
Return: undefined
Stops the timer, resets the instance if true is passed.
Parameters: stop:boolean
Return: undefined
Resets the timer, stops the instance if true is passed.
Parameters: none
Return: undefined
Forces to calculate a timeout when called. Is called internally by when a native timer ticks.
Parameters: none
Return: undefined
Destroys the instance.
Parameters: [timeout] [, data] [, isInterval] [, callback]
Return: Ticker
Quick way to set up a disposable ticker. It will auto run and auto destruct once its purpose is fullfilled.
- Turn timerId, time and last tick into read only parameters + make the real props ‘private’