Comparing version 0.0.6 to 0.0.7
@@ -33,3 +33,3 @@ "use strict"; | ||
if (!isForgoElement(forgoNode)) { | ||
return renderString(forgoNode.toString(), node, pendingAttachStates); | ||
return renderString(stringOfPrimitiveNode(forgoNode), node, pendingAttachStates); | ||
} | ||
@@ -216,7 +216,7 @@ // HTML Element | ||
childNodes[forgoChildIndex].nodeType === TEXT_NODE_TYPE) { | ||
render(forgoChild.toString(), childNodes[forgoChildIndex], []); | ||
render(stringOfPrimitiveNode(forgoChild), childNodes[forgoChildIndex], []); | ||
} | ||
// But otherwise, don't pass a replacement node. Just insert instead. | ||
else { | ||
const { node } = render(forgoChild.toString(), undefined, []); | ||
const { node } = render(stringOfPrimitiveNode(forgoChild), undefined, []); | ||
parentElement.insertBefore(node, childNodes[forgoChildIndex]); | ||
@@ -230,4 +230,6 @@ } | ||
if (findResult.found) { | ||
unloadNodes(parentElement, childNodes, forgoChildIndex, findResult.index); | ||
render(forgoChild, childNodes[findResult.index], []); | ||
for (let i = forgoChildIndex; i < findResult.index; i++) { | ||
unloadNode(parentElement, childNodes[i]); | ||
} | ||
render(forgoChild, childNodes[forgoChildIndex], []); | ||
} | ||
@@ -240,6 +242,8 @@ else { | ||
} | ||
// Now we gotta remove old nodes which aren't being used. | ||
// Everything after forgoChildIndex must go. | ||
unloadNodes(parentElement, childNodes, forgoChildIndex + 1, childNodes.length); | ||
} | ||
// Now we gotta remove old nodes which aren't being used. | ||
// Everything after forgoChildIndex must go. | ||
for (let i = forgoChildIndex; i < childNodes.length; i++) { | ||
unloadNode(parentElement, childNodes[i]); | ||
} | ||
} | ||
@@ -252,12 +256,9 @@ /* | ||
*/ | ||
function unloadNodes(parentElement, nodes, from, to) { | ||
for (let i = from; i < to; i++) { | ||
const node = nodes[i]; | ||
parentElement.removeChild(node); | ||
const state = getForgoState(node); | ||
if (state) { | ||
for (const componentState of state.components) { | ||
if (componentState.component.unmount) { | ||
componentState.component.unmount(); | ||
} | ||
function unloadNode(parentElement, node) { | ||
parentElement.removeChild(node); | ||
const state = getForgoState(node); | ||
if (state) { | ||
for (const componentState of state.components) { | ||
if (componentState.component.unmount) { | ||
componentState.component.unmount(); | ||
} | ||
@@ -425,2 +426,9 @@ } | ||
/* | ||
ForgoNodes can be primitive types. | ||
Convert all primitive types to their string representation. | ||
*/ | ||
function stringOfPrimitiveNode(node) { | ||
return typeof node === "undefined" ? "undefined" : node.toString(); | ||
} | ||
/* | ||
Nodes could be strings, numbers, booleans etc. | ||
@@ -430,3 +438,3 @@ Treat them as strings. | ||
function isForgoElement(node) { | ||
return node.__is_forgo_element__ === true; | ||
return (typeof node !== "undefined" && node.__is_forgo_element__ === true); | ||
} | ||
@@ -433,0 +441,0 @@ /* |
{ | ||
"name": "forgo", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"main": "./dist", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
@@ -149,3 +149,7 @@ /* | ||
if (!isForgoElement(forgoNode)) { | ||
return renderString(forgoNode.toString(), node, pendingAttachStates); | ||
return renderString( | ||
stringOfPrimitiveNode(forgoNode), | ||
node, | ||
pendingAttachStates | ||
); | ||
} | ||
@@ -389,7 +393,15 @@ // HTML Element | ||
) { | ||
render(forgoChild.toString(), childNodes[forgoChildIndex], []); | ||
render( | ||
stringOfPrimitiveNode(forgoChild), | ||
childNodes[forgoChildIndex], | ||
[] | ||
); | ||
} | ||
// But otherwise, don't pass a replacement node. Just insert instead. | ||
else { | ||
const { node } = render(forgoChild.toString(), undefined, []); | ||
const { node } = render( | ||
stringOfPrimitiveNode(forgoChild), | ||
undefined, | ||
[] | ||
); | ||
parentElement.insertBefore(node, childNodes[forgoChildIndex]); | ||
@@ -412,9 +424,6 @@ } | ||
if (findResult.found) { | ||
unloadNodes( | ||
parentElement, | ||
childNodes, | ||
forgoChildIndex, | ||
findResult.index | ||
); | ||
render(forgoChild, childNodes[findResult.index], []); | ||
for (let i = forgoChildIndex; i < findResult.index; i++) { | ||
unloadNode(parentElement, childNodes[i]); | ||
} | ||
render(forgoChild, childNodes[forgoChildIndex], []); | ||
} else { | ||
@@ -426,11 +435,8 @@ const { node } = render(forgoChild, undefined, []); | ||
} | ||
// Now we gotta remove old nodes which aren't being used. | ||
// Everything after forgoChildIndex must go. | ||
unloadNodes( | ||
parentElement, | ||
childNodes, | ||
forgoChildIndex + 1, | ||
childNodes.length | ||
); | ||
} | ||
// Now we gotta remove old nodes which aren't being used. | ||
// Everything after forgoChildIndex must go. | ||
for (let i = forgoChildIndex; i < childNodes.length; i++) { | ||
unloadNode(parentElement, childNodes[i]); | ||
} | ||
} | ||
@@ -444,17 +450,9 @@ | ||
*/ | ||
function unloadNodes( | ||
parentElement: HTMLElement, | ||
nodes: NodeListOf<ChildNode>, | ||
from: number, | ||
to: number | ||
) { | ||
for (let i = from; i < to; i++) { | ||
const node = nodes[i]; | ||
parentElement.removeChild(node); | ||
const state = getForgoState(node); | ||
if (state) { | ||
for (const componentState of state.components) { | ||
if (componentState.component.unmount) { | ||
componentState.component.unmount(); | ||
} | ||
function unloadNode(parentElement: HTMLElement, node: ChildNode) { | ||
parentElement.removeChild(node); | ||
const state = getForgoState(node); | ||
if (state) { | ||
for (const componentState of state.components) { | ||
if (componentState.component.unmount) { | ||
componentState.component.unmount(); | ||
} | ||
@@ -656,2 +654,10 @@ } | ||
/* | ||
ForgoNodes can be primitive types. | ||
Convert all primitive types to their string representation. | ||
*/ | ||
function stringOfPrimitiveNode(node: ForgoNode) { | ||
return typeof node === "undefined" ? "undefined" : node.toString(); | ||
} | ||
/* | ||
Nodes could be strings, numbers, booleans etc. | ||
@@ -661,3 +667,5 @@ Treat them as strings. | ||
function isForgoElement(node: ForgoNode): node is ForgoElement<any, any> { | ||
return (node as any).__is_forgo_element__ === true; | ||
return ( | ||
typeof node !== "undefined" && (node as any).__is_forgo_element__ === true | ||
); | ||
} | ||
@@ -664,0 +672,0 @@ |
Sorry, the diff of this file is not supported yet
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
66522
1125