You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of prescribing one pattern over another, this change presents all three
approaches for grouping service functions (plain object, namespace, abstract class)
using tabs, letting developers choose based on their background and preferences.
Changes:
- Add Tab component to best-practice.md for service pattern examples
- Update main service.ts example to use plain object (simplest approach)
- Keep all three patterns as valid options in the Service section
- Revert controller examples to original (abstract class)
- Remove Function Containers section from typescript.md (rationale belongs in PR)
Copy file name to clipboardExpand all lines: docs/essential/best-practice.md
+72-9Lines changed: 72 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,10 @@ head:
14
14
content: Elysia is a pattern agnostic framework, we leave the decision up to you and your team for coding patterns to use. However, we found that there are several who are using MVC pattern (Model-View-Controller) on Elysia, and found it's hard to decouple and handle types. This page is a guide to use Elysia with MVC pattern.
15
15
---
16
16
17
+
<scriptsetup>
18
+
importTabfrom'../components/fern/tab.vue'
19
+
</script>
20
+
17
21
# Best Practice
18
22
19
23
Elysia is a pattern-agnostic framework, leaving the decision of which coding patterns to use up to you and your team.
@@ -85,10 +89,9 @@ import { status } from 'elysia'
85
89
86
90
importtype { AuthModel } from'./model'
87
91
88
-
// If the class doesn't need to store a property,
89
-
// you may use `abstract class` to avoid class allocation
@@ -280,16 +283,72 @@ There are 2 types of service in Elysia:
280
283
281
284
We recommend abstracting a service class/function away from Elysia.
282
285
283
-
If the service or function isn't tied to an HTTP request or doesn't access a `Context`, it's recommended to implement it as a static class or function.
286
+
If the service or function isn't tied to an HTTP request or doesn't access a `Context`, you can group related functions using several patterns depending on your preference:
0 commit comments