Created
September 26, 2016 20:52
-
-
Save kristoferjoseph/dc9daae6fd8ca47b5557356b09b91f70 to your computer and use it in GitHub Desktop.
Helper function used in memoization of an HTML Node.
This file contains hidden or 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
module.exports = function memoizeNode(node) { | |
var element | |
var placeholder | |
var mounted = false | |
return function render() { | |
if(!element) { | |
element = node | |
mounted = true | |
return element | |
} | |
else if (!mounted) { | |
mounted = true | |
return element | |
} | |
else { | |
placeholder = html`<template></template>` | |
placeholder.isSameNode = function(el) { | |
el.isSameNode(element) | |
} | |
return placeholder | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet was extrapolated from the code found Here