xen-orchestra/@vates/decorate-with
2021-05-31 14:29:23 +02:00
..
.npmignore feat: unified .npmignore for all packages 2021-04-07 13:58:14 +02:00
index.js feat(decorate-with): decorateMethodsWith() 2021-05-28 12:15:22 +02:00
package.json feat(@vates/decorate-with): 0.1.0 (#5795) 2021-05-31 14:29:23 +02:00
README.md feat(decorate-with): decorateMethodsWith() 2021-05-28 12:15:22 +02:00
USAGE.md feat(decorate-with): decorateMethodsWith() 2021-05-28 12:15:22 +02:00

@vates/decorate-with

Package Version License PackagePhobia Node compatibility

Creates a decorator from a function wrapper

Install

Installation of the npm package:

> npm install --save @vates/decorate-with

Usage

decorateWith(fn, ...args)

Creates a new (legacy) method decorator from a function decorator, for instance, allows using Lodash's functions as decorators:

import { decorateWith } from '@vates/decorate-with'

class Foo {
  @decorateWith(lodash.debounce, 150)
  bar() {
    // body
  }
}

decorateMethodsWith(class, map)

Decorates a number of methods directly, without using the decorator syntax:

import { decorateMethodsWith } from '@vates/decorate-with'

class Foo {
  bar() {
    // body
  }

  baz() {
    // body
  }
}

decorateMethodsWith(Foo, {
  // without arguments
  bar: lodash.curry,

  // with arguments
  baz: [lodash.debounce, 150],
})

The decorated class is returned, so you can export it directly.

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Vates SAS