Skip to content

Commit 7aa9a1f

Browse files
committed
Try to avoid re-querying when the query is same
1 parent 49e3df2 commit 7aa9a1f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/syncers/collection.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ export default class CollectionSyncer extends BaseSyncer {
6666

6767
// When new value is found
6868
const callback = function (newVal) {
69+
// Avoid re-querying if it's the same
70+
if (this.Vue.util.looseEqual(this.filters.query, newVal)) {
71+
this.filters.query = newVal
72+
return
73+
}
6974
this.filters.query = newVal
7075

71-
// Clear state (if now null it just makes sure)
76+
// Clear state (if query is now null it makes sure everything's reset)
7277
this.state = this._initialState()
7378
this._matcher = () => false
7479

test/collection.query.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ test('Switching queries', async t => {
118118

119119
t.falsy(syncer.loading)
120120
t.deepEqual(syncer.state, {2: {id: 2, otherItem: true}})
121+
122+
// Try to avoid re-querying whenver possible
123+
instance.$once('syncer-loaded', () => {
124+
t.fail('Queried again when test shouldn\'t')
125+
})
126+
instance.variables.query = {otherItem: true}
127+
// Wait for watchers to do their thing
128+
await new Promise(resolve => {
129+
instance.$nextTick(() => {
130+
resolve()
131+
})
132+
})
133+
t.false(syncer.loading)
121134
})
122135

123136
test('Creating items', async t => {

0 commit comments

Comments
 (0)