Files
xen-orchestra/@vates/decorate-with/USAGE.md
2021-05-28 12:15:22 +02:00

817 B

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.