Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

675 B
Raw Blame
export class PaletteDebouncer {
  #timer: number | null = null;
  readonly #commit: (value: string) => void;
  readonly #delayMs: number;

  constructor(delayMs: number, commit: (value: string) => void) {
    this.#commit = commit;
    this.#delayMs = delayMs;
  }

  cancel = (): void => {
    if (this.#timer !== null) {
      window.clearTimeout(this.#timer);
      this.#timer = null;
    }
  };

  commit = (value: string): void => {
    this.cancel();
    this.#commit(value);
  };

  schedule = (value: string): void => {
    this.cancel();
    this.#timer = window.setTimeout(() => {
      this.#timer = null;
      this.#commit(value);
    }, this.#delayMs);
  };
}