Skip to content

Commit 8b5f8e5

Browse files
committed
docs: service-plugin updates
1 parent 43b32d2 commit 8b5f8e5

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

docs/service-plugin.md

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,17 @@ title: Service Plugin
44

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

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

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

11-
```js
12-
// src/services/users.js
13-
import feathersVuex from 'feathers-vuex'
14-
import feathersClient from '../../feathers-client'
15-
16-
const { service } = feathersVuex(feathersClient, { idField: '_id' })
17-
18-
const servicePath = 'users'
19-
const servicePlugin = service(servicePath)
20-
21-
export default servicePlugin
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:
25-
26-
```js
27-
// src/store.js
28-
import Vue from 'vue'
29-
import Vuex from 'vuex'
30-
import feathersVuex from 'feathers-vuex'
31-
import feathersClient from '../feathers-client'
32-
import usersPlugin from './services/users'
33-
34-
const { auth, FeathersVuex } = feathersVuex(feathersClient, { idField: '_id' })
11+
## New in Feathers-Vuex 2.0
3512

36-
Vue.use(Vuex)
37-
Vue.use(FeathersVuex)
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
3814

39-
export default new Vuex.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.
4618

4719
Old example from the api-overview page:
4820

@@ -68,6 +40,9 @@ export default new Vuex.Store({
6840
nameStyle: 'path', // Use the full service path as the Vuex module name, instead of just the last section
6941
namespace: 'custom-namespace', // Customize the Vuex module name. Overrides nameStyle.
7042
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.
7146
autoRemove: true, // Automatically remove records missing from responses (only use with feathers-rest)
7247
enableEvents: false, // Turn off socket event listeners. It's true by default
7348
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

Comments
 (0)