1.0.2 • Published 10 months ago

@simulacron/decorators v1.0.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
10 months ago

Decorators

A set of handy JavaScript decorators.

autobind

Binds a class context to a method.

Allows you to use class methods as an event handler, without the additional bind:

connectedCallback() {
  // ...
  this.addEventListener('click', this.toggle);
}

disconnectedCallback() {
  this.removeEventListener('click', this.toggle);
  // ...
}

@autobind()
toggle(event) {

}

Such methods can be used in removeEventListener since they are pointers to the same instance used in addEventListener.

debounce

Debounce the execution of the method.

You can specify the value in milliseconds as a number or in string format with the suffix '<delay>ms', supported suffixes: ms - milliseconds, s - seconds, m - minutes.

This can be handy for events such as key presses or "input" in input fields.

@debounce('300ms')
inputChanged(event) {
  // ...
}

throttle

Throttle the execution of the method.

You can specify the value in milliseconds as a number or in string format with the suffix '<delay>ms', supported suffixes: ms - milliseconds, s - seconds, m - minutes.

This can be handy for "resize" or "scroll" events.

@throttle('500ms')
resizeChanged(event) {
  // ...
}
1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago