1.0.0 • Published 4 years ago

@sebowy/proxy-builder v1.0.0

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

Installation

npm install --save @sebowy/proxy-builder
# or
yarn add @sebowy/proxy-builder

Usage

Examples

  • examples with timeouts
import createProxyBuilder, { Builder } from '.';

interface ICarData {
  color: 'red' | 'green' | 'blue';
  doors: 3 | 5;
  engine: 'V6' | 'V8';
}

interface ICarTypeResult {
  carType: 'sport' | 'van';
}

class CarTypeBuilder extends Builder<ICarData, ICarTypeResult> {
  build(): ICarTypeResult {
    if (this.isSportCar()) {
      return { carType: 'sport' };
    }
    return { carType: 'van' };
  }

  private isSportCar(): boolean {
    return this._data.color === 'red' && this._data.engine === 'V8' && this._data.doors === 3;
  }
}

const builder = createProxyBuilder(CarTypeBuilder);
const carTypeResult = builder
  .color('red')
  .doors(3)
  .engine('V8')
  // build method is not available until all properties are set
  .build();
1.0.0

4 years ago