Skip to content

Commit

Permalink
chore(jsdoc): add JSDoc to the updateElement function (#5696)
Browse files Browse the repository at this point in the history
This adds some JSDoc to this function and also removes an unused
parameter.
  • Loading branch information
alicewriteswrongs authored Apr 25, 2024
1 parent e318eec commit dfea716
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/runtime/vdom/update-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import type * as d from '../../declarations';
import { NODE_TYPE } from '../runtime-constants';
import { setAccessor } from './set-accessor';

export const updateElement = (
oldVnode: d.VNode | null,
newVnode: d.VNode,
isSvgMode: boolean,
memberName?: string,
): void => {
/**
* Handle updating attributes on the component element based on the current
* values present in the virtual DOM.
*
* If the component of interest uses shadow DOM these are added to the shadow
* root's host element.
*
* @param oldVnode an old virtual DOM node or null
* @param newVnode a new virtual DOM node
* @param isSvgMode whether or not we're in an SVG context
*/
export const updateElement = (oldVnode: d.VNode | null, newVnode: d.VNode, isSvgMode: boolean): void => {
// if the element passed in is a shadow root, which is a document fragment
// then we want to be adding attrs/props to the shadow root's "host" element
// if it's not a shadow root, then we add attrs/props to the same element
Expand All @@ -23,15 +29,15 @@ export const updateElement = (

if (BUILD.updatable) {
// remove attributes no longer present on the vnode by setting them to undefined
for (memberName of sortedAttrNames(Object.keys(oldVnodeAttrs))) {
for (const memberName of sortedAttrNames(Object.keys(oldVnodeAttrs))) {
if (!(memberName in newVnodeAttrs)) {
setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
}
}
}

// add new & update changed attributes
for (memberName of sortedAttrNames(Object.keys(newVnodeAttrs))) {
for (const memberName of sortedAttrNames(Object.keys(newVnodeAttrs))) {
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
}
};
Expand Down

0 comments on commit dfea716

Please sign in to comment.