Skip to content

Commit

Permalink
feat!: rewrite vuex logic to set the source of truth the URL queries
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the source of truth is now the URL
  • Loading branch information
AlejandroAkbal committed Feb 22, 2021
1 parent e11da2e commit fd0e3fe
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 120 deletions.
54 changes: 54 additions & 0 deletions components/pages/posts/navigation/url/UrlManagerMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { mapGetters, mapActions } from 'vuex'
import { isEqual } from 'lodash-es'

export default {
computed: {
...mapGetters('url', ['urlDomain', 'urlPage', 'urlTags']),
},

watch: {
async urlDomain(from, to) {
if (from === to) {
console.debug('Same domain, skipping...', [from, to])
return
}

console.debug('URL `domain` changed.', [from, to])

await this.fetchPosts()
},

async urlPage(from, to) {
if (from === to) {
console.debug('Same page, skipping...', [from, to])
return
}

console.debug('URL `page` changed.', [from, to])

await this.fetchPosts()
},

async urlTags(from, to) {
if (isEqual(from, to)) {
console.debug('Same tags, skipping...', [from, to])
return
}

console.debug('URL `tags` changed.', [from, to])

await this.fetchPosts()
},
},

async mounted() {
await this.setInitialUrlState()

await this.fetchPosts()
},

methods: {
...mapActions('url', ['setInitialUrlState']),
...mapActions('booru', ['fetchPosts']),
},
}
Loading

0 comments on commit fd0e3fe

Please sign in to comment.