Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#429): update module prop watches #536

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-roses-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-site": minor
---

Added watch for 'theme' prop
5 changes: 5 additions & 0 deletions .changeset/three-emus-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-entity": minor
---

Added watch for 'settings' prop
5 changes: 5 additions & 0 deletions .changeset/tidy-melons-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-views": minor
---

Added watch for 'arguments' prop
4 changes: 4 additions & 0 deletions packages/entity/src/components/DruxtEntity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export default {
this.$fetch()
},

settings() {
this.$fetch()
},

schemaType() {
this.$fetch()
},
Expand Down
6 changes: 6 additions & 0 deletions packages/site/src/components/DruxtSite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export default {
regions: ({ model, value }) => model || value || [],
},

watch: {
theme() {
this.$fetch()
}
},

methods: {
...mapActions({ getCollection: 'druxt/getCollection' }),
},
Expand Down
34 changes: 17 additions & 17 deletions packages/views/src/components/DruxtView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export default {
},

watch: {
async '$route.query'(to) {
'$route.query'(to) {
if (!Object.entries(to || {}).length) {
this.model = {
filter: {},
Expand All @@ -290,42 +290,42 @@ export default {
}
},

async displayId() {
await this.$fetch()
arguments() {
this.$fetch()
},

displayId() {
this.$fetch()
},

'model.filter': {
deep: true,
async handler(to, from) {
handler(to, from) {
if (!Object.entries(to || {}).length && !Object.entries(from || {}).length) {
return
}
await this.$fetch()
this.$fetch()
},
},

async 'model.page'(to, from) {
'model.page'(to, from) {
if (to !== from) {
await this.$fetch()
this.$fetch()
}
},

async 'model.sort'(to, from) {
'model.sort'(to, from) {
if (to !== from) {
await this.$fetch()
this.$fetch()
}
},

async query() {
await this.$fetch()
},

async uuid() {
await this.$fetch()
uuid() {
this.$fetch()
},

async viewId() {
await this.$fetch()
viewId() {
this.$fetch()
},
},

Expand Down
14 changes: 6 additions & 8 deletions packages/views/test/components/DruxtView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,19 @@ describe('DruxtView', () => {
expect(wrapper.vm.getQuery(wrapper.vm.component.settings)).toStrictEqual({})

// Watches.
expect(mocks.$fetch).toHaveBeenCalledTimes(0)
expect(mocks.$fetch).toHaveBeenCalledTimes(2)
await DruxtView.watch.displayId.call(mocks)
expect(mocks.$fetch).toHaveBeenCalledTimes(1)
expect(mocks.$fetch).toHaveBeenCalledTimes(3)
wrapper.vm.model.page = 1
await localVue.nextTick()
expect(mocks.$fetch).toHaveBeenCalledTimes(2)
expect(mocks.$fetch).toHaveBeenCalledTimes(4)
wrapper.vm.model.sort = 'nid'
await localVue.nextTick()
expect(mocks.$fetch).toHaveBeenCalledTimes(3)
await DruxtView.watch.query.call(mocks)
expect(mocks.$fetch).toHaveBeenCalledTimes(4)
await DruxtView.watch.uuid.call(mocks)
expect(mocks.$fetch).toHaveBeenCalledTimes(5)
await DruxtView.watch.viewId.call(mocks)
await DruxtView.watch.uuid.call(mocks)
expect(mocks.$fetch).toHaveBeenCalledTimes(6)
await DruxtView.watch.viewId.call(mocks)
expect(mocks.$fetch).toHaveBeenCalledTimes(7)
})

test('fetch by uuid', async () => {
Expand Down