Last active
February 7, 2020 16:12
-
-
Save asoglovo/cdd29893c3e7ecd5fe7f6800b9c19979 to your computer and use it in GitHub Desktop.
Vue3 patch function simplified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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