-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.decorator.ts
36 lines (33 loc) · 1003 Bytes
/
component.decorator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @module Decorators
*/
import { ComponentConfig } from '../index';
import { componentStore, ComponentStore } from '../internal.index';
/**
*
* Class Decorator Function
*
* A collection of endpoints. Every endpoints in this will apply the given metadata.
* Add the class Symbols to the application components array (similar to angular module)
* to apply them to an application
* @returns
*
* @example
* ```typescript
*
* @Component({
* route: '/api',
* middleware: [(request: Request, response: Response) => { }]
* })
* class Test {}
* ```
* **/
export function Component(conf: ComponentConfig) {
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
const store: ComponentStore = componentStore.get(constructor.name) || {} as ComponentStore;
store.componentRoute = conf.route;
store.componentMiddleware = conf.middleware || [];
componentStore.set(constructor.name, store);
return constructor;
}
}