@@ -124,6 +124,7 @@ import { searchDeepInObject, sortByKey, stringify, parse } from '@utils/util'
124
124
import debounce from ' lodash/debounce'
125
125
import groupBy from ' lodash/groupBy'
126
126
import { mapState , mapGetters , mapActions , mapMutations } from ' vuex'
127
+ import { mutationBuffer } from ' ./module'
127
128
128
129
export default {
129
130
components: {
@@ -253,6 +254,10 @@ export default {
253
254
}
254
255
},
255
256
257
+ created () {
258
+ this .loadStateDebounce = 300
259
+ },
260
+
256
261
mounted () {
257
262
bridge .on (' vuex:mutation' , this .onMutation )
258
263
if (this .isOnlyMutationPayload && this .$shared .vuexAutoload ) {
@@ -312,9 +317,25 @@ export default {
312
317
}
313
318
}, 250 ),
314
319
315
- loadState: debounce (function () {
316
- this .loadStateNow ()
317
- }, 300 ),
320
+ loadState () {
321
+ // Debouncing
322
+ clearTimeout (this .loadStateTimer )
323
+ this .loadStateTimer = setTimeout (() => {
324
+ this .loadStateNow ()
325
+ }, this .loadStateDebounce )
326
+
327
+ // Increase debounce delay
328
+ this .loadStateDebounce += 600
329
+ if (this .loadStateDebounce > 2000 ) {
330
+ this .loadStateDebounce = 2000
331
+ }
332
+
333
+ // Reset debounce delay after a period of inactivity
334
+ clearTimeout (this .loadStateDebounceResetTimer )
335
+ this .loadStateDebounceResetTimer = setTimeout (() => {
336
+ this .loadStateDebounce = 300
337
+ }, 3000 )
338
+ },
318
339
319
340
loadStateNow () {
320
341
const history = this .filteredHistory
@@ -323,10 +344,18 @@ export default {
323
344
324
345
onMutation () {
325
346
if (this .$shared .vuexAutoload ) {
326
- const unwatch = this .$watch (() => this .history .length , (value , oldValue ) => {
327
- unwatch ()
347
+ if (this .unwatchHistoryLength ) this .unwatchHistoryLength ()
348
+ if (mutationBuffer .length ) {
349
+ // Wait for history to receive mutations batch
350
+ this .unwatchHistoryLength = this .$watch (() => this .history .length , (value , oldValue ) => {
351
+ this .unwatchHistoryLength ()
352
+ if (! mutationBuffer .length ) {
353
+ this .loadState ()
354
+ }
355
+ })
356
+ } else {
328
357
this .loadState ()
329
- })
358
+ }
330
359
}
331
360
},
332
361
0 commit comments