Skip to content

Commit d61a7e8

Browse files
committed
fixed children mounting event emission
1 parent 9d2adc1 commit d61a7e8

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modular-openscriptjs",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "OpenScriptJs Framework - A lightweight, reactive JavaScript framework for building modern web applications",
55
"type": "module",
66
"main": "./dist/modular-openscriptjs.umd.js",

src/component/Component.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default class Component {
4141
rendered: "rendered", // component ui is computed
4242
rerendered: "rerendered", // component was ui was recomputed.
4343
mounted: "mounted", // the component is now on the dom
44-
unmounted: "unmounted", // removed from the repository
44+
unmounted: "unmounted", // removed from the repository,
45+
childrenMounted: "childrenMounted", // used when rerendering completes
4546
};
4647

4748
/**
@@ -101,6 +102,12 @@ export default class Component {
101102
if (component) component.handleMounted();
102103
});
103104

105+
this.on(this.EVENTS.childrenMounted, (componentId) => {
106+
let repo = container.resolve("repository");
107+
let component = repo.findComponent(componentId);
108+
if (component) component.handleChildrenMounted();
109+
});
110+
104111
/**
105112
* Compare two Nodes
106113
*/
@@ -435,9 +442,10 @@ export default class Component {
435442
} else {
436443
reconciler.reconcile(markup, e.childNodes[0]);
437444
}
438-
}
439445

440-
this.emit(this.EVENTS.rerendered, this.id);
446+
this.emit(this.EVENTS.childrenMounted, this.id);
447+
this.emit(this.EVENTS.rerendered, this.id);
448+
}
441449
});
442450

443451
queueMicrotask(cleanupDisconnectedComponents);
@@ -593,4 +601,26 @@ export default class Component {
593601
if (component) component.emit(this.EVENTS.mounted, component.id);
594602
});
595603
}
604+
605+
handleChildrenMounted() {
606+
if (!this.mounted) return;
607+
608+
let markups = this.markup();
609+
610+
let root = markups[0];
611+
612+
if (!root || !root.isConnected) return;
613+
614+
let children = getOjsChildren(root);
615+
616+
children.forEach((child) => {
617+
let component = container
618+
.resolve("repository")
619+
.findComponent(child.getAttribute("ojs-uid"));
620+
621+
if (component && !component.mounted) {
622+
component.emit(this.EVENTS.mounted, component.id);
623+
}
624+
});
625+
}
596626
}

0 commit comments

Comments
 (0)