Skip to content

Commit 5d4c8fa

Browse files
author
Jérémy
committed
Merge branch 'master' of https://github.com/feathersjs-ecosystem/feathers-vuex into mixin-local
2 parents b7498a2 + 14c8305 commit 5d4c8fa

File tree

4 files changed

+84
-27
lines changed

4 files changed

+84
-27
lines changed

docs/common-patterns.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ When this record is instantiated, the `user` attribute will first be turned into
384384

385385
There's another amazing benefit from these relationships. Because `feathers-vuex` listens to real-time events and keeps data up to date, when the user record changes, the `todo.user` automatically updates!
386386

387+
### Handling Sequelize Joins
388+
389+
See [this issue](https://github.com/feathersjs-ecosystem/feathers-vuex/issues/404) for a discussion on how to handle joins with Sequelize. It's important to specify `raw: false`, as shown in [this comment](https://github.com/feathersjs-ecosystem/feathers-vuex/issues/404#issuecomment-571774598).
390+
387391
### Workflow for Saving Model Associations
388392

389393
A great issue was opened on GitHub about the [Workflow for clone and save Model with associations](https://github.com/feathersjs-ecosystem/feathers-vuex/issues/278). That's a great issue to read to get familiar with the workflow.

docs/data-components.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,36 @@ The `FeathersVuexFind` component retrieves data from the API server, puts it in
8181

8282
## FeathersVuexGet
8383

84+
The `FeathersVuexGet` component allows fetching data from directly inside a template. It makes the slot scope available to the child components. Note that in `[email protected]` the component now includes support for `params` and `fetchParams` props. These are meant to replace the `query` and `fetchQuery` props. The `params` allow you, for example, to configure a project to pass custom params to the server. This would require use of custom hooks.
85+
86+
```html
87+
<template>
88+
<FeathersVuexGet service="users" :id="id" :params="params" :watch="[id, params]">
89+
<template slot-scope="{ item: user }">
90+
{{ user }}
91+
</template>
92+
</FeathersVuexGet>
93+
</template>
94+
95+
<script>
96+
export default {
97+
name: 'UserProfile',
98+
computed: {
99+
id() {
100+
return this.$route.params.id
101+
},
102+
params() {
103+
return {
104+
$populateParams: {
105+
name: 'withFollowers'
106+
}
107+
}
108+
}
109+
}
110+
}
111+
</script>
112+
```
113+
84114
## A note about the internal architecture
85115

86116
These components use Vuex getters (to query data from the local store) and actions (to query data from the API server). When a `query` or `id` is provided, the components pull data from the API server and put it into the store. That same `query` or `id` is then used to pull data from the local Vuex store. Keep this in mind, especially when attempting to use server-side pagination. To use server-side pagination, use the `query` prop for pulling data from the local vuex store, then use the `fetchQuery` prop to retrieve data from the API server.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "feathers-vuex",
33
"description": "FeathersJS, Vue, and Nuxt for the artisan developer",
4-
"version": "3.2.1",
4+
"version": "3.3.0",
55
"homepage": "https:feathers-vuex.feathersjs-ecosystem.com",
66
"main": "dist/",
77
"module": "dist/",
@@ -45,7 +45,7 @@
4545
"watch": "shx rm -rf lib/ && babel --watch -d lib/ src/",
4646
"lint": "standard --fix",
4747
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --opts mocha.opts",
48-
"test": "TS_NODE_PROJECT='tsconfig.test.json' mocha --require ts-node/register test/**/*.test.ts",
48+
"test": "TS_NODE_PROJECT='tsconfig.test.json' mocha --require ts-node/register 'test/**/*.test.ts'",
4949
"testee": "testee test/index.html --browsers firefox",
5050
"start": "npm run compile && node example/app",
5151
"docs:serve": "vuepress dev docs",

src/FeathersVuexGet.ts

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
12
export default {
23
props: {
34
/**
@@ -22,6 +23,29 @@ export default {
2223
type: Object,
2324
default: null
2425
},
26+
/**
27+
* If a separate query is desired to fetch data, use fetchQuery
28+
* The watchers are automatically updated, so you don't have to write 'fetchQuery.propName'
29+
*/
30+
fetchQuery: {
31+
type: Object
32+
},
33+
/**
34+
* Can be used in place of the `query` prop to provide more params. Only params.query is
35+
* passed to the getter.
36+
*/
37+
params: {
38+
type: Object,
39+
default: null
40+
},
41+
/**
42+
* Can be used in place of the `fetchQuery` prop to provide more params. Only params.query is
43+
* passed to the getter.
44+
*/
45+
fetchParams: {
46+
type: Object,
47+
default: null
48+
},
2549
/**
2650
* When `queryWhen` evaluates to false, no API request will be made.
2751
*/
@@ -34,13 +58,6 @@ export default {
3458
type: [Number, String],
3559
default: null
3660
},
37-
/**
38-
* If a separate query is desired to fetch data, use fetchQuery
39-
* The watchers are automatically updated, so you don't have to write 'fetchQuery.propName'
40-
*/
41-
fetchQuery: {
42-
type: Object
43-
},
4461
/**
4562
* Specify which properties in the query to watch and re-trigger API requests.
4663
*/
@@ -76,13 +93,17 @@ export default {
7693
computed: {
7794
item() {
7895
const getArgs = this.getArgs(this.query)
79-
8096
if (this.id) {
81-
return (
82-
this.$store.getters[`${this.service}/get`](
83-
getArgs.length === 1 ? this.id : getArgs
84-
) || null
85-
)
97+
if (getArgs.length === 1) {
98+
return this.$store.getters[`${this.service}/get`](this.id) || null
99+
} else {
100+
const args = [this.id]
101+
const query = getArgs[1].query
102+
if (query) {
103+
args.push(query)
104+
}
105+
return this.$store.getters[`${this.service}/get`](args) || null
106+
}
86107
} else {
87108
return null
88109
}
@@ -97,12 +118,14 @@ export default {
97118
methods: {
98119
getArgs(queryToUse) {
99120
const query = queryToUse || this.fetchQuery || this.query
100-
const getArgs = [this.id]
121+
const params = this.fetchParams || this.params
101122

102-
if (query && Object.keys(query).length > 0) {
123+
const getArgs = [this.id]
124+
if (params) {
125+
getArgs.push(params)
126+
} else if (query && Object.keys(query).length > 0) {
103127
getArgs.push({ query })
104128
}
105-
106129
return getArgs
107130
},
108131
getData() {
@@ -121,8 +144,9 @@ export default {
121144
`${this.service}/get`,
122145
getArgs.length === 1 ? this.id : getArgs
123146
)
124-
.then(() => {
147+
.then(response => {
125148
this.isGetPending = false
149+
return response
126150
})
127151
}
128152
}
@@ -131,17 +155,15 @@ export default {
131155
if (this.local || this.id === 'new') {
132156
return
133157
} else if (
134-
this.id !== null &&
135-
this.id !== undefined &&
136-
!this.query &&
137-
!this.fetchQuery
158+
this.fetchQuery ||
159+
this.query ||
160+
this.params ||
161+
(this.id !== null && this.id !== undefined)
138162
) {
139163
return this.getData()
140164
} else {
141165
// eslint-disable-next-line no-console
142-
console.log(
143-
`No query and no id provided, so no data will be fetched.`
144-
)
166+
console.log(`No query and no id provided, so no data will be fetched.`)
145167
}
146168
}
147169
},
@@ -153,7 +175,7 @@ export default {
153175
}
154176
if (!this.$store.state[this.service]) {
155177
throw new Error(
156-
`The '${ this.service }' plugin is not registered with feathers-vuex`
178+
`The '${this.service}' plugin is not registered with feathers-vuex`
157179
)
158180
}
159181

@@ -162,6 +184,7 @@ export default {
162184
if (
163185
this.fetchQuery ||
164186
this.query ||
187+
this.params ||
165188
(this.id !== null && this.id !== undefined)
166189
) {
167190
watch.forEach(prop => {

0 commit comments

Comments
 (0)