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/service-plugin.md
+10-35Lines changed: 10 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,45 +4,17 @@ title: Service Plugin
4
4
5
5
<!-- markdownlint-disable MD002 MD033 MD041 -->
6
6
7
-
The `Service Module` creates plugins which can be used to connect a Feathers service to the Vuex store. Once you create the plugin, you must register it in the `plugins` section of your store setup:
7
+
The `Service Plugin` creates a vuex plugin which connects a Feathers service to the Vuex store. Once you create the plugin, you must register it in the `plugins` section of your store setup:
8
8
9
-
Here's a basic example of creating a service plugin:
9
+
See the [setup documentation](/api-overview.html#service-plugins) to learn the basics of setting up a Service Plugin.
10
10
11
-
```js
12
-
// src/services/users.js
13
-
importfeathersVuexfrom'feathers-vuex'
14
-
importfeathersClientfrom'../../feathers-client'
15
-
16
-
const { service } =feathersVuex(feathersClient, { idField:'_id' })
17
-
18
-
constservicePath='users'
19
-
constservicePlugin=service(servicePath)
20
-
21
-
exportdefaultservicePlugin
22
-
```
23
-
24
-
The above code block demonstrates setting up a service plugin, but the plugin doesn't run until you register it with Vuex, as shown in this next example:
Feathers-Vuex 2.0 includes a few breaking changes to the service plugin. Some of these changes are being made to prepare for future compatibility beyond FeathersJS
38
14
39
-
exportdefaultnewVuex.Store({
40
-
plugins: [
41
-
users: usersPlugin,
42
-
auth({ userService:'users' })
43
-
]
44
-
})
45
-
```
15
+
- The `service` method is now called `makeServicePlugin`
16
+
- The Feathers Client service is no longer created, internally, so a Feathers service object must be provided instead of just the path string.
17
+
- A Model class is now required. The `instanceDefaults` API has been moved into the Model class. You can find a basic example of a minimal Model class in the [Data Modeling](/model-classes.html) docs.
46
18
47
19
Old example from the api-overview page:
48
20
@@ -68,6 +40,9 @@ export default new Vuex.Store({
68
40
nameStyle:'path', // Use the full service path as the Vuex module name, instead of just the last section
69
41
namespace:'custom-namespace', // Customize the Vuex module name. Overrides nameStyle.
70
42
debug:true, // Enable some logging for debugging
43
+
servicePath:'', // Not all Feathers service plugins expose the service path, so it can be manually specified when missing.
44
+
instanceDefaults: () => ({}), // Override this method to provide default data for new instances. If using Model classes, specify this as a static class property.
45
+
setupInstance:instance=> instance, // Override this method to setup data types or related data on an instance. If using Model classes, specify this as a static class property.
71
46
autoRemove:true, // Automatically remove records missing from responses (only use with feathers-rest)
72
47
enableEvents:false, // Turn off socket event listeners. It's true by default
73
48
addOnUpsert:true, // Add new records pushed by 'updated/patched' socketio events into store, instead of discarding them. It's false by default
0 commit comments