@schamane/component-container
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Container and component typescript library

create your container with components

How to use

npm install @schamane/component-container

Start using package in your code like that

import { Container } from '@schamane/component-container';

const cont =  new Container();
console.log(cont.getAllComponents());

Documentation

Use Component as base class to extend it for own needs. As example create container for holding string.

import { Component } from '@schamane/component-container';

export class StringComponent<T extends string> extends Component {
  protected prop: T;

  public constructor(item?: T) {
    super(StringComponent);
    this.prop = item || undefined;
  }

  public get(): T {
    return this.prop;
  }

  public set(value: T): void {
    this.prop = value;
  }
}

Now create Container

import { Container } from '@schamane/component-container';
import { StringComponent } from './stringComponent';

const cont =  new Container();
cont.addComponent(new StringComponent('testItem1'));
cont.addComponent(new StringComponent('testItem2'));

console.log(cont.getAllComponents());

Now you can create one more complex container. Add it to your container. Than you can use getComponent and getComponents.

console.log(cont.getComponent(StringComponent));

This will returns you first found component from container by Type.

/@schamane/component-container/

    Package Sidebar

    Install

    npm i @schamane/component-container

    Weekly Downloads

    1

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    25.3 kB

    Total Files

    36

    Last publish

    Collaborators

    • schamane