r3bl-ts-utils
Version:
The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu
48 lines (47 loc) • 1.74 kB
TypeScript
import { Optional } from "../lang-utils/core";
import { Option } from "../lang-utils/rust-lang-utils";
import { Counter } from "./counter";
import { State, TimerTickFn } from "./externals";
import { TimerInternal } from "./internals";
export declare const NoDuration = -1;
export declare class TimerImpl implements TimerInternal {
readonly name: string;
readonly delayMs: number;
readonly durationMs: number;
readonly counter?: Counter | undefined;
/**
* Node.js uses Timeout and browser uses number. ReturnType<typeof setTimeout> handles this 🎉.
*
* More info:
* - https://tinyurl.com/y2bssbfr
* - https://stackoverflow.com/a/56970244/2085356
* @private
*/
private timerHandle?;
private _state;
private _onTickFn;
private _onStopFn;
private _onStartFn;
constructor(name: string, delayMs: number, durationMs?: number, counter?: Counter | undefined);
getOnStopFn(): Option<TimerTickFn>;
setOnStopFn(fn: Optional<TimerTickFn>): void;
getOnStartFn(): Option<TimerTickFn>;
setOnStartFn(value: Optional<TimerTickFn>): void;
getOnTickFn(): Option<TimerTickFn>;
setOnTickFn(fn: Optional<TimerTickFn>): void;
/**
* Computes the new state using `TimerReducer.reducerFn` and puts it `this.state` property.
* @param action if not provided compute initial state, else use it to get new state
* @return new state object
*/
private dispatch;
startTicking: () => this;
stopTicking: () => this;
get isStopped(): boolean;
get isRunning(): boolean;
get isCreatedAndNotStarted(): boolean;
get state(): State;
actuallyStart: () => void;
actuallyStop: () => void;
toString: () => string;
}