-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
state.ts
43 lines (42 loc) · 942 Bytes
/
state.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
37
38
39
40
41
42
43
import {Locals} from "@tsed/common";
/**
* State return the value from koa.ctx.state object.
*
* #### Example
*
* ```typescript
* * @Middleware()
* class StateMiddleware {
* use(@State() state: any) {
* // set some on locals
* state.user = "user"
* }
* }
*
* @Controller('/')
* @UseBefore(StateMiddleware)
* class MyCtrl {
* @Get('/')
* @Render('home.ejs') // will use locals and returned data to render the page
* get(@State('user') user: any) {
* console.log('user', user);
*
* return {
* description: 'Hello world'
* }
* }
* }
* ```
*
* @param expression The path of the property to get.
* @decorator
* @operation
* @input
* @response
* @koa
*/
export function State(expression: string): ParameterDecorator;
export function State(): ParameterDecorator;
export function State(...args: any[]): ParameterDecorator {
return (Locals as any)(...args);
}