@remembered/decorator
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Actions Status Actions Status Actions Status Test Coverage Maintainability Packages npm version

Decorator for easy remembered appliance.

How to Install

npm i @remembered/decorator remembered

How to use it

Apply the decorator UseRemembered to every method you want:

class MyClass {
  @UseRemembered((a: SomeType) => a.id)
  async myMethod(a: SomeType) {
    return processResult(a);
  }
}

Notice that the decorator needs a callback to define how the remembering key will be generated. this callback will be called with the exactly same parameters myMethod is called. The decorator itself will not make any difference but, in some initialization part of your code, after all your classes are already loaded (which is trivial if you're using the default class declaration and import pattern), just call setupRemembered:

setupRemembered((class) => injector.get(Remembered));

Look that setupRemembered receives a callback that must return a Remembered instance. This callback receives a reference to the Class object where Remembered will be applied. This way, you have control on how you want to instantiate it, or if you want to use some extension like @remembered/redis. There is also a helper function that guarantees to you that only one instance per decorated class will be returned. To use it, you can do like this:

setupRemembered(getRememberedByClassFactory((class) => injector.get(Remembered)));

License

Licensed under MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i @remembered/decorator

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

10.7 kB

Total Files

12

Last publish

Collaborators

  • danielgaleni
  • farenheith