es-decorators

Most useful EcmaScript decorators

Usage no npm install needed!

<script type="module">
  import esDecorators from 'https://cdn.skypack.dev/es-decorators';
</script>

README

es-decorators Build Status

Most useful EcmaScript decorators

Usage

import {Debounce, Defaults} from 'es-decorators';

@Defaults({
  ammunitionCount: 100
})
class Panzer {
  
  @Debounce(1000, {leading: true})
  fire() {
    // ...
  }
  
}

API

@Autobind

binds method to container (e.g. class or object)

@Defaults(props)

props {object}
@Defaults decorator slightly differs from lodash.defaults

@Debounce(duration, [options])

duration {number}
options {object} see lodash.debounce

@Throttle(duration, [options])

duration {number}
options {object} see lodash.throttle

@Memoize([resolver])

resolver {function} see lodash.memoize

@Once

see lodash.once

@Retry([count = 0])

count {number} retry count. 0 means no retries, simply call.
Assumes that decorated function returns promise. The function will be called up to count times until it is resolved.

@DecorateInstance(decorator, ...args)

decorator {function}
args {*[]}
@DecorateInstance transforms instance method with provided decorator when it is accessed first time