Loading problem…
You're building a virtual DOM system similar to React. The first step is to convert a real DOM tree into an object literal representation that can be serialized, manipulated, and later rendered back to DOM.
Given a real DOM element, convert it to an object literal representation similar to how React represents JSX elements. This process is called "virtualization" - creating a virtual representation of the DOM.
type and props structureclass → className, data-test → dataTest)// Given this DOM structure:
// <div>
// <h1>Hello</h1>
// <p class="text">World</p>
// </div>
const element = document.querySelector('div');
const virtual = virtualize(element);
// Returns:
// {
// type: 'div',
// props: {
// children: [
// {
// type: 'h1',
// props: { children: 'Hello' }
// },
// {
// type: 'p',
// props: {
// className: 'text',
// children: 'World'
// }
// }
// ]
// }
// }This problem models real virtual DOM systems: