Skip to content

dldc-packages/stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b3e55c0 · Jun 13, 2023

History

32 Commits
Jun 10, 2023
Jun 13, 2023
Jun 13, 2023
Jun 13, 2023
Jun 12, 2023
Jun 11, 2023
Jun 11, 2023
Jun 10, 2023
Jun 12, 2023
Jun 11, 2023
Jun 11, 2023
Jun 11, 2023
Jun 13, 2023
Jun 11, 2023
Jun 12, 2023
Jun 10, 2023

Repository files navigation

🏯 Staack

A library to create type-safe opaque stacks

Example

// TODO

Installation

npm install staack
# or
yarn add staack

Extending Staack

You can create your own Staack:

class CustomStaack extends Staack {
  // You need to override the `with` method to return a new instance of your CustomStaack
  with(...keys: Array<KeyProvider<any>>): CustomStaack {
    // Use the static `applyKeys` method to apply keys to the current instance
    return Staack.applyKeys<CustomStaack>(this, keys, (internal) => new CustomStaack(internal));
  }
}

const custom = new CustomStaack();
expect(custom instanceof CustomStaack).toBe(true);
expect(custom instanceof Staack).toBe(true);

If you want to pass custom arguments to yout CustomStaack:

class ParamsStaack extends Staack {
  // You can pass your own parameters to the constructor
  constructor(public readonly param: string, internal: StaackInternal<ParamsStaack> | null = null) {
    super(internal);
  }

  with(...keys: Array<KeyProvider<any>>): ParamsStaack {
    return Staack.applyKeys<ParamsStaack>(this, keys, (internal) => new ParamsStaack(this.param, internal));
  }
}

const custom = new ParamsStaack('some value');
expect(custom.param).toBe('some value');
expect(custom instanceof ParamsStaack).toBe(true);
expect(custom instanceof Staack).toBe(true);