0.0.2 • Published 4 years ago

tiny-ticker v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

tiny ticker Build Status view on npm

A ticker utility for time-sensitive loops in Node.js, written in TypeScript. Not currently supported in browsers.

Installation

For Node.js or webpack projects, install with the NPM package manager:

npm install --save tiny-ticker

Usage

// commonjs module
const { Ticker } = require('tiny-ticker')

// esmodules
import { Ticker } from 'tiny-ticker'

// in the browser
const { Ticker } = window.TinyTicker

const ticker = new Ticker(50) // create a Ticker that ticks every 50ms

ticker.on('start', () => {/* ... */}) // fired when the ticker starts
ticker.on('tick', () => {/* ... */}) // fired for every tick, run your update loop here
ticker.on('stop', () => {/* ... */}) // fired when the ticker stops

ticker.start() // start ticker

/* ... */

ticker.stop() // stop ticker

For detailed documentation on each of these methods, check the API documention below.

API

Ticker ⇐ EventEmitter<ITickerEvents>

A Ticker controller.

Kind: global class
Extends: EventEmitter<ITickerEvents>

new Ticker(interval)

Create a Ticker.

ParamTypeDefaultDescription
intervalnumber0Interval (or tick speed) in milliseconds to run the Ticker at

ticker.start() ⇒ void

Start the Ticker, immediately emits a start event.

Kind: instance method of Ticker
Emits: start
Access: public

ticker.stop() ⇒ void

Start the Ticker, immediately emits a stop event.

Kind: instance method of Ticker
Emits: stop
Access: public

"start"

Fires when the Ticker is started.

Kind: event emitted by Ticker

"stop"

Fires when the Ticker is stopped.

Kind: event emitted by Ticker

"tick"

Fires on every tick.

Kind: event emitted by Ticker
Properties

NameTypeDescription
tickCountnumberCurrent tick
deltanumberCurrent delta
0.0.2

4 years ago

0.0.1

4 years ago