Skip to content

Commit d4e3dba

Browse files
committed
docs updates
1 parent ea0e805 commit d4e3dba

File tree

5 files changed

+30
-212
lines changed

5 files changed

+30
-212
lines changed

docs/2.0-major-release.md

Lines changed: 18 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
title: 2.0 Breaking Changes
3+
sidebarDepth: 3
4+
---
5+
16
# 2.0 Breaking Changes
27

38
The biggest change in Feathers-Vuex 2.0 is that it has been refactored with TypeScript! (It's mostly ES6, still)
@@ -104,188 +109,6 @@ const store = new Vuex.Store({
104109
})
105110
```
106111

107-
## Setting up a project
108-
109-
There are four steps to setting up the entirety of `feathers-vuex`:
110-
111-
1. Setup the FeathersJS Client.
112-
2. Setup each Service plugin
113-
3. Setup the Auth plugin
114-
4. Register all plugins with Vuex
115-
116-
### Setup the FeathersJS Client
117-
118-
It's now recommended that the FeathersJS and client live together in the same file. This cleans up imports when setting up services. So let's start with the `feathers-client.js` file. I usually put this in `src/feathers-client.js`, but you can put it in the store folder if you want.
119-
120-
```js
121-
// src/feathers-client.js
122-
import feathers from '@feathersjs/feathers'
123-
import socketio from '@feathersjs/socketio-client'
124-
import authClient from '@feathersjs/authentication-client'
125-
import io from 'socket.io-client'
126-
import feathersVuex from 'feathers-vuex' // or '@/libs/feathers-vuex' if you're copying feathers-vuex as mentioned earlier.
127-
128-
// Setup the Feathers client
129-
const host = process.env.VUE_APP_API_URL // or set a string here, directly
130-
const socket = io(host, { transports: ['websocket'] })
131-
const feathersClient = feathers()
132-
.configure(socketio(socket))
133-
.configure(authClient({ storage: window.localStorage }))
134-
135-
export default feathersClient
136-
137-
// Setup feathers-vuex
138-
const {
139-
makeServicePlugin,
140-
makeAuthPlugin,
141-
BaseModel,
142-
models,
143-
clients,
144-
FeathersVuex
145-
} = feathersVuex(feathersClient, {
146-
serverAlias: 'api', // or whatever that makes sense for your project
147-
idField: '_id' // `id` and `_id` are both supported, so this is only necessary if you're using something else.
148-
})
149-
150-
export {
151-
makeAuthPlugin,
152-
makeServicePlugin,
153-
BaseModel,
154-
models,
155-
clients,
156-
FeathersVuex
157-
}
158-
159-
```
160-
161-
Now that we have setup the client, we can use the configured exports in each of our services.
162-
163-
### Setup the Services Plugins
164-
165-
Now let's setup a Vuex plugin for each service. I use Webpack's `require.context` to automatically import all of the services instead of explicitly typing them all. So, I'll put the services in the `src/store/services` folder.
166-
167-
```js
168-
// Bring in the imports from the feathers-client.js file.
169-
import feathersClient, {
170-
makeServicePlugin,
171-
BaseModel
172-
} from '../../feathers-client'
173-
174-
// Extend the base class
175-
class User extends BaseModel {
176-
constructor(data, options) {
177-
super(data, options)
178-
}
179-
static modelName = 'User'
180-
static instanceDefaults() {
181-
return {
182-
firstName: '',
183-
lastName: '',
184-
email: '',
185-
password: ''
186-
}
187-
}
188-
get fullName() {
189-
return `${this.firstName} ${this.lastName}`
190-
}
191-
}
192-
const servicePath = 'users'
193-
const servicePlugin = makeServicePlugin({
194-
Model: User,
195-
service: feathersClient.service(servicePath),
196-
servicePath
197-
})
198-
199-
// Optionally add service-level hooks, here:
200-
feathersClient.service(servicePath).hooks({
201-
before: {
202-
all: [],
203-
find: [],
204-
get: [],
205-
create: [],
206-
update: [],
207-
patch: [],
208-
remove: []
209-
},
210-
after: {
211-
all: [],
212-
find: [],
213-
get: [],
214-
create: [],
215-
update: [],
216-
patch: [],
217-
remove: []
218-
},
219-
error: {
220-
all: [],
221-
find: [],
222-
get: [],
223-
create: [],
224-
update: [],
225-
patch: [],
226-
remove: []
227-
}
228-
})
229-
230-
export default servicePlugin
231-
232-
```
233-
234-
Once the service plugin is exported, we can register it with Vuex, but first let's setup the auth plugin.
235-
236-
### Setup the Auth Plugin
237-
238-
We'll use the `makeAuthPlugin` method to tell the auth plugin where to find our `/users` service:
239-
240-
```js
241-
// src/store/store.auth.js
242-
import feathersClient, { makeAuthPlugin } from '../feathers-client'
243-
244-
export default makeAuthPlugin({ userService: 'users' })
245-
246-
```
247-
248-
Once you've added the export, we're finally ready to setup the store.
249-
250-
### Register all plugins with Vuex
251-
252-
The final step is to add all of the plugins to the Vuex store.
253-
254-
```js
255-
// src/store/store.js
256-
import Vue from 'vue'
257-
import Vuex from 'vuex'
258-
import { FeathersVuex } from 'feathers-vuex'
259-
import auth from './store.auth'
260-
261-
Vue.use(Vuex)
262-
Vue.use(FeathersVuex)
263-
264-
// Require the entire folder of service plugins with Webpack
265-
const requireModule = require.context( './services', false, /.js$/ )
266-
const servicePlugins = requireModule
267-
.keys()
268-
.map(modulePath => requireModule(modulePath).default)
269-
270-
// Or you can import them manually for Rollup, etc.
271-
import users from './services/users'
272-
273-
export default new Vuex.Store({
274-
state: {},
275-
getters: {},
276-
mutations: {},
277-
actions: {},
278-
plugins: [
279-
...servicePlugins, // if you're using require.context, spread the plugins into the array.
280-
users, // if you're manually importing, just add the plugins into the array, like this
281-
auth
282-
]
283-
})
284-
285-
```
286-
287-
With the above four steps accomplished, the base of most any application using `feathers-vuex` is ready to build something awesome!
288-
289112
## Feathers-Vuex Vue plugin changes
290113

291114
The Vue plugin is registered in exactly the same way. The difference comes when you try to find the Model classes in the `$FeathersVuex` object. Instead of finding models directly on the `$FeathersVuex` object, they are namespaced by the `serverAlias` you provided. This allows cleaner support for multiple APIs. Supposing you had this code in a component, previously...
@@ -320,7 +143,7 @@ Because of the new ability to handle temporary records, a message is only logged
320143

321144
## Getters Work with Temporary Records
322145

323-
The `find` getter has been updated to include records from `state.tempsById`, by default. You can pass `temps: false` in the params to only search `state.keyedById`: `find({ query: {}, temps: false })`
146+
The `find` getter has been updated to include records from `state.tempsById` when you pass `temps: true` in the params.
324147

325148
The `get` getter has also been updated to work with temp ids. Pass the tempId the way you normally would pass the id: `get(tempId)`
326149

@@ -804,21 +627,21 @@ The above code will override the `responseHandler` auth action to work with the
804627
805628
Don't try to perform a query from within a getter like the example, below. It will result in an infinite loop:
806629
807-
```
630+
```js
808631
get user () {
809-
if (this.userId) {
810-
const user = Models.User.getFromStore(this.userId)
632+
if (this.userId) {
633+
const user = Models.User.getFromStore(this.userId)
811634

812-
// Fetch the User record if we don't already have it
813-
if (!user) {
814-
Models.User.get(this.userId)
815-
}
635+
// Fetch the User record if we don't already have it
636+
if (!user) {
637+
Models.User.get(this.userId)
638+
}
816639

817-
return user
818-
} else {
819-
return null
820-
}
821-
}
640+
return user
641+
} else {
642+
return null
643+
}
644+
}
822645
```
823646
824647
### Using custom query parameters
@@ -829,13 +652,3 @@ There are two places where the query operators have to be allowed.
829652
- Inside feathers-vuex (for the getters): Check out the `paramsForServer` and `whitelist` options for `feathers-vuex`. Both accept an array of strings representing prop names, but now I can't remember why I determined that I needed both. :)
830653
831654
For the Feathers Client, follow the FeathersJS docs for your database adapter.
832-
833-
### Access `$FeathersVuex` models in Nuxt `asyncData`
834-
835-
In `feathers-vuex@2.x`, you can get access to the `$FeathersVuex` object by importing the `models` object from the main export:
836-
837-
```
838-
import { models } from 'feathers-vuex'
839-
```
840-
841-
`models` and `$FeathersVuex` are the same object.

docs/composition-api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ And here's a look at each individual property:
9595
- You can use `params.qid` to dynamically specify the query identifier for any API request. The `qid` is used for tracking pagination data and enabling the fall-through cache across multiple queries.
9696
- Set `params.paginate` to `true` to turn off realtime updates for the results and defer pagination to the API server. Pagination works the same as for the [makeFindMixin pagination](./mixins.html#pagination-with-fall-through-cacheing).
9797
- Set `params.debounce` to an integer and the API requests will automatically be debounced by that many milliseconds. For example, setting `debounce: 1000` will assure that the API request will be made at most every 1 second.
98+
- Set `params.temps` to `true` to include temporary (local-only) items in the results. Temporary records are instances that have been created but not yet saved to the database.
9899
- `fetchParams` This is a separate set of params that, when provided, will become the params sent to the API server. The `params` will then only be used to query data from the local data store.
99100
- Explicitly returning `null` will prevent an API request from being made.
100101
- `queryWhen` must be a `computed` property which returns a `boolean`. It provides a logical separation for preventing API requests *outside* of the `params`.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ features:
1111
- title: Simplified Auth & Services
1212
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
14-
details: Common Redux patterns come included. Fall-through cache comes standard. Query the vuex store like a database.
14+
details: Vue Composition API 😎 Common Redux patterns included. Fall-through cache by default. Query the Vuex store like a database.
1515
footer: MIT Licensed | Copyright © 2017-present Marshall Thompson
1616
---

docs/nuxt.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ title: Nuxt
44

55
# Nuxt
66

7+
### Access `$FeathersVuex` models in Nuxt `asyncData`
8+
9+
In `[email protected]`, you can get access to the `$FeathersVuex` object by importing the `models` object from the main export:
10+
11+
```
12+
import { models } from 'feathers-vuex'
13+
```
14+
15+
The `models` and `$FeathersVuex` variables are the same object.
16+
717
## Preventing Memory Leaks
818

919
The default settings of Feathers-Vuex include having realtime events enabled by default. This will result in increased memory usage over time on the SSR server. It can be turned off when you configure `feathers-vuex`. The example below has been modified from the example of [Setting up the Feathers Client & Feathers-Vuex](./api-overview.md#feathers-client-feathers-vuex). Look specifically at the `enableEvents` option.

src/service-module/notes.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,6 @@ Feathers-Vuex 2.0 supports tracking temporary items and automatically assigns a
384384

385385
Because of the new ability to handle temporary records, a message is only logged when assigning a temporary id to a record. The `checkId` utility function has been removed, since this was its main purpose.
386386

387-
## Getters Work with Temporary Records
388-
389-
The `find` getter has been updated to include records from `state.tempsById`, by default. You can pass `temps: false` in the params to only search `state.keyedById`: `find({ query: {}, temps: false })`
390-
391-
The `get` getter has also been updated to work with temp ids. Pass the tempId the way you normally would pass the id: `get(tempId)`
392-
393387
## The "currentItem" workflow is no longer supported
394388

395389
The `setCurrent` mutation and `currentId` state encouraged use of a very limiting API. It's much more common for apps to require more than one current record. The `createCopy`, `resetCopy` (formerly called `rejectCopy`), `commitCopy`, and `clearCopy` mutations (since v1.x) provide a more flexible solution for implementing the same functionality. As a result of this, following have been removed from the modules:

0 commit comments

Comments
 (0)