polyplug

1.0.0-1 • Public • Published

polyplug

Simple plugin system

This is prerelease software.

Usage

const polyplug = require('polyplug')
 
class A {
  constructor() {
    this.initialize()
    this.bar()
  }
}
 
class B {
  initialize() {
    // ...
  }
  bar()
}
 
polyplug(A, B)

Assume A is the main class and B is the plugin class.

The above will merge B's prototype into A's, just like a mixin. This won't make instances of A instances of B, though.

This also assumes no instances of B will ever be created. Instead, plugin classes can declare initialize(). When polyplug(A, B) is called, the definition of B's initialize() will be added to A's. Essentially, calling (new A).initialize() will first call A.prototype.initialze() followed by B.prototype.initialize.

This initialize() functionality is optional and can be missing from either A or B.

All members visible to Object.getOwnPropertyNames() and Object.getOwnPropertySymbols will be copied.

License

MIT

/polyplug/

    Package Sidebar

    Install

    npm i polyplug

    Weekly Downloads

    0

    Version

    1.0.0-1

    License

    MIT

    Last publish

    Collaborators

    • seangenabe