@refabric/extend
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

Refabric Extend

Framework to create extensible classes that behave like middleware holders and event emitters.

Get Started

Install extend.

npm install @refabric/extend

Extend the extensible class.

import { Extensible } from '@refabric/extend';
import assert from 'assert';

class Counter extends Extensible {
  async count(context) {
    await this.processExtensions(context);
  }
}

const counter = new Counter();
counter.extend((ctx) => ctx.count++);
counter.extend((ctx) => ctx.count *= 2);

const ctx = {
  count: 1,
};

counter.count(ctx).then(() => {
  assert(ctx.count === 4);
});

/@refabric/extend/

    Package Sidebar

    Install

    npm i @refabric/extend

    Weekly Downloads

    3

    Version

    1.1.4

    License

    ISC

    Unpacked Size

    5.32 kB

    Total Files

    10

    Last publish

    Collaborators

    • popon