Skip to content

Commit

Permalink
fix: formatting issues and destructing assignments from renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
ravijayaramappa committed Jun 3, 2022
1 parent 9e7c4bc commit f35826f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
76 changes: 50 additions & 26 deletions packages/@lwc/engine-core/src/framework/base-lightning-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ function doAttachShadow(vm: VM): ShadowRoot {
mode,
shadowMode,
def: { ctor },
renderer: { attachShadow },
} = vm;
const { attachShadow } = vm.renderer;

const shadowRoot = attachShadow(elm, {
[KEY__SYNTHETIC_MODE]: shadowMode === ShadowMode.Synthetic,
Expand Down Expand Up @@ -283,8 +283,10 @@ LightningElement.prototype = {

dispatchEvent(event: Event): boolean {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { dispatchEvent } = vm.renderer;
const {
elm,
renderer: { dispatchEvent },
} = vm;
return dispatchEvent(elm, event);
},

Expand All @@ -294,8 +296,10 @@ LightningElement.prototype = {
options?: boolean | AddEventListenerOptions
): void {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { addEventListener } = vm.renderer;
const {
elm,
renderer: { addEventListener },
} = vm;

if (process.env.NODE_ENV !== 'production') {
const vmBeingRendered = getVMBeingRendered();
Expand Down Expand Up @@ -323,38 +327,49 @@ LightningElement.prototype = {
options?: boolean | AddEventListenerOptions
): void {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { removeEventListener } = vm.renderer;
const {
elm,
renderer: { removeEventListener },
} = vm;

const wrappedListener = getWrappedComponentsListener(vm, listener);
removeEventListener(elm, type, wrappedListener, options);
},

hasAttribute(name: string): boolean {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { getAttribute } = vm.renderer;
const {
elm,
renderer: { getAttribute },
} = vm;
return !isNull(getAttribute(elm, name));
},

hasAttributeNS(namespace: string | null, name: string): boolean {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { getAttribute } = vm.renderer;
const {
elm,
renderer: { getAttribute },
} = vm;
return !isNull(getAttribute(elm, name, namespace));
},

removeAttribute(name: string): void {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { removeAttribute } = vm.renderer;
const {
elm,
renderer: { removeAttribute },
} = vm;
unlockAttribute(elm, name);
removeAttribute(elm, name);
lockAttribute(elm, name);
},

removeAttributeNS(namespace: string | null, name: string): void {
const { elm, renderer: { removeAttribute } } = getAssociatedVM(this);
const {
elm,
renderer: { removeAttribute },
} = getAssociatedVM(this);
unlockAttribute(elm, name);
removeAttribute(elm, name, namespace);
lockAttribute(elm, name);
Expand All @@ -376,8 +391,10 @@ LightningElement.prototype = {

setAttribute(name: string, value: string): void {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { setAttribute } = vm.renderer;
const {
elm,
renderer: { setAttribute },
} = vm;

if (process.env.NODE_ENV !== 'production') {
assert.isFalse(
Expand All @@ -393,8 +410,10 @@ LightningElement.prototype = {

setAttributeNS(namespace: string | null, name: string, value: string): void {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { setAttribute } = vm.renderer;
const {
elm,
renderer: { setAttribute },
} = vm;

if (process.env.NODE_ENV !== 'production') {
assert.isFalse(
Expand All @@ -410,8 +429,10 @@ LightningElement.prototype = {

getBoundingClientRect(): ClientRect {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { getBoundingClientRect } = vm.renderer;
const {
elm,
renderer: { getBoundingClientRect },
} = vm;

if (process.env.NODE_ENV !== 'production') {
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect()');
Expand All @@ -422,15 +443,19 @@ LightningElement.prototype = {

get isConnected(): boolean {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { isConnected } = vm.renderer;
const {
elm,
renderer: { isConnected },
} = vm;
return isConnected(elm);
},

get classList(): DOMTokenList {
const vm = getAssociatedVM(this);
const { elm } = vm;
const { getClassList } = vm.renderer;
const {
elm,
renderer: { getClassList },
} = vm;

if (process.env.NODE_ENV !== 'production') {
// TODO [#1290]: this still fails in dev but works in production, eventually, we should
Expand Down Expand Up @@ -543,8 +568,7 @@ for (const queryMethod of queryMethods) {
queryAndChildGetterDescriptors[queryMethod] = {
value(this: LightningElement, arg: string) {
const vm = getAssociatedVM(this);
const { elm } = vm;
const renderer = vm.renderer;
const { elm, renderer } = vm;

if (process.env.NODE_ENV !== 'production') {
warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
Expand Down
6 changes: 4 additions & 2 deletions packages/@lwc/engine-core/src/framework/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ function hydrateVM(vm: VM) {
const children = renderComponent(vm);
vm.children = children;

const parentNode = vm.renderRoot;
const { getFirstChild } = vm.renderer;
const {
renderRoot: parentNode,
renderer: { getFirstChild },
} = vm;
hydrateChildren(getFirstChild(parentNode), children, parentNode, vm);
runRenderedCallback(vm);
}
Expand Down

0 comments on commit f35826f

Please sign in to comment.