Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: move renderer to top-level module #2598

Merged
merged 8 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/@lwc/engine-core/src/3rdparty/snabbdom/snabbdom.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Code distributed by Snabbdom as part of the Snabbdom project at
https://github.com/snabbdom/snabbdom/ https://github.com/snabbdom/snabbdom/
*/ */


import { nextSibling } from '../../renderer';
import { VNode, VNodes, Key } from './types'; import { VNode, VNodes, Key } from './types';


function isUndef(s: any): s is undefined { function isUndef(s: any): s is undefined {
Expand Down Expand Up @@ -107,11 +108,7 @@ export function updateDynamicChildren(parentElm: Node, oldCh: VNodes, newCh: VNo
} else if (sameVnode(oldStartVnode, newEndVnode)) { } else if (sameVnode(oldStartVnode, newEndVnode)) {
// Vnode moved right // Vnode moved right
patchVnode(oldStartVnode, newEndVnode); patchVnode(oldStartVnode, newEndVnode);
newEndVnode.hook.move( newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling(oldEndVnode.elm!));
oldStartVnode,
parentElm,
oldEndVnode.owner.renderer.nextSibling(oldEndVnode.elm!)
);
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) { } else if (sameVnode(oldEndVnode, newStartVnode)) {
Expand Down
18 changes: 7 additions & 11 deletions packages/@lwc/engine-core/src/framework/api.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
StringReplace, StringReplace,
toString, toString,
} from '@lwc/shared'; } from '@lwc/shared';
import { createText, createComment, createElement, isSyntheticShadowDefined } from '../renderer';
import { logError, logWarn } from '../shared/logger'; import { logError, logWarn } from '../shared/logger';
import { invokeEventListener } from './invoker'; import { invokeEventListener } from './invoker';
import { getVMBeingRendered } from './template'; import { getVMBeingRendered } from './template';
Expand Down Expand Up @@ -82,9 +83,8 @@ const SymbolIterator: typeof Symbol.iterator = Symbol.iterator;
const TextHook: Hooks<VText> = { const TextHook: Hooks<VText> = {
create: (vnode) => { create: (vnode) => {
const { owner } = vnode; const { owner } = vnode;
const { renderer } = owner;


const elm = renderer.createText(vnode.text!); const elm = createText(vnode.text!);
linkNodeToShadow(elm, owner); linkNodeToShadow(elm, owner);
vnode.elm = elm; vnode.elm = elm;
}, },
Expand Down Expand Up @@ -117,9 +117,8 @@ const TextHook: Hooks<VText> = {
const CommentHook: Hooks<VComment> = { const CommentHook: Hooks<VComment> = {
create: (vnode) => { create: (vnode) => {
const { owner, text } = vnode; const { owner, text } = vnode;
const { renderer } = owner;


const elm = renderer.createComment(text); const elm = createComment(text);
linkNodeToShadow(elm, owner); linkNodeToShadow(elm, owner);
vnode.elm = elm; vnode.elm = elm;
}, },
Expand Down Expand Up @@ -161,10 +160,9 @@ const ElementHook: Hooks<VElement> = {
owner, owner,
data: { svg }, data: { svg },
} = vnode; } = vnode;
const { renderer } = owner;


const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined; const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
const elm = renderer.createElement(sel, namespace); const elm = createElement(sel, namespace);


linkNodeToShadow(elm, owner); linkNodeToShadow(elm, owner);
fallbackElmHook(elm, vnode); fallbackElmHook(elm, vnode);
Expand Down Expand Up @@ -225,8 +223,7 @@ const ElementHook: Hooks<VElement> = {
const CustomElementHook: Hooks<VCustomElement> = { const CustomElementHook: Hooks<VCustomElement> = {
create: (vnode) => { create: (vnode) => {
const { sel, owner } = vnode; const { sel, owner } = vnode;
const { renderer } = owner; const UpgradableConstructor = getUpgradableConstructor(sel);
const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
/** /**
* Note: if the upgradable constructor does not expect, or throw when we new it * Note: if the upgradable constructor does not expect, or throw when we new it
* with a callback as the first argument, we could implement a more advanced * with a callback as the first argument, we could implement a more advanced
Expand Down Expand Up @@ -307,7 +304,6 @@ const CustomElementHook: Hooks<VCustomElement> = {
mode, mode,
owner, owner,
tagName: sel, tagName: sel,
renderer: owner.renderer,
}); });


vnode.elm = elm as Element; vnode.elm = elm as Element;
Expand All @@ -334,10 +330,10 @@ const CustomElementHook: Hooks<VCustomElement> = {
}; };


function linkNodeToShadow(elm: Node, owner: VM) { function linkNodeToShadow(elm: Node, owner: VM) {
const { renderer, renderMode, shadowMode } = owner; const { renderMode, shadowMode } = owner;


// TODO [#1164]: this should eventually be done by the polyfill directly // TODO [#1164]: this should eventually be done by the polyfill directly
if (renderer.isSyntheticShadowDefined) { if (isSyntheticShadowDefined) {
if (shadowMode === ShadowMode.Synthetic || renderMode === RenderMode.Light) { if (shadowMode === ShadowMode.Synthetic || renderMode === RenderMode.Light) {
(elm as any)[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER]; (elm as any)[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {


import { getAssociatedVM } from './vm'; import { getAssociatedVM } from './vm';
import { reactiveMembrane } from './membrane'; import { reactiveMembrane } from './membrane';
import { HTMLElementConstructor } from './renderer'; import { HTMLElementConstructor } from './html-element';
import { HTMLElementOriginalDescriptors } from './html-properties'; import { HTMLElementOriginalDescriptors } from './html-properties';
import { isAttributeLocked } from './attributes'; import { isAttributeLocked } from './attributes';


Expand Down
Loading