2.2.0 • Published 9 months ago

@aegenet/belt-anti-bounce v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

npm version

@aegenet/belt-anti-bounce

@antiBounce a debounce decorator for TypeScript classes to prevent multiple calls in a short period of time.

Note: Stage 3 decorator (for stage 2, you can use an older version (< 2.0.0) of this package).

💾 Installation

yarn add @aegenet/belt-anti-bounce@^2.0.0
# or
npm i @aegenet/belt-anti-bounce@^2.0.0

📝 Usage

import { IAntiBounceSupport, IAntiBounce, disposeAntiBounces } from '@aegenet/belt-anti-bounce';

class Sample implements IAntiBounceSupport {
  public declare $antiBounces?: Map<string, IAntiBounce>;
  private _i = 0;

  @antiBounce({ duration: 300 })
  public inc(): void {
    this._i++;
  }

  public main() {
    this.inc();
    this.inc();
    this.inc();
    // this._i => 1
  }

  public dispose() {
    disposeAntiBounces(this);
  }
}

AntiBounce, utility

import { AntiBounce } from '@aegenet/belt-anti-bounce';

let i = 0;
const diposable = new AntiBounce(() => i++, 300);
assert.strictEqual(i, 0);
// Go !
diposable.call();
diposable.call();
diposable.call();
diposable.call();
// i = 0
await delay(300);
// i = 1

diposable.dispose();
2.2.0

9 months ago

2.1.0

11 months ago

1.6.2

12 months ago

1.7.0

12 months ago

2.0.0

12 months ago

1.5.0

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

2 years ago