Skip to content

Commit 7bd563c

Browse files
committed
data.Store: event firing cleanup #6552
1 parent 6889f34 commit 7bd563c

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/data/Store.mjs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class Store extends Base {
400400
onCollectionMutate(opts) {
401401
let me = this;
402402

403-
if (me.configsApplied && !me.isLoading) {
403+
if (me.isConstructed && !me.isLoading) {
404404
me.fire('load', me.items)
405405
}
406406
}
@@ -411,9 +411,8 @@ class Store extends Base {
411411
onCollectionSort() {
412412
let me = this;
413413

414-
if (me.configsApplied) {
415-
// console.log('onCollectionSort', me.collection.items);
416-
// me.fire('load', me.items);
414+
if (me.isConstructed) {
415+
me.fire('load', me.items)
417416
}
418417
}
419418

@@ -429,11 +428,15 @@ class Store extends Base {
429428
me.afterSetData(me.data);
430429
}
431430

432-
if (me.autoLoad) {
433-
me.timeout(100).then(() => { // todo
431+
// Being constructed does not mean that related afterSetStore() methods got executed
432+
// => break the sync flow to ensure potential listeners got applied
433+
Promise.resolve().then(() => {
434+
if (me.getCount() > 0) {
435+
me.fire('load', me.items)
436+
} else if (me.autoLoad) {
434437
me.load()
435-
})
436-
}
438+
}
439+
})
437440
}
438441

439442
/**

0 commit comments

Comments
 (0)