1.1.4 • Published 3 years ago

@refabric/extend v1.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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);
});