Skip to content

Commit 2c3fa3c

Browse files
committed
docs: service plugin realtime events and config
closes #281
1 parent fa92403 commit 2c3fa3c

File tree

1 file changed

+26
-65
lines changed

1 file changed

+26
-65
lines changed

docs/service-plugin.md

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,43 @@ title: Service Plugin
44

55
<!-- markdownlint-disable MD002 MD033 MD041 -->
66

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.
88

99
See the [setup documentation](/api-overview.html#service-plugins) to learn the basics of setting up a Service Plugin.
1010

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
1812

19-
Old example from the api-overview page:
13+
The following options are supported on `makeServicePlugin`.
2014

2115
```js
22-
// store/index.js
23-
import Vue from 'vue'
24-
import Vuex from 'vuex'
25-
import feathersVuex from 'feathers-vuex'
26-
import feathersClient from '../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'
30+
}
31+
```
2732

28-
const { service, auth, FeathersVuex } = feathersVuex(feathersClient, { idField: '_id' })
33+
## Realtime by Default
2934

30-
Vue.use(Vuex)
31-
Vue.use(FeathersVuex)
35+
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.
3236

33-
export default new Vuex.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
6138

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
7640

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.
8244

8345
## The FeathersClient Service
8446

@@ -104,7 +66,6 @@ Each service comes loaded with the following default state:
10466
replaceItems: false, // When set to true, updates and patches will replace the record in the store instead of merging changes
10567
paginate: false, // Indicates if pagination is enabled on the Feathers service.
10668

107-
10869
paramsForServer: [], // Custom query operators that are ignored in the find getter, but will pass through to the server.
10970
whitelist: [], // Custom query operators that will be allowed in the find getter.
11071

0 commit comments

Comments
 (0)