You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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({
104
109
})
105
110
```
106
111
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.
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
-
classUserextendsBaseModel {
176
-
constructor(data, options) {
177
-
super(data, options)
178
-
}
179
-
static modelName ='User'
180
-
staticinstanceDefaults() {
181
-
return {
182
-
firstName:'',
183
-
lastName:'',
184
-
email:'',
185
-
password:''
186
-
}
187
-
}
188
-
getfullName() {
189
-
return`${this.firstName}${this.lastName}`
190
-
}
191
-
}
192
-
constservicePath='users'
193
-
constservicePlugin=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
-
exportdefaultservicePlugin
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:
// Or you can import them manually for Rollup, etc.
271
-
importusersfrom'./services/users'
272
-
273
-
exportdefaultnewVuex.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
-
289
112
## Feathers-Vuex Vue plugin changes
290
113
291
114
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
320
143
321
144
## Getters Work with Temporary Records
322
145
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.
324
147
325
148
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)`
326
149
@@ -804,21 +627,21 @@ The above code will override the `responseHandler` auth action to work with the
804
627
805
628
Don't try to perform a query from within a getter like the example, below. It will result in an infinite loop:
806
629
807
-
```
630
+
```js
808
631
getuser () {
809
-
if (this.userId) {
810
-
constuser=Models.User.getFromStore(this.userId)
632
+
if (this.userId) {
633
+
constuser=Models.User.getFromStore(this.userId)
811
634
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
+
}
816
639
817
-
return user
818
-
} else {
819
-
returnnull
820
-
}
821
-
}
640
+
return user
641
+
} else {
642
+
returnnull
643
+
}
644
+
}
822
645
```
823
646
824
647
### Using custom query parameters
@@ -829,13 +652,3 @@ There are two places where the query operators have to be allowed.
829
652
- 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. :)
830
653
831
654
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:
Copy file name to clipboardExpand all lines: docs/composition-api.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,7 @@ And here's a look at each individual property:
95
95
- 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.
96
96
- 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).
97
97
- 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.
98
99
-`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.
99
100
- Explicitly returning `null` will prevent an API request from being made.
100
101
-`queryWhen` must be a `computed` property which returns a `boolean`. It provides a logical separation for preventing API requests *outside* of the `params`.
Copy file name to clipboardExpand all lines: docs/nuxt.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,16 @@ title: Nuxt
4
4
5
5
# Nuxt
6
6
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
+
7
17
## Preventing Memory Leaks
8
18
9
19
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.
Copy file name to clipboardExpand all lines: src/service-module/notes.md
-6Lines changed: 0 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -384,12 +384,6 @@ Feathers-Vuex 2.0 supports tracking temporary items and automatically assigns a
384
384
385
385
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.
386
386
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
-
393
387
## The "currentItem" workflow is no longer supported
394
388
395
389
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