easy-decorator

A utility function for writing ES7 method/getter decorators.

Usage no npm install needed!

<script type="module">
  import easyDecorator from 'https://cdn.skypack.dev/easy-decorator';
</script>

README

easy-decorator

Install

npm install easy-decorator --save

Example

import easyDecorator from 'easy-decorator';
import _ from 'lodash';

const once = easyDecorator(fn => {
  let hasRun = false;
  let result;
  return function() {
    if(!hasRun) {
      result = fn.apply(this, arguments);
      hasRun = true;
    }
    return result;
  };
});

const throttle = easyDecorator(_.throttle);

class C {
  @once get myGetter() {

  }

  @once myMethod() {

  }

  @throttle(250) myThrottledMethod() {

  }
}