LearnNewsExamplesServices
Frontmatter
id6065
titlemanager.Component: add a 2nd map for wrapped components
stateClosed
labels
enhancement
assigneestobiu
createdAtNov 6, 2024, 11:09 AM
updatedAtNov 6, 2024, 1:11 PM
githubUrlhttps://github.com/neomjs/neo/issues/6065
authortobiu
commentsCount0
parentIssue6045
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtNov 6, 2024, 1:11 PM

manager.Component: add a 2nd map for wrapped components

Closed v8.1.0 enhancement
tobiu
tobiu commented on Nov 6, 2024, 11:09 AM
    addVnodeComponentReferences(vnode, ownerId) {
        vnode = {...vnode}; // shallow copy

        let me         = this,
            childNodes = vnode?.childNodes ? [...vnode.childNodes] : [],
            component;

        vnode.childNodes = childNodes;

        childNodes.forEach((childNode, index) => {
            if (!childNode.componentId && childNode.id !== ownerId) {
                // searching for wrapped components as a fallback
                component = me.get(childNode.id) || me.findFirst('vdom.id', childNode.id)
            }

            childNodes[index] = component ?
                {componentId: component.id, id: component.vdom.id} :
                this.addVnodeComponentReferences(childNode, ownerId)
        });

        return vnode
    }

to keep the vdom & vnode trees in sync, we need to add component references into the vnode tree as well.

e.g. rendering the viewport => we get the full vnode (DOM) tree of the entire app. then we need to walk over every node to see if it is a cmp.

for most cmps this is an easy map check inside manager.Component. however, there are wrapped cmps, which can have 1-x parent nodes.

querying manager.Component to identify them is not reasonable (slow).

my first idea was to create manager.WrappedComponent, but i doubt that devs would need it for querying / searching.

so we can just add a second map into manager.Component. key => wrapper node id, value => component reference.

should be sufficient and lightweight.

tobiu added the enhancement label on Nov 6, 2024, 11:09 AM
tobiu assigned to @tobiu on Nov 6, 2024, 11:09 AM
tobiu referenced in commit 00d6a09 - "manager.Component: add a 2nd map for wrapped components #6065" on Nov 6, 2024, 12:12 PM
tobiu closed this issue on Nov 6, 2024, 1:11 PM
tobiu referenced in commit 4731043 - "manager.Component: add a 2nd map for wrapped components #6065" on Nov 8, 2024, 2:09 PM