1.0.3 • Published 6 years ago

ticker-js v1.0.3

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

100% test coverage

ticker-js

Event-emitting time keeper for browser friendly render cycles

Browser-based module that fires events at a given interval to facilitate interactions on a timeline. Tries to help facilitate measure/render grouping by firing two separate events at different moments in the process tick.

  • The update event is when any measurement or calculations should occur.
  • The render event is when the results of any measurements are applied to the DOM.

Installation

Install via npm:

$ npm i ticker-js --save

API

All properties should be accessed via the getter and setter methods.

methodparamsdescription
startStarts the instance, firing its events
stopStops the instance, stopping events from firing
setFpsnumber: fpsThrottles the ticker to the passed value
getFpsReturns the current fps setting as a number or null
isTickingReturns boolean indicating if the instance is running
destroyDestroys the instance, removing all listeners

Events

All events pass the same event object defined below.

eventdescription
updateDOM measurements and calculations should occur when fired.
renderDOM modification should occur when fired.

Event object

The two events pass listeners an event object as defined below.

typenamedescription
@property {object}dataevent data object
@property {number}data.fpsframes per second
@property {number}data.trueFpsun-throttled frames per second
@property {number}data.runtimethe total duration of the ticker while ticking
@property {number}data.deltatime since last render
@property {number}data.timecurrent lifespan of render cycle
@property {number}data.nowcurrent time

Usage

Instantiate and attach any listeners.

var Ticker = require('ticker-js');
var ticker = new Ticker(30);

ticker.on('update', function (evt) {
  // measure
});

ticker.on('render', function (evt) {
  // render
});

Instances do not auto-run. You must call the start method for the events to begin firing.

ticker.start();

Once running, the update and render events will begin firing at the ticker's fps interval. If fps is unset, the ticker is not throttled, and will tick as close to 60 fps as possible.

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago