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
+26-65Lines changed: 26 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,81 +4,43 @@ title: Service Plugin
4
4
5
5
<!-- markdownlint-disable MD002 MD033 MD041 -->
6
6
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:
7
+
The `makeServicePlugin` method creates a vuex plugin which connects a Feathers service to the Vuex store. Once you create a plugin, you must register it in the Vuex store's `plugins` section.
8
8
9
9
See the [setup documentation](/api-overview.html#service-plugins) to learn the basics of setting up a Service Plugin.
10
10
11
-
## New in Feathers-Vuex 2.0
12
-
13
-
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
14
-
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.
11
+
## Configuration
18
12
19
-
Old example from the api-overview page:
13
+
The following options are supported on `makeServicePlugin`.
20
14
21
15
```js
22
-
// store/index.js
23
-
importVuefrom'vue'
24
-
importVuexfrom'vuex'
25
-
importfeathersVuexfrom'feathers-vuex'
26
-
importfeathersClientfrom'../feathers-client'
16
+
{
17
+
idField:'_id', // The field in each record that will contain the id
18
+
nameStyle:'path', // Use the full service path as the Vuex module name, instead of just the last section
19
+
namespace:'custom-namespace', // Customize the Vuex module name. Overrides nameStyle.
20
+
debug:true, // Enable some logging for debugging
21
+
servicePath:'', // Not all Feathers service plugins expose the service path, so it can be manually specified when missing.
22
+
instanceDefaults: () => ({}), // Override this method to provide default data for new instances. If using Model classes, specify this as a static class property.
23
+
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.
24
+
autoRemove:true, // Automatically remove records missing from responses (only use with feathers-rest)
25
+
enableEvents:false, // Turn off socket event listeners. It's true by default
26
+
addOnUpsert:true, // Add new records pushed by 'updated/patched' socketio events into store, instead of discarding them. It's false by default
27
+
replaceItems:true, // If true, updates & patches replace the record in the store. Default is false, which merges in changes
28
+
skipRequestIfExists:true, // For get action, if the record already exists in store, skip the remote request. It's false by default
29
+
modelName:'OldTask'// Default modelName would have been 'Task'
Service plugins automatically listen to all socket messages received by the Feathers Client. This can be disabled by setting `enableEvents: false` in the options, as shown above.
32
36
33
-
exportdefaultnewVuex.Store({
34
-
plugins: [
35
-
service('todos'),
36
-
37
-
// Specify custom options per service
38
-
service('/v1/tasks', {
39
-
idField:'_id', // The field in each record that will contain the id
40
-
nameStyle:'path', // Use the full service path as the Vuex module name, instead of just the last section
41
-
namespace:'custom-namespace', // Customize the Vuex module name. Overrides nameStyle.
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.
46
-
autoRemove:true, // Automatically remove records missing from responses (only use with feathers-rest)
47
-
enableEvents:false, // Turn off socket event listeners. It's true by default
48
-
addOnUpsert:true, // Add new records pushed by 'updated/patched' socketio events into store, instead of discarding them. It's false by default
49
-
replaceItems:true, // If true, updates & patches replace the record in the store. Default is false, which merges in changes
50
-
skipRequestIfExists:true, // For get action, if the record already exists in store, skip the remote request. It's false by default
51
-
modelName:'OldTask'// Default modelName would have been 'Task'
52
-
})
53
-
54
-
// Add custom state, getters, mutations, or actions, if needed. See example in another section, below.
55
-
service('things', {
56
-
state: {},
57
-
getters: {},
58
-
mutations: {},
59
-
actions: {}
60
-
})
37
+
## New in Feathers-Vuex 2.0
61
38
62
-
// Setup a service with defaults for Model instances
63
-
service('manufacturers', {
64
-
instanceDefaults: {
65
-
name:''
66
-
}
67
-
})
68
-
// Setup a service with light-weight relational data
69
-
service('models', {
70
-
instanceDefaults: {
71
-
name:'',
72
-
manufacturerId:'',
73
-
manufacturer:'Manufacturer'// Refers to data (populated on the server) that gets put in the `manufacturers` vuex store.
74
-
}
75
-
})
39
+
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
76
40
77
-
// Setup the auth plugin.
78
-
auth({ userService:'users' })
79
-
]
80
-
})
81
-
```
41
+
- The `service` method is now called `makeServicePlugin`
42
+
- The Feathers Client service is no longer created, internally, so a Feathers service object must be provided instead of just the path string.
43
+
- 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.
82
44
83
45
## The FeathersClient Service
84
46
@@ -104,7 +66,6 @@ Each service comes loaded with the following default state:
104
66
replaceItems:false, // When set to true, updates and patches will replace the record in the store instead of merging changes
105
67
paginate:false, // Indicates if pagination is enabled on the Feathers service.
106
68
107
-
108
69
paramsForServer: [], // Custom query operators that are ignored in the find getter, but will pass through to the server.
109
70
whitelist: [], // Custom query operators that will be allowed in the find getter.
0 commit comments