Skip to content

Commit 5bd4e6c

Browse files
Merge pull request #201 from feathers-plus/new-docs
Add docs
2 parents 8e0dc55 + 2e2f689 commit 5bd4e6c

15 files changed

+34085
-8110
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
## Demo & Documentation
3131
[Demo](https://codesandbox.io/s/xk52mqm7o)
3232

33-
See [https://feathers-plus.github.io/v1/feathers-vuex/index.html](https://feathers-plus.github.io/v1/feathers-vuex/index.html) for full documentation.
33+
See [https://feathers-plus.github.io./index.html](https://feathers-plus.github.io./index.html) for full documentation.
3434

3535
## Installation
3636

docs/.vuepress/config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
title: 'FeathersVuex',
3+
description: 'Integration of FeathersJS, Vue, and Nuxt for the artisan developer',
4+
themeConfig: {
5+
repo: 'feathers-plus/feathers-vuex',
6+
docsDir: 'docs',
7+
editLinks: true,
8+
sidebar: [
9+
'/api-overview.md',
10+
'/vue-plugin.md',
11+
'/service-module.md',
12+
'/auth-module.md',
13+
'/model-classes.md',
14+
'/common-patterns.md',
15+
'/mixins.md',
16+
'/components.md',
17+
'/nuxt.md'
18+
],
19+
serviceWorker: {
20+
updatePopup: true
21+
}
22+
}
23+
}

docs/api-overview.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
title: API Overview
3+
---
4+
5+
<!--- Usage ------------------------------------------------------------------------------------ -->
6+
[![Build Status](https://travis-ci.org/feathers-plus/feathers-vuex.png?branch=master)](https://travis-ci.org/feathers-plus/feathers-vuex)
7+
[![Dependency Status](https://img.shields.io/david/feathers-plus/feathers-vuex.svg?style=flat-square)](https://david-dm.org/feathers-plus/feathers-vuex)
8+
[![Download Status](https://img.shields.io/npm/dm/feathers-vuex.svg?style=flat-square)](https://www.npmjs.com/package/feathers-vuex)
9+
10+
![feathers-vuex service logo](https://github.com/feathers-plus/feathers-vuex/raw/master/service-logo.png)
11+
12+
> Integrate the Feathers Client into Vuex
13+
14+
`feathers-vuex` is a first class integration of the Feathers Client and Vuex. It implements many Redux best practices under the hood, eliminates *a lot* of boilerplate code, and still allows you to easily customize the Vuex store.
15+
16+
## Features
17+
18+
- Fully powered by Vuex & Feathers
19+
- Realtime By Default
20+
- Actions With Reactive Data *
21+
- Local Queries
22+
- Fall-Through Caching *
23+
- Feathers Query Syntax
24+
- `$FeathersVuex` [Vue Plugin](./vue-plugin.md) *
25+
- Live Queries
26+
- [Per-Service Data Modeling](./common-patterns.md#Basic-Data-Modeling-with-instanceDefaults) *
27+
- Clone & Commit *
28+
- Simplified Auth
29+
- Vuex Strict Mode *
30+
- Per-Record Defaults *
31+
- Data Level Computes *
32+
- Relation Support *
33+
34+
`* New in v1.2.0`
35+
36+
## Installation
37+
38+
```console
39+
npm install feathers-vuex --save
40+
```
41+
42+
## Use
43+
To setup `feathers-vuex`, we first need to setup a Feathers Client. Here's an example using the latest `@feathersjs` npm packages.
44+
45+
**feathers-client.js:**
46+
```js
47+
import feathers from '@feathersjs/feathers'
48+
import socketio from '@feathersjs/socketio-client'
49+
import auth from '@feathersjs/authentication-client'
50+
import io from 'socket.io-client'
51+
52+
const socket = io('http://localhost:3030', {transports: ['websocket']})
53+
54+
const feathersClient = feathers()
55+
.configure(socketio(socket))
56+
.configure(auth({ storage: window.localStorage }))
57+
58+
export default feathersClient
59+
```
60+
61+
And here's how you would integrate the Feathers Client into the Vuex store:
62+
63+
**store/index.js:**
64+
```js
65+
import Vue from 'vue'
66+
import Vuex from 'vuex'
67+
import feathersVuex from 'feathers-vuex'
68+
import feathersClient from '../feathers-client'
69+
70+
const { service, auth, FeathersVuex } = feathersVuex(feathersClient, { idField: '_id' })
71+
72+
Vue.use(Vuex)
73+
Vue.use(FeathersVuex)
74+
75+
export default new Vuex.Store({
76+
plugins: [
77+
service('todos'),
78+
79+
// Specify custom options per service
80+
service('/v1/tasks', {
81+
idField: '_id', // The field in each record that will contain the id
82+
nameStyle: 'path', // Use the full service path as the Vuex module name, instead of just the last section
83+
namespace: 'custom-namespace', // Customize the Vuex module name. Overrides nameStyle.
84+
debug: true, // Enable some logging for debugging
85+
autoRemove: true, // Automatically remove records missing from responses (only use with feathers-rest)
86+
enableEvents: false, // Turn off socket event listeners. It's true by default
87+
addOnUpsert: true, // Add new records pushed by 'updated/patched' socketio events into store, instead of discarding them. It's false by default
88+
replaceItems: true, // If true, updates & patches replace the record in the store. Default is false, which merges in changes
89+
skipRequestIfExists: true, // For get action, if the record already exists in store, skip the remote request. It's false by default
90+
modelName: 'OldTask' // Default modelName would have been 'Task'
91+
})
92+
93+
// Add custom state, getters, mutations, or actions, if needed. See example in another section, below.
94+
service('things', {
95+
state: {},
96+
getters: {},
97+
mutations: {},
98+
actions: {}
99+
})
100+
101+
// Setup a service with defaults for Model instances
102+
service('manufacturers', {
103+
instanceDefaults: {
104+
name: ''
105+
}
106+
})
107+
// Setup a service with light-weight relational data
108+
service('models', {
109+
instanceDefaults: {
110+
name: '',
111+
manufacturerId: '',
112+
manufacturer: 'Manufacturer' // Refers to data (populated on the server) that gets put in the `manufacturers` vuex store.
113+
}
114+
})
115+
116+
// Setup the auth plugin.
117+
auth({ userService: 'users' })
118+
]
119+
})
120+
```
121+
122+
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.
123+
124+
To see `feathers-vuex` in a working vue-cli application, check out [`feathers-chat-vuex`](https://github.com/feathers-plus/feathers-chat-vuex).
125+
126+
127+
## Note about feathers-reactive
128+
Previous versions of this plugin required both RxJS and `feathers-reactive` to receive realtime updates. `[email protected]` has socket messaging support built in and takes advantage of Vuex reactivity, so RxJS and `feathers-reactive` are no longer required or supported.
129+
130+
## Global Configuration
131+
132+
The following default options are available for configuration:
133+
134+
```js
135+
const defaultOptions = {
136+
idField: 'id', // The field in each record that will contain the id
137+
autoRemove: false, // automatically remove records missing from responses (only use with feathers-rest)
138+
nameStyle: 'short', // Determines the source of the module name. 'short' or 'path'
139+
enableEvents: true, // Set to false to explicitly disable socket event handlers.
140+
preferUpdate: false, // When true, calling modelInstance.save() will do an update instead of a patch.
141+
}
142+
```
143+
144+
Each service module can also be individually configured.
145+
146+
## The Vuex modules
147+
148+
There are two modules included:
149+
1. The [Service module](./service-module.md) adds a Vuex store for new services.
150+
2. The [Auth module](./auth-module.md) sets up the Vuex store for authentication / logout.
151+
152+
153+
## License
154+
155+
Copyright (c) Forever and Ever, or at least the current year.
156+
157+
Licensed under the [MIT license](LICENSE).

docs/auth-module.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Auth Module API
3+
---
4+
5+
The Auth module helps setup your app for login / logout. It includes the following state by default:
6+
```js
7+
{
8+
accessToken: undefined, // The JWT
9+
payload: undefined, // The JWT payload
10+
11+
// entityIdField is only in v1.7.0-pre.41 or later
12+
entityIdField: 'userId', // The property in the payload storing the user id
13+
14+
isAuthenticatePending: false,
15+
isLogoutPending: false,
16+
17+
errorOnAuthenticate: undefined,
18+
errorOnLogout: undefined
19+
}
20+
```
21+
22+
### Actions
23+
The following actions are included in the `auth` module:
24+
- `authenticate`: use instead of `feathersClient.authenticate()`
25+
- `logout`: use instead of `feathersClient.logout()`
26+
The Vuex auth store may not update if you use the feathers client version.
27+
28+
29+
### Configuration
30+
You can provide a `userService` in the auth plugin's options to automatically populate the user upon successful login.
31+
32+
```js
33+
import Vuex from 'vuex'
34+
import feathersClient from './feathers-client'
35+
import feathersVuex from 'feathers-vuex'
36+
37+
const { auth } = feathersVuex(feathersClient, { idField: '_id' })
38+
39+
const store = new Vuex.Store({
40+
plugins: [
41+
auth({ userService: 'users' }) // if your user service endpoint is named 'users'
42+
]
43+
})
44+
```

0 commit comments

Comments
 (0)