Options
All
  • Public
  • Public/Protected
  • All
Menu

A Simple Timer class extending EventEmitter3

Auther: Shen Yiming(soimy@163.com)

Repo: https://github.com/soimy/eventemitter3-timer

export
class

Timer

extends

{EventEmitter}

Hierarchy

  • EventEmitter
    • Timer

Index

Constructors

constructor

  • new Timer(time?: number): Timer
  • Creates an instance of Timer.

    Newly created timers will be default to be added to the global timerManager. Can manually create TimerManager and assign timers.

    memberof

    Timer

    Parameters

    • Default value time: number = 1

    Returns Timer

Properties

Private _delayTime

_delayTime: number

Private _elapsedTime

_elapsedTime: number

Private _repeat

_repeat: number

Private _timerManager

_timerManager: TimerManager | null

active

active: boolean

The activation status of timer.

type

{boolean}

memberof

Timer

delay

delay: number

Delay in ms before timer starts

type

{number}

memberof

Timer

expire

expire: boolean

Whether this timer is expired and should be removed from timerManager.

type

{boolean}

memberof

Timer

isEnded

isEnded: boolean

Status indicator: whether this timer is ended.

type

{boolean}

memberof

Timer

isStarted

isStarted: boolean

Status indicator: whether this timer is started.

type

{boolean}

memberof

Timer

loop

loop: boolean

Whether this timer loops forever

type

{boolean}

memberof

Timer

repeat

repeat: number

The repeat count before timer stop

type

{number}

memberof

Timer

time

time: number

The time until timer triggered.

type

{number}

memberof

Timer

Static Private _timerManager

_timerManager: TimerManager

Static prefixed

prefixed: string | boolean

Accessors

timerManager

timerManager:

The timerManager this timer is assigned to.

type

{(TimerManager | null)}

memberof

Timer

Static timerManager

timerManager:

The global TimerManager which is default to all newly created timers.

static
type

{TimerManager}

memberof

Timer

Methods

addListener

  • addListener(event: string | symbol, fn: ListenerFn, context?: any): this
  • Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns this

emit

  • emit(event: string | symbol, ...args: Array<any>): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string | symbol
    • Rest ...args: Array<any>

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<string | symbol>

listenerCount

  • listenerCount(event: string | symbol): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Array<ListenerFn>
  • Return the listeners registered for a given event.

    Parameters

    • event: string | symbol

    Returns Array<ListenerFn>

off

  • off(event: string | symbol, fn?: ListenerFn, context?: any, once?: undefined | true | false): this
  • Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: undefined | true | false

    Returns this

on

  • on(event: string | symbol, fn: ListenerFn, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns this

once

  • once(event: string | symbol, fn: ListenerFn, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns this

remove

  • Remove this timer from it's timerManager.

    memberof

    Timer

    Returns Timer

    Return self for chainable method.

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, fn?: ListenerFn, context?: any, once?: undefined | true | false): this
  • Remove the listeners of a given event.

    Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: undefined | true | false

    Returns this

reset

  • Rest timer to it's initial status.

    memberof

    Timer

    Returns Timer

    Return self for chainable method.

start

  • Start timer from it's current time.

    A started event will be emitted.

    memberof

    Timer

    Returns Timer

    Return self for chainable method.

stop

  • Stop timer, current time stop updated.

    A ended event will be emitted.

    memberof

    Timer

    Returns Timer

    Return self for chainable method.

update

  • update(delta: number): void
  • Increment timer's time. Should be put in main logic loop.

    Using TimerManager.update() method instead is recommended.

    memberof

    Timer

    Parameters

    • delta: number

      The amount of increment in ms.

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc