Skip to content

Commit 70f5b99

Browse files
authored
Merge branch 'main' into homepage-typo
2 parents f5ec79a + 191edc7 commit 70f5b99

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

docs/.vitepress/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export default defineConfig({
128128
text: 'Derive',
129129
link: '/concept/derive'
130130
},
131+
{
132+
text: 'Plugin',
133+
link: '/concept/plugin'
134+
},
131135
{
132136
text: 'Group',
133137
link: '/concept/group'
@@ -152,10 +156,6 @@ export default defineConfig({
152156
text: 'Config',
153157
link: '/concept/config'
154158
},
155-
{
156-
text: 'Plugin',
157-
link: '/concept/plugin'
158-
},
159159
{
160160
text: 'Explicit Body',
161161
link: '/concept/explicit-body'

docs/concept/plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ You can customize plugin by creating function to return callback which accepts E
7474
```typescript
7575
import { Elysia } from 'elysia'
7676

77-
const plugin = ({
77+
const plugin = <const Prefix>({
7878
prefix = '/v1'
79-
}) => (app: Elysia) => app
79+
}: { prefix: Prefix }) => new Elysia({ prefix })
8080
.get(`/${prefix}/hi`, () => 'Hi')
8181

8282
const app = new Elysia()

docs/patterns/dependency-injection.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const app = new Elysia()
2727
// and so on...
2828

2929
// routes/authen.ts
30-
const authen = (app: Elysia) => app
30+
const authen = new Elysia()
3131
.post('/sign-in', signIn)
3232
.post('/sign-up', signUp)
3333
```
@@ -43,7 +43,7 @@ const app = new Elysia()
4343
// and so on...
4444

4545
// routes/authen.ts
46-
const authen = (app: Elysia) => app
46+
const authen = new Elysia()
4747
.post('/sign-in', signIn)
4848
.post('/sign-up', signUp)
4949
// But then there is no type
@@ -56,7 +56,7 @@ const authen = (app: Elysia) => app
5656

5757
If you hovered over the main `app` in `index.ts`, you can see that it has some type auto-generated for your main server which might look something like this:
5858
```typescript
59-
const app: Elysia<{
59+
const app: Elysia<'', {
6060
store: {
6161
redis: Redis;
6262
};
@@ -72,12 +72,12 @@ But this type isn't applied to sub-modules.
7272
To apply the type to sub-modules, you can create a plugin which only contains `state` and `decorate` which caused **type side-effect** as dependency, and apply to the module you want to use.
7373
7474
```typescript
75-
const setup = (app: Elysia) => app
75+
const setup = new Elysia({ name: 'setup' })
7676
.decorate('signOut', signOut)
7777
.state('redis', redis)
7878

7979
// routes/authen.ts
80-
const authen = (app: Elysia) => app
80+
const authen = new Elysia()
8181
.use(setup)
8282
.post('/sign-in', signIn)
8383
.post('/sign-up', signUp)

docs/patterns/reference-models.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,13 @@ Now when we need to quickly access the model's group, we can separate a `setMode
8484
// auth.model.ts
8585
import { Elysia } from 'elysia'
8686

87-
export const authModel = (app: Elysia) =>
88-
app
89-
.model({
90-
sign: t.Object({
91-
username: t.String(),
92-
password: t.String()
93-
})
87+
export const authModel = new Elysia()
88+
.model({
89+
sign: t.Object({
90+
username: t.String(),
91+
password: t.String()
9492
})
93+
})
9594

9695
// index.ts
9796
import { Elysia } from 'elysia'
@@ -113,15 +112,14 @@ const app = new Elysia()
113112
// auth.model.ts
114113
import { Elysia } from 'elysia'
115114

116-
export const authModel = (app: Elysia) =>
117-
app
118-
.model({
119-
sign: t.Object({
120-
username: t.String(),
121-
password: t.String()
122-
}),
123-
number: t.Number()
124-
})
115+
export const authModel = new Elysia()
116+
.model({
117+
sign: t.Object({
118+
username: t.String(),
119+
password: t.String()
120+
}),
121+
number: t.Number()
122+
})
125123
```
126124

127125
## Naming Convention
@@ -133,24 +131,22 @@ Let's say that you have all models stored at `models/<name>.ts`, you can declare
133131

134132
```typescript
135133
// admin.model.ts
136-
export const authModel = (app: Elysia) =>
137-
app
138-
.model({
139-
'admin.auth': t.Object({
140-
username: t.String(),
141-
password: t.String()
142-
})
134+
export const authModel = new Elysia()
135+
.model({
136+
'admin.auth': t.Object({
137+
username: t.String(),
138+
password: t.String()
143139
})
140+
})
144141

145142
// user.model.ts
146-
export const authModel = (app: Elysia) =>
147-
app
148-
.model({
149-
'user.auth': t.Object({
150-
username: t.String(),
151-
password: t.String()
152-
})
143+
export const authModel = new Elysia()
144+
.model({
145+
'user.auth': t.Object({
146+
username: t.String(),
147+
password: t.String()
153148
})
149+
})
154150
```
155151

156152
This can prevent naming duplication at some level, but in the end, it's best to let the naming convention decision up to your team's agreement is the best option.

0 commit comments

Comments
 (0)