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
Copy file name to clipboardExpand all lines: docs/guide/schema/collection.md
+149Lines changed: 149 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,155 @@ const store = await createStore({
88
88
The [currying](https://en.wikipedia.org/wiki/Currying) is necessary to specify the type of the item while still letting TypeScript infer the type of the collection. This is a limitation of TypeScript, and [it might improve in the future](https://github.com/microsoft/TypeScript/issues/26242).
89
89
:::
90
90
91
+
## Collection hooks
92
+
93
+
You can define hooks on the collection that will be called at different stages of the item lifecycle in the `hooks` option. The available hooks are:
94
+
95
+
-`fetchFirst`: fetch a single item by its key or by other parameters
96
+
-`fetchMany`: fetch multiple items
97
+
-`create`: create a new item
98
+
-`update`: update an existing item
99
+
-`delete`: delete an item
100
+
101
+
::: tip
102
+
Instead of defining the hooks in the collection, you can also create a plugin to handle the fetching logic for many collections at once and with a larger choice of hooks (see [Plugins](../plugin/setup.md)).
103
+
:::
104
+
105
+
Each hook receives a payload object with the following properties:
106
+
-`fetchFirst`:
107
+
-`key` (optional): the key of the item to fetch
108
+
-`params` (optional): additional parameters for the fetch
109
+
-`include` (optional): dictionnary of related items to include (see [Relations](./relations.md))
110
+
-`fetchMany`:
111
+
-`params` (optional): additional parameters for the fetch (if available)
112
+
-`include` (optional): dictionnary of related items to include (see [Relations](./relations.md))
rstore uses a normalized cache to store the data. This means that each item is stored in a flat structure, and the key is used to identify the item in the cache.
0 commit comments