rateLimit

@rateLimit

(n: number): MethodDecorator

Observer method decorator: limit the decorated asynchronous observer method to be invoked only at a maximum frequency, determined by the given number of milliseconds.

Note: This decorator is intended for use on methods that are part of an observer class, see observe().

Example

class MyComponent extends Component {
  foo = "";
}

class MyComponentObserver {
  constructor (public readonly c: MyComponent) { }

  @rateLimit(100)
  async onFooChangeAsync() {
    console.log("foo changed: " + this.c.foo);
  }
}

observe(MyComponent, MyComponentObserver);

let c = new MyComponent();
c.foo = "bar";
setTimeout(() => { c.foo = "baz" }, 50);
// after 100ms => foo changed: baz