@webkrafters/long-count
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Long Count

Introduction

Long Count is a library of setInterval and setTimeout functions producing a LongCounter instance capable of handling superbly long delay times and surviving device sleep and wake cycles.

Name:

@webkrafters/long-count
Alternate: long-count.js

Installation

npm install --save @webkrafters/long-count

Usage

Timeout

import type {
    Delay,
    Options,
    VoidFn
} from '@webkrafters/long-count';

import {
    clearTimeout,
    setTimeout
} from '@webkrafters/long-count';

const timeout = setTimeout(
    callback : VoidFn,
    delay? : Delay,
    options? : boolean | Partial<Options>,
    ...args : Array<any>
); // => LongCounter

clearTimeout( timeout );
// or clearTimeout( timeout.id );
// or clearTimeout( timeout.valueOf() );

Interval

import type {
    Delay,
    Options,
    VoidFn
} from '@webkrafters/long-count';

import {
    clearInterval,
    setInterval
} from '@webkrafters/long-count';

const interval = setInterval(
    callback : VoidFn,
    delay? : Delay,
    options? : boolean | Partial<Options>,
    ...args : Array<any>
); // => Interval (a child LongCounter)

clearInterval( interval );
// or clearInterval( interval.id );
// or clearInterval( interval.valueOf() );

Events

The LongCounter instance is an observable notifying observers of the events.
See Event Types in the next section.

import type {
    EventType,
    VoidFn
} from '@webkrafters/long-count';

import { setTimeout } from '@webkrafters/long-count';

const timeout = setTimeout( ... ); // => LongCounter
timeout.addEventListener(
    eventType : EventType,
    listener : VoidFn
); // => void
timeout.dispatchEvent(
    eventType : EventType,
    ...args : Array<any>
); // => void
timeout.removeEventListener(
    eventType : EventType,
    listener : VoidFn
); // => void

Event Types

Type Event observed
cycleEnding End of a delay segment. A delay segment equals the platform time delay limit or the entire delay when less than the device limit.
cycleStarted Start of a delay segment. A delay segment equals the platform time delay limit or the entire delay when less than the device limit.
exit Eve of a LongCounter disposal.
resume Page receiving visibility (e.g. when waking from device "sleep" mode).
suspend Page losing visibility (e.g. when entering device "sleep" mode).

License

MIT

Dependents (1)

Package Sidebar

Install

npm i @webkrafters/long-count

Weekly Downloads

31

Version

1.0.1

License

MIT

Unpacked Size

237 kB

Total Files

28

Last publish

Collaborators

  • webkrafters