Skip to content

Commit 4004d74

Browse files
authored
Merge pull request #1 from feathersjs-ecosystem/master
Update from source
2 parents 58119d9 + 6512242 commit 4004d74

File tree

8 files changed

+527
-385
lines changed

8 files changed

+527
-385
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: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "feathers-vuex",
33
"description": "FeathersJS, Vue, and Nuxt for the artisan developer",
4-
"version": "3.2.1",
4+
"version": "3.4.0",
55
"homepage": "https:feathers-vuex.feathersjs-ecosystem.com",
66
"main": "dist/",
77
"module": "dist/",
88
"types": "dist/",
99
"keywords": [
10+
"vue",
1011
"feathers",
1112
"feathers-plugin"
1213
],
@@ -18,7 +19,7 @@
1819
"author": {
1920
"name": "Marshall Thompson",
2021
"email": "[email protected]",
21-
"url": "https://feathersjs-ecosystem.github.io."
22+
"url": "https://github.com/marshallswain"
2223
},
2324
"funding": {
2425
"type": "Github sponsor",
@@ -44,7 +45,7 @@
4445
"watch": "shx rm -rf lib/ && babel --watch -d lib/ src/",
4546
"lint": "standard --fix",
4647
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --opts mocha.opts",
47-
"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'",
4849
"testee": "testee test/index.html --browsers firefox",
4950
"start": "npm run compile && node example/app",
5051
"docs:serve": "vuepress dev docs",
@@ -112,7 +113,7 @@
112113
"@vue/composition-api": "^0.3.4",
113114
"bson-objectid": "^1.3.0",
114115
"debug": "^4.1.1",
115-
"events": "^3.0.0",
116+
"events": "^3.1.0",
116117
"fast-copy": "^2.0.4",
117118
"fast-json-stable-stringify": "^2.1.0",
118119
"inflection": "^1.12.0",
@@ -138,12 +139,12 @@
138139
"@feathersjs/socketio-client": "^4.4.3",
139140
"@types/chai": "^4.2.7",
140141
"@types/mocha": "^5.2.7",
141-
"@typescript-eslint/eslint-plugin": "^2.12.0",
142-
"@typescript-eslint/parser": "^2.12.0",
142+
"@typescript-eslint/eslint-plugin": "^2.16.0",
143+
"@typescript-eslint/parser": "^2.16.0",
143144
"@vue/eslint-config-prettier": "^6.0.0",
144145
"@vue/eslint-config-typescript": "^5.0.1",
145146
"@vue/test-utils": "^1.0.0-beta.30",
146-
"axios": "^0.19.0",
147+
"axios": "^0.19.1",
147148
"babel-cli": "^6.26.0",
148149
"babel-core": "^6.26.3",
149150
"babel-eslint": "^10.0.3",
@@ -153,17 +154,17 @@
153154
"body-parser": "^1.19.0",
154155
"can-fixture-socket": "^2.0.3",
155156
"chai": "^4.2.0",
156-
"date-fns": "^2.8.1",
157+
"date-fns": "^2.9.0",
157158
"deep-object-diff": "^1.1.0",
158-
"eslint": "^6.7.1",
159-
"eslint-config-prettier": "^6.7.0",
159+
"eslint": "^6.8.0",
160+
"eslint-config-prettier": "^6.9.0",
160161
"eslint-plugin-prettier": "^3.1.2",
161-
"eslint-plugin-vue": "^6.0.1",
162+
"eslint-plugin-vue": "^6.1.2",
162163
"feathers-memory": "^4.1.0",
163164
"istanbul": "^1.1.0-alpha.1",
164-
"jsdom": "^15.2.1",
165+
"jsdom": "^16.0.0",
165166
"jsdom-global": "^3.0.2",
166-
"mocha": "^6.2.2",
167+
"mocha": "^7.0.0",
167168
"omit-deep-lodash": "^1.1.4",
168169
"prettier": "^1.19.1",
169170
"shx": "^0.3.2",
@@ -172,8 +173,8 @@
172173
"steal": "^2.2.4",
173174
"steal-mocha": "^2.0.1",
174175
"testee": "^0.9.1",
175-
"ts-node": "^8.5.2",
176-
"typescript": "^3.7.3",
176+
"ts-node": "^8.6.2",
177+
"typescript": "^3.7.4",
177178
"vue": "^2.6.11",
178179
"vue-server-renderer": "^2.6.11",
179180
"vue-template-compiler": "^2.6.11",

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)