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/plugin/setup.md
+53-3Lines changed: 53 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,38 @@ export default definePlugin({
20
20
21
21
The `setup` function is called when the plugin is registered. It receives a `pluginApi` object that contains useful methods to customize the store.
22
22
23
+
## Category
24
+
25
+
Plugins can be categorized to define their role in the data flow. The available categories are:
26
+
27
+
-`virtual`: Plugins that provide virtual/in-memory collections that do not have any persistent storage.
28
+
-`local`: Plugins that handle local data sources in the current device, such as saving it to a client-side database or storage such as IndexedDB or LocalStorage.
29
+
-`remote`: Plugins that handle remote data sources, such as REST APIs or GraphQL APIs.
30
+
-`processing`: Plugins that process data, such as transforming or validating it.
31
+
32
+
By default plugins will be sorted based on their category in the following order:
33
+
34
+
1.`virtual`
35
+
2.`local`
36
+
3.`remote`
37
+
4.`processing`
38
+
39
+
You can customize the sorting using the `before` and `after` options (see [Sorting plugins](#sorting-plugins)).
40
+
41
+
```ts{5-7}
42
+
import { definePlugin } from '@rstore/vue'
43
+
44
+
export default definePlugin({
45
+
name: 'my-plugin',
46
+
// Will be after 'virtual' and 'local' plugins
47
+
// and before 'processing' plugins
48
+
category: 'remote',
49
+
setup(pluginApi) {
50
+
// Plugin code goes here
51
+
},
52
+
})
53
+
```
54
+
23
55
## Hooks
24
56
25
57
Hooks are the primary way to extend the functionality of the store. They allow you to run custom code at different points in the lifecycle of the store. The hooks are called in the order they are defined.
Plugins are sorted based on their dependencies. You can specify that a plugin should be loaded before or after another plugin using the `before` and `after` options:
152
+
Plugins are sorted based on their dependencies and category. You can specify that a plugin should be loaded before or after another plugin or category using the `before` and `after` options:
121
153
122
154
```ts
123
155
import { definePlugin } from'@rstore/vue'
124
156
125
157
exportdefaultdefinePlugin({
126
158
name: 'my-plugin',
127
-
before: ['another-plugin'],
128
-
after: ['yet-another-plugin'],
159
+
before: {
160
+
plugins: ['another-plugin'],
161
+
categories: ['remote'],
162
+
},
163
+
after: {
164
+
plugins: ['yet-another-plugin'],
165
+
categories: ['virtual'],
166
+
},
129
167
})
130
168
```
169
+
170
+
Each property of `before` and `after` is optional, you can either specify `plugins`, `categories`, or both.
171
+
172
+
::: warning
173
+
Be mindful of circular dependencies when using `before` and `after`. For example, if Plugin A is set to load after Plugin B, and Plugin B is set to load after Plugin A, this will create a circular dependency that cannot be resolved. The system will detect such circular dependencies and handle them gracefully by skipping the remaining sorting rules (with a warning printed to the console).
174
+
175
+
Prioritization is done in the following order:
176
+
177
+
-`before.plugins` and `after.plugins` have the highest priority.
178
+
-`before.categories` and `after.categories` have the next priority.
0 commit comments