In one of Vue my components I have code that looks like this
<li class="comment" v-for="comment in comments">
...
</li>
And my computed method
computed: {
comments() {
// All filter UI elements are associated with a filter method
// and when the user interacts with an element of the UI, filtersToApply gets populated with
// the associated method. Not too important right now,
// it just checks whether user interacted with the UI or not, so it could essentially be a boolean. But I plan to make use of the functionality at a later time.
const filtersToApply = this.filtersToApply();
// if user hasn't interacted with the filter UI, just return the comments
// else, apply filter(s) to comments
if (filtersToApply.length === 0) {
return this.$store.getters.comments;
} else {
return this.applyFilters(this.$store.getters.comments);
}
}
Ultimately, I want to do something like this:
// Apply the filters to the comments, one by one
applyFilters(comment) {
return this.filterByX()
.then(this.filterByY)
.then(this.filterByZ)
....
}
where the filter methods look like
filterByX(comments) {
return new Promise((resolve, reject) => {
.......
resolve(comments)
})
}
How could I make this work? And is it a good pattern?