inferno-hydrate
Advanced tools
Comparing version 8.0.3 to 8.0.4
@@ -9,240 +9,225 @@ 'use strict'; | ||
function isNullOrUndef(o) { | ||
return o === void 0 || o === null; | ||
return o === void 0 || o === null; | ||
} | ||
function isInvalid(o) { | ||
return o === null || o === false || o === true || o === void 0; | ||
return o === null || o === false || o === true || o === void 0; | ||
} | ||
function isFunction(o) { | ||
return typeof o === 'function'; | ||
return typeof o === 'function'; | ||
} | ||
function isNull(o) { | ||
return o === null; | ||
return o === null; | ||
} | ||
function throwError(message) { | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error(("Inferno Error: " + message)); | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error("Inferno Error: " + message); | ||
} | ||
function warning(message) { | ||
// tslint:disable-next-line:no-console | ||
console.error(message); | ||
// tslint:disable-next-line:no-console | ||
console.error(message); | ||
} | ||
function isSameInnerHTML(dom, innerHTML) { | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
} | ||
function findLastDOMFromVNode(vNode) { | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} | ||
else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} | ||
else { | ||
vNode = children; | ||
} | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
return null; | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} else { | ||
vNode = children; | ||
} | ||
} | ||
return null; | ||
} | ||
function isSamePropsInnerHTML(dom, props) { | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
} | ||
function hydrateComponent(vNode, parentDOM, dom, context, isSVG, isClass, lifecycle, animations) { | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || inferno.EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = inferno._CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
inferno._MCCC(ref, instance, lifecycle, animations); | ||
} | ||
else { | ||
var input$1 = inferno._HI(inferno._RFC(vNode, context)); | ||
currentNode = hydrateVNode(input$1, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = input$1; | ||
inferno._MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || inferno.EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = inferno._CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
inferno._MCCC(ref, instance, lifecycle, animations); | ||
} else { | ||
var _input = inferno._HI(inferno._RFC(vNode, context)); | ||
currentNode = hydrateVNode(_input, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = _input; | ||
inferno._MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
} | ||
function hydrateChildren(parentVNode, parentNode, currentNode, context, isSVG, lifecycle, animations) { | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
inferno._M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
inferno._M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
} else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} | ||
else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} | ||
else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
} | ||
currentNode = null; | ||
} | ||
currentNode = null; | ||
} else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0) { | ||
inferno._M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || (prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0)) { | ||
inferno._M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
} else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
} | ||
} | ||
function hydrateElement(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
inferno._ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
inferno._MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} | ||
else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} | ||
else { | ||
dom.className = className; | ||
} | ||
inferno._MR(ref, dom, lifecycle); | ||
inferno._ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
} else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
inferno._MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
return vNode.dom; | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} else { | ||
dom.className = className; | ||
} | ||
inferno._MR(ref, dom, lifecycle); | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateText(vNode, parentDOM, dom) { | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild((vNode.dom = document.createTextNode(vNode.children)), dom); | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild(vNode.dom = document.createTextNode(vNode.children), dom); | ||
} else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateFragment(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
} | ||
function hydrateVNode(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations) { | ||
var flags = (vNode.flags |= 16384 /* VNodeFlags.InUse */); | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
{ | ||
throwError(("hydrate() expects a valid VNode, instead it received an object with the type \"" + (typeof vNode) + "\".")); | ||
} | ||
throwError(); | ||
return null; | ||
var flags = vNode.flags |= 16384 /* VNodeFlags.InUse */; | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
{ | ||
throwError("hydrate() expects a valid VNode, instead it received an object with the type \"" + typeof vNode + "\"."); | ||
} | ||
throwError(); | ||
return null; | ||
} | ||
function hydrate(input, parentDOM, callback) { | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
inferno.render(input, parentDOM, callback); | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
else { | ||
var lifecycle = []; | ||
var animations = new inferno.AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
inferno.render(input, parentDOM, callback); | ||
} else { | ||
var lifecycle = []; | ||
var animations = new inferno.AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
exports.hydrate = hydrate; |
@@ -5,240 +5,225 @@ import { render, AnimationQueues, EMPTY_OBJ, _CI, _MCCC, _HI, _RFC, _MFCC, _ME, _MP, _MR, _M } from 'inferno'; | ||
function isNullOrUndef(o) { | ||
return o === void 0 || o === null; | ||
return o === void 0 || o === null; | ||
} | ||
function isInvalid(o) { | ||
return o === null || o === false || o === true || o === void 0; | ||
return o === null || o === false || o === true || o === void 0; | ||
} | ||
function isFunction(o) { | ||
return typeof o === 'function'; | ||
return typeof o === 'function'; | ||
} | ||
function isNull(o) { | ||
return o === null; | ||
return o === null; | ||
} | ||
function throwError(message) { | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error(("Inferno Error: " + message)); | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error("Inferno Error: " + message); | ||
} | ||
function warning(message) { | ||
// tslint:disable-next-line:no-console | ||
console.error(message); | ||
// tslint:disable-next-line:no-console | ||
console.error(message); | ||
} | ||
function isSameInnerHTML(dom, innerHTML) { | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
} | ||
function findLastDOMFromVNode(vNode) { | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} | ||
else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} | ||
else { | ||
vNode = children; | ||
} | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
return null; | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} else { | ||
vNode = children; | ||
} | ||
} | ||
return null; | ||
} | ||
function isSamePropsInnerHTML(dom, props) { | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
} | ||
function hydrateComponent(vNode, parentDOM, dom, context, isSVG, isClass, lifecycle, animations) { | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = _CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
_MCCC(ref, instance, lifecycle, animations); | ||
} | ||
else { | ||
var input$1 = _HI(_RFC(vNode, context)); | ||
currentNode = hydrateVNode(input$1, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = input$1; | ||
_MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = _CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
_MCCC(ref, instance, lifecycle, animations); | ||
} else { | ||
var _input = _HI(_RFC(vNode, context)); | ||
currentNode = hydrateVNode(_input, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = _input; | ||
_MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
} | ||
function hydrateChildren(parentVNode, parentNode, currentNode, context, isSVG, lifecycle, animations) { | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
_M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
_M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
} else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} | ||
else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} | ||
else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
} | ||
currentNode = null; | ||
} | ||
currentNode = null; | ||
} else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0) { | ||
_M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || (prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0)) { | ||
_M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
} else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
} | ||
} | ||
function hydrateElement(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
_ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
_MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} | ||
else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} | ||
else { | ||
dom.className = className; | ||
} | ||
_MR(ref, dom, lifecycle); | ||
_ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
} else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
_MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
return vNode.dom; | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} else { | ||
dom.className = className; | ||
} | ||
_MR(ref, dom, lifecycle); | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateText(vNode, parentDOM, dom) { | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild((vNode.dom = document.createTextNode(vNode.children)), dom); | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild(vNode.dom = document.createTextNode(vNode.children), dom); | ||
} else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateFragment(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
} | ||
function hydrateVNode(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations) { | ||
var flags = (vNode.flags |= 16384 /* VNodeFlags.InUse */); | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
{ | ||
throwError(("hydrate() expects a valid VNode, instead it received an object with the type \"" + (typeof vNode) + "\".")); | ||
} | ||
throwError(); | ||
return null; | ||
var flags = vNode.flags |= 16384 /* VNodeFlags.InUse */; | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
{ | ||
throwError("hydrate() expects a valid VNode, instead it received an object with the type \"" + typeof vNode + "\"."); | ||
} | ||
throwError(); | ||
return null; | ||
} | ||
function hydrate(input, parentDOM, callback) { | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
render(input, parentDOM, callback); | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
else { | ||
var lifecycle = []; | ||
var animations = new AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
render(input, parentDOM, callback); | ||
} else { | ||
var lifecycle = []; | ||
var animations = new AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
export { hydrate }; |
@@ -5,227 +5,212 @@ import { render, AnimationQueues, EMPTY_OBJ, _CI, _MCCC, _HI, _RFC, _MFCC, _ME, _MP, _MR, _M } from 'inferno'; | ||
function isNullOrUndef(o) { | ||
return o === void 0 || o === null; | ||
return o === void 0 || o === null; | ||
} | ||
function isInvalid(o) { | ||
return o === null || o === false || o === true || o === void 0; | ||
return o === null || o === false || o === true || o === void 0; | ||
} | ||
function isFunction(o) { | ||
return typeof o === 'function'; | ||
return typeof o === 'function'; | ||
} | ||
function isNull(o) { | ||
return o === null; | ||
return o === null; | ||
} | ||
function throwError(message) { | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error(("Inferno Error: " + message)); | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error("Inferno Error: " + message); | ||
} | ||
function isSameInnerHTML(dom, innerHTML) { | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
} | ||
function findLastDOMFromVNode(vNode) { | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} | ||
else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} | ||
else { | ||
vNode = children; | ||
} | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
return null; | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} else { | ||
vNode = children; | ||
} | ||
} | ||
return null; | ||
} | ||
function isSamePropsInnerHTML(dom, props) { | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
} | ||
function hydrateComponent(vNode, parentDOM, dom, context, isSVG, isClass, lifecycle, animations) { | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = _CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
_MCCC(ref, instance, lifecycle, animations); | ||
} | ||
else { | ||
var input$1 = _HI(_RFC(vNode, context)); | ||
currentNode = hydrateVNode(input$1, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = input$1; | ||
_MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = _CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
_MCCC(ref, instance, lifecycle, animations); | ||
} else { | ||
var _input = _HI(_RFC(vNode, context)); | ||
currentNode = hydrateVNode(_input, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = _input; | ||
_MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
} | ||
function hydrateChildren(parentVNode, parentNode, currentNode, context, isSVG, lifecycle, animations) { | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
_M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
_M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
} else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} | ||
else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} | ||
else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
} | ||
currentNode = null; | ||
} | ||
currentNode = null; | ||
} else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0) { | ||
_M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || (prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0)) { | ||
_M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
} else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
} | ||
} | ||
function hydrateElement(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
_ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
_ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
} else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
_MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
_MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} | ||
else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} | ||
else { | ||
dom.className = className; | ||
} | ||
_MR(ref, dom, lifecycle); | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} else { | ||
dom.className = className; | ||
} | ||
return vNode.dom; | ||
_MR(ref, dom, lifecycle); | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateText(vNode, parentDOM, dom) { | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild((vNode.dom = document.createTextNode(vNode.children)), dom); | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild(vNode.dom = document.createTextNode(vNode.children), dom); | ||
} else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateFragment(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
} | ||
function hydrateVNode(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations) { | ||
var flags = (vNode.flags |= 16384 /* VNodeFlags.InUse */); | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
throwError(); | ||
return null; | ||
var flags = vNode.flags |= 16384 /* VNodeFlags.InUse */; | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
throwError(); | ||
return null; | ||
} | ||
function hydrate(input, parentDOM, callback) { | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
render(input, parentDOM, callback); | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
render(input, parentDOM, callback); | ||
} else { | ||
var lifecycle = []; | ||
var animations = new AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
else { | ||
var lifecycle = []; | ||
var animations = new AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
export { hydrate }; |
@@ -5,227 +5,212 @@ import { render, AnimationQueues, EMPTY_OBJ, _CI, _MCCC, _HI, _RFC, _MFCC, _ME, _MP, _MR, _M } from 'inferno'; | ||
function isNullOrUndef(o) { | ||
return o === void 0 || o === null; | ||
return o === void 0 || o === null; | ||
} | ||
function isInvalid(o) { | ||
return o === null || o === false || o === true || o === void 0; | ||
return o === null || o === false || o === true || o === void 0; | ||
} | ||
function isFunction(o) { | ||
return typeof o === 'function'; | ||
return typeof o === 'function'; | ||
} | ||
function isNull(o) { | ||
return o === null; | ||
return o === null; | ||
} | ||
function throwError(message) { | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error(`Inferno Error: ${message}`); | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error(`Inferno Error: ${message}`); | ||
} | ||
function isSameInnerHTML(dom, innerHTML) { | ||
const tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
const tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
} | ||
function findLastDOMFromVNode(vNode) { | ||
let flags; | ||
let children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} | ||
else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} | ||
else { | ||
vNode = children; | ||
} | ||
let flags; | ||
let children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
return null; | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} else { | ||
vNode = children; | ||
} | ||
} | ||
return null; | ||
} | ||
function isSamePropsInnerHTML(dom, props) { | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
} | ||
function hydrateComponent(vNode, parentDOM, dom, context, isSVG, isClass, lifecycle, animations) { | ||
const type = vNode.type; | ||
const ref = vNode.ref; | ||
const props = vNode.props || EMPTY_OBJ; | ||
let currentNode; | ||
if (isClass) { | ||
const instance = _CI(vNode, type, props, context, isSVG, lifecycle); | ||
const input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
_MCCC(ref, instance, lifecycle, animations); | ||
} | ||
else { | ||
const input = _HI(_RFC(vNode, context)); | ||
currentNode = hydrateVNode(input, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = input; | ||
_MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
const type = vNode.type; | ||
const ref = vNode.ref; | ||
const props = vNode.props || EMPTY_OBJ; | ||
let currentNode; | ||
if (isClass) { | ||
const instance = _CI(vNode, type, props, context, isSVG, lifecycle); | ||
const input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
_MCCC(ref, instance, lifecycle, animations); | ||
} else { | ||
const input = _HI(_RFC(vNode, context)); | ||
currentNode = hydrateVNode(input, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = input; | ||
_MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
} | ||
function hydrateChildren(parentVNode, parentNode, currentNode, context, isSVG, lifecycle, animations) { | ||
const childFlags = parentVNode.childFlags; | ||
const children = parentVNode.children; | ||
const props = parentVNode.props; | ||
const flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
_M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
const childFlags = parentVNode.childFlags; | ||
const children = parentVNode.children; | ||
const props = parentVNode.props; | ||
const flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
_M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
} else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} | ||
else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} | ||
else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
} | ||
currentNode = null; | ||
} | ||
currentNode = null; | ||
} else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
let prevVNodeIsTextNode = false; | ||
for (let i = 0, len = children.length; i < len; ++i) { | ||
const child = children[i]; | ||
if (isNull(currentNode) || prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0) { | ||
_M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
let prevVNodeIsTextNode = false; | ||
for (let i = 0, len = children.length; i < len; ++i) { | ||
const child = children[i]; | ||
if (isNull(currentNode) || (prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0)) { | ||
_M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
let nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
let nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
} else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
} | ||
} | ||
function hydrateElement(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
const props = vNode.props; | ||
const className = vNode.className; | ||
const flags = vNode.flags; | ||
const ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
_ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
const props = vNode.props; | ||
const className = vNode.className; | ||
const flags = vNode.flags; | ||
const ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
_ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
} else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
_MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
_MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} | ||
else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} | ||
else { | ||
dom.className = className; | ||
} | ||
_MR(ref, dom, lifecycle); | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} else { | ||
dom.className = className; | ||
} | ||
return vNode.dom; | ||
_MR(ref, dom, lifecycle); | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateText(vNode, parentDOM, dom) { | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild((vNode.dom = document.createTextNode(vNode.children)), dom); | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild(vNode.dom = document.createTextNode(vNode.children), dom); | ||
} else { | ||
const text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
else { | ||
const text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateFragment(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
const children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
const children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
} | ||
function hydrateVNode(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations) { | ||
const flags = (vNode.flags |= 16384 /* VNodeFlags.InUse */); | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
throwError(); | ||
return null; | ||
const flags = vNode.flags |= 16384 /* VNodeFlags.InUse */; | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
throwError(); | ||
return null; | ||
} | ||
function hydrate(input, parentDOM, callback) { | ||
let dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
render(input, parentDOM, callback); | ||
let dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
render(input, parentDOM, callback); | ||
} else { | ||
const lifecycle = []; | ||
const animations = new AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
else { | ||
const lifecycle = []; | ||
const animations = new AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
let listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
if (lifecycle.length > 0) { | ||
let listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
export { hydrate }; |
@@ -9,238 +9,223 @@ (function (global, factory) { | ||
function isNullOrUndef(o) { | ||
return o === void 0 || o === null; | ||
return o === void 0 || o === null; | ||
} | ||
function isInvalid(o) { | ||
return o === null || o === false || o === true || o === void 0; | ||
return o === null || o === false || o === true || o === void 0; | ||
} | ||
function isFunction(o) { | ||
return typeof o === 'function'; | ||
return typeof o === 'function'; | ||
} | ||
function isNull(o) { | ||
return o === null; | ||
return o === null; | ||
} | ||
function throwError(message) { | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error(("Inferno Error: " + message)); | ||
if (!message) { | ||
message = ERROR_MSG; | ||
} | ||
throw new Error("Inferno Error: " + message); | ||
} | ||
function warning(message) { | ||
// tslint:disable-next-line:no-console | ||
console.error(message); | ||
// tslint:disable-next-line:no-console | ||
console.error(message); | ||
} | ||
function isSameInnerHTML(dom, innerHTML) { | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
var tempdom = document.createElement('i'); | ||
tempdom.innerHTML = innerHTML; | ||
return tempdom.innerHTML === dom.innerHTML; | ||
} | ||
function findLastDOMFromVNode(vNode) { | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} | ||
else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} | ||
else { | ||
vNode = children; | ||
} | ||
var flags; | ||
var children; | ||
while (vNode) { | ||
flags = vNode.flags; | ||
if (flags & 1521 /* VNodeFlags.DOMRef */) { | ||
return vNode.dom; | ||
} | ||
return null; | ||
children = vNode.children; | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
vNode = vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */ ? children : children[children.length - 1]; | ||
} else if (flags & 4 /* VNodeFlags.ComponentClass */) { | ||
vNode = children.$LI; | ||
} else { | ||
vNode = children; | ||
} | ||
} | ||
return null; | ||
} | ||
function isSamePropsInnerHTML(dom, props) { | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html)); | ||
} | ||
function hydrateComponent(vNode, parentDOM, dom, context, isSVG, isClass, lifecycle, animations) { | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || inferno.EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = inferno._CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
inferno._MCCC(ref, instance, lifecycle, animations); | ||
} | ||
else { | ||
var input$1 = inferno._HI(inferno._RFC(vNode, context)); | ||
currentNode = hydrateVNode(input$1, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = input$1; | ||
inferno._MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
var type = vNode.type; | ||
var ref = vNode.ref; | ||
var props = vNode.props || inferno.EMPTY_OBJ; | ||
var currentNode; | ||
if (isClass) { | ||
var instance = inferno._CI(vNode, type, props, context, isSVG, lifecycle); | ||
var input = instance.$LI; | ||
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle, animations); | ||
inferno._MCCC(ref, instance, lifecycle, animations); | ||
} else { | ||
var _input = inferno._HI(inferno._RFC(vNode, context)); | ||
currentNode = hydrateVNode(_input, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
vNode.children = _input; | ||
inferno._MFCC(vNode, lifecycle, animations); | ||
} | ||
return currentNode; | ||
} | ||
function hydrateChildren(parentVNode, parentNode, currentNode, context, isSVG, lifecycle, animations) { | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
inferno._M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
var childFlags = parentVNode.childFlags; | ||
var children = parentVNode.children; | ||
var props = parentVNode.props; | ||
var flags = parentVNode.flags; | ||
if (childFlags !== 1 /* ChildFlags.HasInvalidChildren */) { | ||
if (childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
if (isNull(currentNode)) { | ||
inferno._M(children, parentNode, context, isSVG, null, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(children, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
} else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
else if (childFlags === 16 /* ChildFlags.HasTextChildren */) { | ||
if (isNull(currentNode)) { | ||
parentNode.appendChild(document.createTextNode(children)); | ||
} | ||
else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) { | ||
parentNode.textContent = children; | ||
} | ||
else { | ||
if (currentNode.nodeValue !== children) { | ||
currentNode.nodeValue = children; | ||
} | ||
} | ||
currentNode = null; | ||
} | ||
currentNode = null; | ||
} else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0) { | ||
inferno._M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
else if (childFlags & 12 /* ChildFlags.MultipleChildren */) { | ||
var prevVNodeIsTextNode = false; | ||
for (var i = 0, len = children.length; i < len; ++i) { | ||
var child = children[i]; | ||
if (isNull(currentNode) || (prevVNodeIsTextNode && (child.flags & 16 /* VNodeFlags.Text */) > 0)) { | ||
inferno._M(child, parentNode, context, isSVG, currentNode, lifecycle, animations); | ||
} | ||
else { | ||
currentNode = hydrateVNode(child, parentNode, currentNode, context, isSVG, lifecycle, animations); | ||
currentNode = currentNode ? currentNode.nextSibling : null; | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
prevVNodeIsTextNode = (child.flags & 16 /* VNodeFlags.Text */) > 0; | ||
} | ||
} | ||
else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
if ((flags & 8192 /* VNodeFlags.Fragment */) === 0) { | ||
var nextSibling = null; | ||
while (currentNode) { | ||
nextSibling = currentNode.nextSibling; | ||
parentNode.removeChild(currentNode); | ||
currentNode = nextSibling; | ||
} | ||
} | ||
} else if (!isNull(parentNode.firstChild) && !isSamePropsInnerHTML(parentNode, props)) { | ||
parentNode.textContent = ''; // dom has content, but VNode has no children remove everything from DOM | ||
if (flags & 448 /* VNodeFlags.FormElement */) { | ||
// If element is form element, we need to clear defaultValue also | ||
parentNode.defaultValue = ''; | ||
} | ||
} | ||
} | ||
function hydrateElement(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
inferno._ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
var props = vNode.props; | ||
var className = vNode.className; | ||
var flags = vNode.flags; | ||
var ref = vNode.ref; | ||
isSVG = isSVG || (flags & 32 /* VNodeFlags.SvgElement */) > 0; | ||
if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
inferno._MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} | ||
else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} | ||
else { | ||
dom.className = className; | ||
} | ||
inferno._MR(ref, dom, lifecycle); | ||
inferno._ME(vNode, null, context, isSVG, null, lifecycle, animations); | ||
parentDOM.replaceChild(vNode.dom, dom); | ||
} else { | ||
vNode.dom = dom; | ||
hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle, animations); | ||
if (!isNull(props)) { | ||
inferno._MP(vNode, flags, props, dom, isSVG, animations); | ||
} | ||
return vNode.dom; | ||
if (isNullOrUndef(className)) { | ||
if (dom.className !== '') { | ||
dom.removeAttribute('class'); | ||
} | ||
} else if (isSVG) { | ||
dom.setAttribute('class', className); | ||
} else { | ||
dom.className = className; | ||
} | ||
inferno._MR(ref, dom, lifecycle); | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateText(vNode, parentDOM, dom) { | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild((vNode.dom = document.createTextNode(vNode.children)), dom); | ||
if (dom.nodeType !== 3) { | ||
parentDOM.replaceChild(vNode.dom = document.createTextNode(vNode.children), dom); | ||
} else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
else { | ||
var text = vNode.children; | ||
if (dom.nodeValue !== text) { | ||
dom.nodeValue = text; | ||
} | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
vNode.dom = dom; | ||
} | ||
return vNode.dom; | ||
} | ||
function hydrateFragment(vNode, parentDOM, dom, context, isSVG, lifecycle, animations) { | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
var children = vNode.children; | ||
if (vNode.childFlags === 2 /* ChildFlags.HasVNodeChildren */) { | ||
hydrateText(children, parentDOM, dom); | ||
return children.dom; | ||
} | ||
hydrateChildren(vNode, parentDOM, dom, context, isSVG, lifecycle, animations); | ||
return findLastDOMFromVNode(children[children.length - 1]); | ||
} | ||
function hydrateVNode(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations) { | ||
var flags = (vNode.flags |= 16384 /* VNodeFlags.InUse */); | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
{ | ||
throwError(("hydrate() expects a valid VNode, instead it received an object with the type \"" + (typeof vNode) + "\".")); | ||
} | ||
throwError(); | ||
return null; | ||
var flags = vNode.flags |= 16384 /* VNodeFlags.InUse */; | ||
if (flags & 14 /* VNodeFlags.Component */) { | ||
return hydrateComponent(vNode, parentDOM, currentDom, context, isSVG, (flags & 4 /* VNodeFlags.ComponentClass */) > 0, lifecycle, animations); | ||
} | ||
if (flags & 481 /* VNodeFlags.Element */) { | ||
return hydrateElement(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
if (flags & 16 /* VNodeFlags.Text */) { | ||
return hydrateText(vNode, parentDOM, currentDom); | ||
} | ||
if (flags & 8192 /* VNodeFlags.Fragment */) { | ||
return hydrateFragment(vNode, parentDOM, currentDom, context, isSVG, lifecycle, animations); | ||
} | ||
{ | ||
throwError("hydrate() expects a valid VNode, instead it received an object with the type \"" + typeof vNode + "\"."); | ||
} | ||
throwError(); | ||
return null; | ||
} | ||
function hydrate(input, parentDOM, callback) { | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
inferno.render(input, parentDOM, callback); | ||
var dom = parentDOM.firstChild; | ||
if (isNull(dom)) { | ||
{ | ||
warning("Inferno hydration: Server-side markup doesn't match client-side markup"); | ||
} | ||
else { | ||
var lifecycle = []; | ||
var animations = new inferno.AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
inferno.render(input, parentDOM, callback); | ||
} else { | ||
var lifecycle = []; | ||
var animations = new inferno.AnimationQueues(); | ||
if (!isInvalid(input)) { | ||
dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle, animations); | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
// clear any other DOM nodes, there should be only a single entry for the root | ||
while (dom && (dom = dom.nextSibling)) { | ||
parentDOM.removeChild(dom); | ||
} | ||
if (lifecycle.length > 0) { | ||
var listener; | ||
while ((listener = lifecycle.shift()) !== undefined) { | ||
listener(); | ||
} | ||
} | ||
} | ||
parentDOM.$V = input; | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
@@ -247,0 +232,0 @@ |
# MIT License | ||
Copyright (c) 2015-2021 Dominic Gannaway | ||
Copyright (c) 2015-2022 Dominic Gannaway | ||
@@ -4,0 +4,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "inferno-hydrate", | ||
"version": "8.0.3", | ||
"version": "8.0.4", | ||
"license": "MIT", | ||
@@ -40,9 +40,9 @@ "description": "Hydrate plugin to inferno. This package can be used to reuse server side rendered html", | ||
"dependencies": { | ||
"inferno": "8.0.3" | ||
"inferno": "8.0.4" | ||
}, | ||
"devDependencies": { | ||
"inferno-create-element": "8.0.3", | ||
"inferno-hyperscript": "8.0.3", | ||
"inferno-shared": "8.0.3", | ||
"inferno-vnode-flags": "8.0.3" | ||
"inferno-create-element": "8.0.4", | ||
"inferno-hyperscript": "8.0.4", | ||
"inferno-shared": "8.0.4", | ||
"inferno-vnode-flags": "8.0.4" | ||
}, | ||
@@ -59,3 +59,3 @@ "rollup": { | ||
}, | ||
"gitHead": "9734d7259ed85fe405530c9602696ba588a8cb86" | ||
"gitHead": "d03e86ca6b7863d1dcb79adacc4d2dfce45bf0b2" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51649
1137
+ Addedinferno@8.0.4(transitive)
+ Addedinferno-vnode-flags@8.0.4(transitive)
- Removedinferno@8.0.3(transitive)
- Removedinferno-vnode-flags@8.0.3(transitive)
Updatedinferno@8.0.4