state-transition-buffer
TypeScript icon, indicating that this package has built-in type declarations

0.1.10 • Public • Published

state-transition-buffer

Does state change too quickly? With stage-transition-buffer, the minimum duration of any state can be secured.

usage example

import { StateBuffer } from '../dist/src/index.js';

let connectionState = new StateBuffer({
  defaultMinDuration: 1000,
  removeLastDuplicated: true
});

let onchange = () => {
  let bufferedState = connectionState.first; //the one to show to user
  let realtimeState = connectionState.last;
  console.info(new Date(), bufferedState, realtimeState);
};
connectionState.registerChangeHandler(onchange);
connectionState.push("connecting...");
connectionState.push("connected", 2000);
connectionState.push();
connectionState.push("re-connecting...");
connectionState.push("failed to connect");
connectionState.push("re-connecting...");
connectionState.push("failed to connect");
connectionState.removeChangeHandler(onchange);

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i state-transition-buffer

    Weekly Downloads

    1

    Version

    0.1.10

    License

    MIT

    Unpacked Size

    15.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • xuan9