Skip to content

Commit 731f2f9

Browse files
committed
docs: rename module to plugin, where applicable
1 parent 8a9468a commit 731f2f9

File tree

9 files changed

+142
-84
lines changed

9 files changed

+142
-84
lines changed

docs/.vuepress/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = {
99
sidebar: [
1010
'/api-overview.md',
1111
'/vue-plugin.md',
12-
'/service-module.md',
13-
'/auth-module.md',
12+
'/service-plugin.md',
13+
'/auth-plugin.md',
1414
'/model-classes.md',
1515
'/common-patterns.md',
1616
'/mixins.md',

docs/api-overview.md

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ These docs are for version 2.x. For [email protected], please go to [https://fe
3838
- Renderless Form Component **
3939
- Temporary (Local-only) Record Support **
4040
- Server-Powered Pagination Support **
41+
- [VuePress Dark Mode Support](https://tolking.github.io/vuepress-theme-default-prefers-color-scheme/) for the Docs **
4142

4243
`* Improved in v2.0.0`<br />
4344
`** New in v2.0.0`
@@ -48,22 +49,37 @@ These docs are for version 2.x. For [email protected], please go to [https://fe
4849
npm install feathers-vuex --save
4950
```
5051

52+
```bash
53+
yarn add feathers-vuex
54+
```
55+
5156
## Use
5257

5358
Using Feathers-Vuex happens in these steps:
5459

55-
1. Setup the Feathers client and Feathers-Vuex.
56-
2. Define a Model class and service plugin for each service.
57-
3. Register the plugins with the Vuex store.
60+
1. [Setup the Feathers client and Feathers-Vuex](#setup-the-feathers-client-and-feathers-vuex)
61+
2. [Define a Model class and service plugin for each service](#setup-one-or-more-service-plugins)
62+
3. [Setup the auth plugin](#setup-the-auth-plugin), if required.
63+
4. Register the plugins with the Vuex store.
5864

5965
### Setup the Feathers Client and Feathers-Vuex
6066

6167
To setup `feathers-vuex`, we first need to setup the latest Feathers client. We can also setup feathers-vuex in the same file.
6268

69+
First, let's install dependencies.
70+
71+
```bash
72+
npm i @feathersjs/feathers @feathersjs/socketio-client @feathersjs/authentication-client feathers-hooks-common socket.io-client feathers-vuex --save
73+
```
74+
75+
```bash
76+
yarn add @feathersjs/feathers @feathersjs/socketio-client @feathersjs/authentication-client feathers-hooks-common socket.io-client feathers-vuex
77+
```
78+
6379
Note that this example includes an app-level hook that removes attributes for handling temporary (local-only) records.
6480

6581
```js
66-
// feathers-client.js
82+
// src/feathers-client.js
6783
import feathers from '@feathersjs/feathers'
6884
import socketio from '@feathersjs/socketio-client'
6985
import auth from '@feathersjs/authentication-client'
@@ -92,8 +108,8 @@ export default feathersClient
92108
const { makeServicePlugin, makeAuthPlugin, BaseModel, models } = feathersVuex(
93109
feathersClient,
94110
{
95-
serverAlias: 'api',
96-
idField: '_id',
111+
serverAlias: 'api', // optional for working with multiple APIs (this is the default value)
112+
idField: '_id', // Must match the id field in your database table/collection
97113
whitelist: ['$regex', '$options']
98114
}
99115
)
@@ -103,10 +119,10 @@ export { makeAuthPlugin, makeServicePlugin, BaseModel, models }
103119

104120
### Setup one or more service plugins
105121

106-
The following example creates a User class and registers it with the new `makeServicePlugin` utility function.
122+
The following example creates a User class and registers it with the new `makeServicePlugin` utility function. This same file is also a great place to add your service-level hooks, so they're shown, too.
107123

108124
```js
109-
// services/users.js
125+
// src/store/services/users.js
110126
import { makeServicePlugin, BaseModel } from '../feathers-client'
111127

112128
class User extends BaseModel {
@@ -129,11 +145,7 @@ const servicePlugin = makeServicePlugin({
129145
service: feathersClient.service(servicePath),
130146
servicePath
131147
})
132-
```
133-
134-
This same file is also a great place to add your service-level hooks, so append the following.
135148

136-
```js
137149
// Setup the client-side Feathers hooks.
138150
feathersClient.service(servicePath).hooks({
139151
before: {
@@ -166,67 +178,52 @@ feathersClient.service(servicePath).hooks({
166178
})
167179

168180
export default servicePlugin
181+
```
182+
183+
### Setup the Auth Plugin
184+
185+
If your application uses authentication, the Auth Plugin will probably come in handy. It's a couple of lines to setup:
186+
187+
```js
188+
// src/store/store.auth.js
189+
import { makeAuthPlugin } from '../feathers-client'
169190

191+
export default makeAuthPlugin({ userService: 'users' })
170192
```
171193

194+
[Read more about the Auth Plugin](/auth-plugin.html).
195+
196+
### Add the plugins to the Vuex store.
172197

173198
```js
174-
// store/index.js
199+
// src/store/store.js
175200
import Vue from 'vue'
176201
import Vuex from 'vuex'
177-
import feathersVuex from 'feathers-vuex'
178-
import feathersClient from '../feathers-client'
179-
180-
const { service, auth, FeathersVuex } = feathersVuex(feathersClient, { idField: '_id' })
202+
import { FeathersVuex } from '../feathers-client'
203+
import auth from './store.auth'
181204

182205
Vue.use(Vuex)
183206
Vue.use(FeathersVuex)
184207

208+
const requireModule = require.context(
209+
// The path where the service modules live
210+
'./services',
211+
// Whether to look in subfolders
212+
false,
213+
// Only include .js files (prevents duplicate imports`)
214+
/.js$/
215+
)
216+
const servicePlugins = requireModule
217+
.keys()
218+
.map(modulePath => requireModule(modulePath).default)
219+
185220
export default new Vuex.Store({
186-
plugins: [
187-
service('todos'),
188-
189-
// Specify custom options per service
190-
service('/v1/tasks', {
191-
idField: '_id', // The field in each record that will contain the id
192-
nameStyle: 'path', // Use the full service path as the Vuex module name, instead of just the last section
193-
namespace: 'custom-namespace', // Customize the Vuex module name. Overrides nameStyle.
194-
debug: true, // Enable some logging for debugging
195-
autoRemove: true, // Automatically remove records missing from responses (only use with feathers-rest)
196-
enableEvents: false, // Turn off socket event listeners. It's true by default
197-
addOnUpsert: true, // Add new records pushed by 'updated/patched' socketio events into store, instead of discarding them. It's false by default
198-
replaceItems: true, // If true, updates & patches replace the record in the store. Default is false, which merges in changes
199-
skipRequestIfExists: true, // For get action, if the record already exists in store, skip the remote request. It's false by default
200-
modelName: 'OldTask' // Default modelName would have been 'Task'
201-
})
202-
203-
// Add custom state, getters, mutations, or actions, if needed. See example in another section, below.
204-
service('things', {
205-
state: {},
206-
getters: {},
207-
mutations: {},
208-
actions: {}
209-
})
210-
211-
// Setup a service with defaults for Model instances
212-
service('manufacturers', {
213-
instanceDefaults: {
214-
name: ''
215-
}
216-
})
217-
// Setup a service with light-weight relational data
218-
service('models', {
219-
instanceDefaults: {
220-
name: '',
221-
manufacturerId: '',
222-
manufacturer: 'Manufacturer' // Refers to data (populated on the server) that gets put in the `manufacturers` vuex store.
223-
}
224-
})
225-
226-
// Setup the auth plugin.
227-
auth({ userService: 'users' })
228-
]
221+
state: {},
222+
mutations: {},
223+
actions: {},
224+
plugins: [...servicePlugins, auth]
229225
})
226+
230227
```
231228

232229
The new `feathers-vuex` API is more Vuex-like. All of the functionality remains the same, but it is no longer configured like a FeathersJS plugin. While the previous functionality was nice for prototyping, it didn't work well in SSR scenarios, like with Nuxt.
@@ -253,15 +250,15 @@ const defaultOptions = {
253250

254251
Each service module can also be individually configured.
255252

256-
## The Vuex modules
253+
## The Vuex Plugins
257254

258-
There are two modules included:
255+
There are two plugins included:
259256

260-
1. The [Service module](./service-module.md) adds a Vuex store for new services.
261-
2. The [Auth module](./auth-module.md) sets up the Vuex store for authentication / logout.
257+
1. The [Service Plugin](./service-plugin.md) adds a Vuex store for new services.
258+
2. The [Auth Plugin](./auth-plugin.md) sets up the Vuex store for authentication / logout.
262259

263260
## License
264261

265-
Copyright (c) Forever and Ever, or at least the current year.
262+
Copyright (c) Forever, or at least the current year.
266263

267264
Licensed under the [MIT license](LICENSE).

docs/auth-module.md renamed to docs/auth-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Auth Module API
2+
title: Auth Plugin
33
---
44

55
The Auth module helps setup your app for login / logout. It includes the following state by default:

docs/common-patterns.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ You can set `debug: true` in the options to enable some logging to assist with d
1212

1313
## Use the `<FeathersVuexFind>` and `<FeathersVuexGet>` components
1414

15-
Using the new `<FeathersVuexFind>` and `<FeathersVuexGet>` components provides concise access to the best features of `feathers-vuex`, including live queries, reactive lists, custom pagination tracking per component, and fall-through cacheing of local data in the Vuex store. Check out the [Renderless Data Components](./components.md) docs for more details.
15+
Using the new `<FeathersVuexFind>` and `<FeathersVuexGet>` components provides concise access to the best features of `feathers-vuex`, including live queries, reactive lists, custom pagination tracking per component, and fall-through cacheing of local data in the Vuex store. Check out the [Renderless Data Components](./components.html) docs for more details.
1616

1717
## Use the `makeFindMixin` and `makeGetMixin` utilities
1818

19-
The mixin utilities provide the same functionality as the components, but with more power and flexibility. Check out the [Mixin docs](./mixins.md) for more details.
19+
The mixin utilities provide the same functionality as the components, but with more power and flexibility. Check out the [Mixin docs](./mixins.html) for more details.
2020

2121
## Working with TypeScript
2222

@@ -28,7 +28,7 @@ The best solution is to simply refresh to clear memory. The alternative to refr
2828

2929
## Accessing the store from hooks
3030

31-
Because the service's Model [is available](./service-module.md#The-FeathersClient-Service) at `service.FeathersVuexModel`, you can access the store inside hooks. This is especially handy if you have some custom attributes in a paginated server response.
31+
Because the service's Model [is available](./service-plugin.html#The-FeathersClient-Service) at `service.FeathersVuexModel`, you can access the store inside hooks. This is especially handy if you have some custom attributes in a paginated server response.
3232

3333
As an example, this `speeding-tickets` service has a `summary` attribute that comes back in the response. We can
3434

@@ -73,7 +73,7 @@ Sometimes your server response may contain more attributes than just database re
7373

7474
Depending on what you need to do, you may be able to solve this by [accessing the store from hooks](#Accessing-the-store-from-hooks). But that solution won't handle a scenario where you need the response data to be already populated in the store.
7575

76-
If you need the response data to already be in the store, you can use the [`afterFind` action](./service-module.md#afterFind-response). Here's what this looks like:
76+
If you need the response data to already be in the store, you can use the [`afterFind` action](./service-plugin.html#afterFind-response). Here's what this looks like:
7777

7878
```js
7979
import feathersVuex from 'feathers-vuex'
@@ -289,7 +289,7 @@ In summary, you can plan on individual records in the action response data to be
289289

290290
## Basic Data Modeling with `instanceDefaults`
291291

292-
See the [instanceDefaults API](./model-classes.md#instanceDefaults)
292+
See the [instanceDefaults API](./model-classes.html#instanceDefaults)
293293

294294
## Model-Specific Computed Properties
295295

@@ -371,7 +371,7 @@ instanceDefaults: {
371371
}
372372
```
373373

374-
When this record is instantiated, the `user` attribute will first be turned into a User [model instance](./model-classes.md), stored properly in the `/users` store. The `todo.user` attribute will be a reference to that user. No more duplicate data! Here's an example of how to set this up. The following example specifies that Todo instances can have a `user` attribute that contains a `User` Model instance:
374+
When this record is instantiated, the `user` attribute will first be turned into a User [model instance](./model-classes.html), stored properly in the `/users` store. The `todo.user` attribute will be a reference to that user. No more duplicate data! Here's an example of how to set this up. The following example specifies that Todo instances can have a `user` attribute that contains a `User` Model instance:
375375

376376
```js
377377
import Vue from 'vue'

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ features:
99
- title: Realtime by Default
1010
details: It's fully powered by Vuex and FeathersJS, lightweight, & realtime out of the box.
1111
- title: Simplified Auth & Services
12-
details: Includes modules for making auth and service plugins powered by Vuex. All plugins can be easily customized to fit your app. Fully flexible.
12+
details: Includes service and auth plugins powered by Vuex. All plugins can be easily customized to fit your app. Fully flexible.
1313
- title: Best Practices, Baked In
1414
details: Common Redux patterns come included. Fall-through cache comes standard. Query the vuex store like a database.
1515
footer: MIT Licensed | Copyright © 2017-present Marshall Thompson

docs/model-classes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Models & Instances API
2+
title: Data Modeling
33
---
44

55
<!-- markdownlint-disable MD002 MD033 MD041 -->
@@ -17,7 +17,7 @@ The following attributes are available on each model:
1717

1818
### Model.find(params)
1919

20-
Model classes have a `find` method, which is a proxy to the [`find` action](./service-module.md#find-params). <Badge text="1.7.0+" />
20+
Model classes have a `find` method, which is a proxy to the [`find` action](./service-plugin.html#find-params). <Badge text="1.7.0+" />
2121

2222
```js
2323
// In your Vue component
@@ -29,7 +29,7 @@ created () {
2929

3030
### Model.findInStore(params)
3131

32-
Model classes have a `findInStore` method, which is a proxy to the [`find` getter](./service-module.md#Service-Getters). <Badge text="1.7.0+" />
32+
Model classes have a `findInStore` method, which is a proxy to the [`find` getter](./service-plugin.html#Service-Getters). <Badge text="1.7.0+" />
3333

3434
```js
3535
// In your Vue component
@@ -41,7 +41,7 @@ created () {
4141

4242
### Model.get(id, params)
4343

44-
Model classes have a `get` method, which is a proxy to the [`get` action](./service-module.md#get-id-or-get-id-params). <Badge text="1.7.0+" />Notice that the signature is more Feathers-like, and doesn't require using an array to passing both id and params.
44+
Model classes have a `get` method, which is a proxy to the [`get` action](./service-plugin.html#get-id-or-get-id-params). <Badge text="1.7.0+" />Notice that the signature is more Feathers-like, and doesn't require using an array to passing both id and params.
4545

4646
```js
4747
// In your Vue component
@@ -53,7 +53,7 @@ created () {
5353

5454
### Model.getFromStore(id, params)
5555

56-
Model classes have a `getFromStore` method, which is a proxy to the [`get` getter](./service-module.md#Service-Getters). <Badge text="1.7.0+" /> Notice that the signature is more Feathers-like, and doesn't require using an array to passing both id and params.
56+
Model classes have a `getFromStore` method, which is a proxy to the [`get` getter](./service-plugin.html#Service-Getters). <Badge text="1.7.0+" /> Notice that the signature is more Feathers-like, and doesn't require using an array to passing both id and params.
5757

5858
```js
5959
// In your Vue component

0 commit comments

Comments
 (0)