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,189 +109,7 @@ 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
-
## FeathersVuex Vue plugin changes
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...
292
115
@@ -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:
Version 3.0 of Feathers-Vuex is the Vue Composition API release! There were quite a few disappointed (and misinformed:) developers in 2019 when the Vue.js team announced what is now called the Vue Composition API. From my perspective:
11
+
12
+
- It is the most powerful feature added to Vue since its first release.
13
+
- It improves the ability to create dynamic functionality in components.
14
+
- It greatly enhances organization of code in components.
15
+
- It encourages code re-use. Check out the [vue-use-web](https://logaretm.github.io/vue-use-web/) collection for some great examples.
16
+
17
+
And now it has become the best way to perform queries with Feathers-Vuex. To find out how to take advantage of the new functionality in your apps, read the [Feather-Vuex Composition API docs](./composition-api.md).
18
+
19
+
## A Single Breaking Change
20
+
21
+
Since Feathers-Vuex follows semantic versioning, a single, small breaking change is the reason for the major version bump. Feathers-Vuex 3.0 has only one breaking change:
22
+
23
+
The `makeFindMixin` (and the new `useFind` utility) now have server-side pagination support turned off, by default. Real-time arrays of results are now the default setting. This really improves the development experience, especially for new users.
24
+
25
+
To migrate your app to version 3.0, you need to update any `params` where you are using server-side pagination. It will work as it has been in version 2.0 once you explicitly set `paginate: true` in the params, like this:
That's the only breaking change in this release. This behavior exactly matches the new `useFind` utility.
45
+
46
+
## One Deprecation
47
+
48
+
The `keepCopiesInStore` option is now deprecated. This was a part of the "clone and commit" API which basically disabled the reason for creating the "clone and commit" API in the first place.
49
+
50
+
If you're not familiar with the Feathers-Vuex "clone and commit" API, you can learn more about the [built-in data modeling](./model-classes.md) API and the section about [Working with Forms](./feathers-vuex-form-wrapper.md#the-clone-and-commit-pattern).
51
+
52
+
The `keepCopiesInStore` feature is set to be removed in Feathers-Vuex 4.0.
-[VuePress Dark Mode Support](https://tolking.github.io/vuepress-theme-default-prefers-color-scheme/) for the Docs
43
44
44
-
`* Improved in v2.0.0`<br />
45
-
`** New in v2.0.0`
45
+
`** Improved in v3.0.0`
46
46
47
47
## Installation
48
48
@@ -112,6 +112,8 @@ build: {
112
112
}
113
113
```
114
114
115
+
Be sure to read the section of the docs dedicated to [Working With Nuxt](./nuxt.md).
116
+
115
117
## Vue DevTools
116
118
117
119
Since Feathers-Vuex extensively uses Vuex under the hood, you'll want to make sure your VueJS developer tools are up to date AND setup properly. Specifically, the "New Vuex Backend" needs to be enabled. To setup the devtools
@@ -185,7 +187,7 @@ The following example creates a User class and registers it with the new `makeSe
0 commit comments