Skip to content

Commit 889e27a

Browse files
committed
docs: add better notice about exection
1 parent 1892f00 commit 889e27a

File tree

1 file changed

+10
-1
lines changed
  • adminforth/documentation/docs/tutorial/03-Customization

1 file changed

+10
-1
lines changed

adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Hooks are used to:
1515
- modify the fetched data before it is displayed in the list and show
1616
- prevent the request to db depending on some condition (Better use [allowedActions](./05-limitingAccess.md) for this)
1717

18-
Every hook is executed when AdminForth frontend makes some internal API HTTP request to the backend.
18+
Every hook is executed when AdminForth frontend (Vue SPA) makes some internal API HTTP request to the backend. Every hook function is always executed only on backend side (Node.js) from the HTTP request handler and allows you to perform some actions before or after the actual request to datasource (database) is made. This is most flexible way to control flow and extend it with custom logic.
19+
1920

2021
Every hook must return one of two objects:
2122
1) If everything is fine and request flow should be continued hook should return `{ ok: true }`
@@ -27,6 +28,14 @@ For simplicity of course you can specify hook as scalar async function and not a
2728

2829
Here we will consider possible flows one by one
2930

31+
32+
### Performance notice
33+
34+
Every hook function is async, so you can use `await` inside it to perform some async operations like fetching data from another service or database, but please remember that while hook will not finish its execution, the request flow will be waiting for it. So every delay awaited in hook will delay the whole request. That is why we encourage you to use parallel async operations in hooks (like Promise.all) to make them faster.
35+
36+
If multiple hooks are defined (e.g. plugin might add own hook to `list.beforeDatasourceRequest` after you will already add one in your config), then hooks will be executed one by one, and can't be parallelized. This ensures that different hooks will not interfere with each other, but also means that if you have bootleneck in one hook, all other hooks will wait for it and whole request will be slower.
37+
38+
3039
## Initial data for edit page flow
3140

3241
When user opens edit page, AdminForth makes a request to the backend to get the initial data for the form.

0 commit comments

Comments
 (0)