Comparing version 0.0.17 to 0.0.18
@@ -145,5 +145,26 @@ "use strict"; | ||
const savedComponentState = state.components[componentIndex]; | ||
const hasCompatibleState = savedComponentState && savedComponentState.ctor === forgoElement.type; | ||
if (!hasCompatibleState) { | ||
// We have to create a new component | ||
const haveCompatibleState = savedComponentState && savedComponentState.ctor === forgoElement.type; | ||
// We have compatible state, and this is a rerender | ||
if (haveCompatibleState) { | ||
if (fullRerender || | ||
havePropsChanged(savedComponentState.props, forgoElement.props)) { | ||
const args = { | ||
element: { componentIndex: pendingAttachStates.length }, | ||
}; | ||
// Since we have compatible state already stored, | ||
// we'll push the savedComponentState into pending states for later attachment. | ||
const statesToAttach = pendingAttachStates.concat(Object.assign(Object.assign({}, savedComponentState), { props: forgoElement.props })); | ||
// Get a new element by calling render on existing component. | ||
const newForgoElement = savedComponentState.component.render(forgoElement.props, args); | ||
return boundaryFallback(node, forgoElement.props, args, statesToAttach, fullRerender, boundary, () => { | ||
// Pass it on for rendering... | ||
return internalRender(newForgoElement, node, statesToAttach, fullRerender, boundary); | ||
}); | ||
} | ||
else { | ||
return { node, boundary }; | ||
} | ||
} | ||
// We don't have compatible state, have to create a new component. | ||
else { | ||
const args = { element: { componentIndex } }; | ||
@@ -170,23 +191,2 @@ const ctor = forgoElement.type; | ||
} | ||
// We have compatible state, and this is a rerender | ||
else { | ||
if (fullRerender || | ||
havePropsChanged(savedComponentState.props, forgoElement.props)) { | ||
const args = { | ||
element: { componentIndex: pendingAttachStates.length }, | ||
}; | ||
// Since we have compatible state already stored, | ||
// we'll push the savedComponentState into pending states for later attachment. | ||
const statesToAttach = pendingAttachStates.concat(Object.assign(Object.assign({}, savedComponentState), { props: forgoElement.props })); | ||
// Get a new element by calling render on existing component. | ||
const newForgoElement = savedComponentState.component.render(forgoElement.props, args); | ||
return boundaryFallback(node, forgoElement.props, args, statesToAttach, fullRerender, boundary, () => { | ||
// Pass it on for rendering... | ||
return internalRender(newForgoElement, node, statesToAttach, fullRerender, boundary); | ||
}); | ||
} | ||
else { | ||
return { node, boundary }; | ||
} | ||
} | ||
} | ||
@@ -193,0 +193,0 @@ // First time render |
{ | ||
"name": "forgo", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"main": "./dist", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
@@ -330,47 +330,7 @@ /* | ||
const savedComponentState = state.components[componentIndex]; | ||
const hasCompatibleState = | ||
const haveCompatibleState = | ||
savedComponentState && savedComponentState.ctor === forgoElement.type; | ||
if (!hasCompatibleState) { | ||
// We have to create a new component | ||
const args: ForgoRenderArgs = { element: { componentIndex } }; | ||
const ctor = forgoElement.type; | ||
const component = ctor(forgoElement.props); | ||
boundary = component.error ? component : boundary; | ||
// Create new component state | ||
// ... and push it to pendingAttachStates | ||
const componentState = { | ||
key: forgoElement.key, | ||
ctor, | ||
component, | ||
props: forgoElement.props, | ||
args, | ||
}; | ||
const statesToAttach = pendingAttachStates.concat(componentState); | ||
return boundaryFallback( | ||
node, | ||
forgoElement.props, | ||
args, | ||
statesToAttach, | ||
fullRerender, | ||
boundary, | ||
() => { | ||
// Create an element by rendering the component | ||
const newForgoElement = component.render(forgoElement.props, args); | ||
// Pass it on for rendering... | ||
return internalRender( | ||
newForgoElement, | ||
node, | ||
statesToAttach, | ||
fullRerender, | ||
boundary | ||
); | ||
} | ||
); | ||
} | ||
// We have compatible state, and this is a rerender | ||
else { | ||
if (haveCompatibleState) { | ||
if ( | ||
@@ -419,2 +379,42 @@ fullRerender || | ||
} | ||
// We don't have compatible state, have to create a new component. | ||
else { | ||
const args: ForgoRenderArgs = { element: { componentIndex } }; | ||
const ctor = forgoElement.type; | ||
const component = ctor(forgoElement.props); | ||
boundary = component.error ? component : boundary; | ||
// Create new component state | ||
// ... and push it to pendingAttachStates | ||
const componentState = { | ||
key: forgoElement.key, | ||
ctor, | ||
component, | ||
props: forgoElement.props, | ||
args, | ||
}; | ||
const statesToAttach = pendingAttachStates.concat(componentState); | ||
return boundaryFallback( | ||
node, | ||
forgoElement.props, | ||
args, | ||
statesToAttach, | ||
fullRerender, | ||
boundary, | ||
() => { | ||
// Create an element by rendering the component | ||
const newForgoElement = component.render(forgoElement.props, args); | ||
// Pass it on for rendering... | ||
return internalRender( | ||
newForgoElement, | ||
node, | ||
statesToAttach, | ||
fullRerender, | ||
boundary | ||
); | ||
} | ||
); | ||
} | ||
} | ||
@@ -551,3 +551,3 @@ // First time render | ||
forgoChild, | ||
childNodes[forgoChildIndex], | ||
childNodes[forgoChildIndex], | ||
[], | ||
@@ -554,0 +554,0 @@ fullRerender |
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
77671