Skip to content

Instantly share code, notes, and snippets.

@asoglovo
Last active February 7, 2020 16:12
Show Gist options
  • Save asoglovo/cdd29893c3e7ecd5fe7f6800b9c19979 to your computer and use it in GitHub Desktop.
Save asoglovo/cdd29893c3e7ecd5fe7f6800b9c19979 to your computer and use it in GitHub Desktop.
Vue3 patch function simplified
function patch(
n1: HostVNode | null
n2: HostVNode,
container: HostElement
/* elided arguments */
) {
/* elided */
const { type, shapeFlag } = n2
switch (type) {
case Text:
processText(n1, n2, container, /* elided args */)
break
case Comment:
processCommentNode(n1, n2, container, /* elided args */)
break
/* some elided cases */
default:
if (shapeFlag & ShapeFlags.ELEMENT) {
processElement(n1, n2, container, /* elided args */)
} else if (shapeFlag & ShapeFlags.COMPONENT) {
processComponent(n1, n2, container, /* elided args */)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment