1.8.0 • Published 2 years ago

plugin-decorator v1.8.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

plugin-decorator

Using TypeScript MIT License NPM

plugin-decorator is a library of tools to quickly empower your projects with plugins!

import { Hook, Inject, PluginTarget, Plugin } from 'plugin-decorator';

class DemoTarget extends PluginTarget {
  @Hook()
  public method1() {
    console.log('origin method');
  }
}

class DemoPlugin extends Plugin {
  @Inject()
  public method1(next) {
    next();
    console.log('plugin method');
  }
}

const demoTarget = new DemoTarget();
demoTarget.install(new DemoPlugin());
demoTarget.method1();

// => origin method
// => plugin method

Decorator

import { Hook, Inject, PluginTarget, Plugin } from 'plugin-decorator';

class DemoTarget extends PluginTarget {
  @Hook()
  public method1() {
    return 'origin method';
  }
}

class DemoPlugin extends Plugin {
  @Inject()
  public method1(next) {
    return `plugin ${next()}`;
  }
}

const demoTarget = new DemoTarget();
demoTarget.install(new DemoPlugin());

demoTarget.method1();

// => plugin origin method

Promise

import { Hook, Inject, PluginTarget, Plugin } from 'plugin-decorator';

class DemoTarget extends PluginTarget {
  @Hook()
  public methodPromise() {
    return new Promise((resolve) => {
      setTimeout(() => resolve('origin method'), 1000);
    });
  }
}

class DemoPlugin extends Plugin {
  @Inject()
  public async methodPromise(next) {
    return `plugin ${await next()}`;
  }
}

const demoTarget = new DemoTarget();
demoTarget.install(new DemoPlugin());

demoTarget.methodPromise().then(console.log);

// => Promise<plugin origin method>
1.8.0

2 years ago

1.7.1

2 years ago

1.7.0

3 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago