I have a technical programming assignment coming up as part of the interview process for a company. I know it's going to be in Vanilla Javascript but I still want to organize my code properly as if I were using a modern MVC framework.
I'd like to implement a rough way of handling Components where I have a template string corresponding to html for a parent component. Nothing fancy like having the template be custom rendered, simply a chunk of html that will be set to a component's innerHTML
.
Essentially each Component will have an init()
function that looks roughly as follows:
init(props = {}) {
this.rootElement = document.querySelector('#app');
// Render component with template
this.rootElement.innerHTML = this.template;
// Init children
}
I want to be able to initialize the children but only after I know for sure that the this.rootElement.innerHTML = this.template
call as successfully rendered the div's that will be queried with querySelector
in the children's init
function.