https://github.com/schamane/component-container
Library for typescript for basic components and containers feature
https://github.com/schamane/component-container
Last synced: 2 months ago
JSON representation
Library for typescript for basic components and containers feature
- Host: GitHub
- URL: https://github.com/schamane/component-container
- Owner: schamane
- License: other
- Created: 2019-11-19T23:11:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T11:56:18.000Z (over 2 years ago)
- Last Synced: 2025-03-26T09:21:35.881Z (2 months ago)
- Language: TypeScript
- Size: 382 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```ts
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.
```ts
import { Component } from '@schamane/component-container';export class StringComponent 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
```ts
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.
```ts
console.log(cont.getComponent(StringComponent));
```This will returns you first found component from container by Type.