Comparing version 0.0.22 to 0.0.23
@@ -23,3 +23,3 @@ export declare type ForgoRef<T> = { | ||
error?: (props: TProps, args: ForgoErrorArgs) => ForgoElement<ForgoComponentCtor<TProps>, TProps>; | ||
unmount?: () => void; | ||
unmount?: (props: TProps, args: ForgoRenderArgs) => void; | ||
shouldUpdate?: (newProps: TProps, oldProps: TProps) => boolean; | ||
@@ -26,0 +26,0 @@ }; |
@@ -144,16 +144,16 @@ "use strict"; | ||
const componentIndex = pendingAttachStates.length; | ||
const savedComponentState = state.components[componentIndex]; | ||
const haveCompatibleState = savedComponentState && savedComponentState.ctor === forgoElement.type; | ||
const componentState = state.components[componentIndex]; | ||
const haveCompatibleState = componentState && componentState.ctor === forgoElement.type; | ||
// We have compatible state, and this is a rerender | ||
if (haveCompatibleState) { | ||
if (fullRerender || | ||
havePropsChanged(forgoElement.props, savedComponentState.props)) { | ||
if (!savedComponentState.component.shouldUpdate || | ||
savedComponentState.component.shouldUpdate(forgoElement.props, savedComponentState.props)) { | ||
havePropsChanged(forgoElement.props, componentState.props)) { | ||
if (!componentState.component.shouldUpdate || | ||
componentState.component.shouldUpdate(forgoElement.props, componentState.props)) { | ||
// 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 })); | ||
const statesToAttach = pendingAttachStates.concat(Object.assign(Object.assign({}, componentState), { props: forgoElement.props })); | ||
// Get a new element by calling render on existing component. | ||
const newForgoElement = savedComponentState.component.render(forgoElement.props, savedComponentState.args); | ||
return boundaryFallback(node, forgoElement.props, savedComponentState.args, statesToAttach, fullRerender, boundary, () => { | ||
const newForgoElement = componentState.component.render(forgoElement.props, componentState.args); | ||
return boundaryFallback(node, forgoElement.props, componentState.args, statesToAttach, fullRerender, boundary, () => { | ||
// Pass it on for rendering... | ||
@@ -181,3 +181,3 @@ return internalRender(newForgoElement, node, statesToAttach, fullRerender, boundary); | ||
// ... and push it to pendingAttachStates | ||
const componentState = { | ||
const newComponentState = { | ||
key: forgoElement.key, | ||
@@ -189,3 +189,3 @@ ctor, | ||
}; | ||
const statesToAttach = pendingAttachStates.concat(componentState); | ||
const statesToAttach = pendingAttachStates.concat(newComponentState); | ||
return boundaryFallback(node, forgoElement.props, args, statesToAttach, fullRerender, boundary, () => { | ||
@@ -305,3 +305,3 @@ // Create an element by rendering the component | ||
if (componentState.component.unmount) { | ||
componentState.component.unmount(); | ||
componentState.component.unmount(componentState.props, componentState.args); | ||
} | ||
@@ -337,3 +337,3 @@ } | ||
if (oldState.component.unmount) { | ||
oldState.component.unmount(); | ||
oldState.component.unmount(oldState.props, oldState.args); | ||
} | ||
@@ -483,10 +483,10 @@ } | ||
if (state) { | ||
const component = state.components[element.componentIndex]; | ||
const effectiveProps = typeof props !== "undefined" ? props : component.props; | ||
if (!component.component.shouldUpdate || | ||
component.component.shouldUpdate(effectiveProps, component.props)) { | ||
const forgoNode = component.component.render(effectiveProps, component.args); | ||
const componentState = state.components[element.componentIndex]; | ||
const effectiveProps = typeof props !== "undefined" ? props : componentState.props; | ||
if (!componentState.component.shouldUpdate || | ||
componentState.component.shouldUpdate(effectiveProps, componentState.props)) { | ||
const forgoNode = componentState.component.render(effectiveProps, componentState.args); | ||
const statesToAttach = state.components | ||
.slice(0, element.componentIndex) | ||
.concat(Object.assign(Object.assign({}, component), { props: effectiveProps })); | ||
.concat(Object.assign(Object.assign({}, componentState), { props: effectiveProps })); | ||
internalRender(forgoNode, element.node, statesToAttach, fullRerender); | ||
@@ -493,0 +493,0 @@ } |
{ | ||
"name": "forgo", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"main": "./dist", | ||
@@ -5,0 +5,0 @@ "author": "Jeswin Kumar<jeswinpk@agilehead.com>", |
@@ -122,3 +122,3 @@ # forgo | ||
When a component is unmounted, Forgo will invoke the unmount() function if defined for a component. This is of course, totally optional. | ||
When a component is unmounted, Forgo will invoke the unmount() function if defined for a component. It receives the current props and args as arguments, just as in the render() function. | ||
@@ -131,3 +131,3 @@ ```jsx | ||
}, | ||
unmount() { | ||
unmount(props, args) { | ||
console.log("Got unloaded."); | ||
@@ -134,0 +134,0 @@ }, |
@@ -52,3 +52,3 @@ /* | ||
) => ForgoElement<ForgoComponentCtor<TProps>, TProps>; | ||
unmount?: () => void; | ||
unmount?: (props: TProps, args: ForgoRenderArgs) => void; | ||
shouldUpdate?: (newProps: TProps, oldProps: TProps) => boolean; | ||
@@ -332,5 +332,5 @@ }; | ||
const componentIndex = pendingAttachStates.length; | ||
const savedComponentState = state.components[componentIndex]; | ||
const componentState = state.components[componentIndex]; | ||
const haveCompatibleState = | ||
savedComponentState && savedComponentState.ctor === forgoElement.type; | ||
componentState && componentState.ctor === forgoElement.type; | ||
@@ -341,9 +341,9 @@ // We have compatible state, and this is a rerender | ||
fullRerender || | ||
havePropsChanged(forgoElement.props, savedComponentState.props) | ||
havePropsChanged(forgoElement.props, componentState.props) | ||
) { | ||
if ( | ||
!savedComponentState.component.shouldUpdate || | ||
savedComponentState.component.shouldUpdate( | ||
!componentState.component.shouldUpdate || | ||
componentState.component.shouldUpdate( | ||
forgoElement.props, | ||
savedComponentState.props | ||
componentState.props | ||
) | ||
@@ -354,3 +354,3 @@ ) { | ||
const statesToAttach = pendingAttachStates.concat({ | ||
...savedComponentState, | ||
...componentState, | ||
props: forgoElement.props, | ||
@@ -360,5 +360,5 @@ }); | ||
// Get a new element by calling render on existing component. | ||
const newForgoElement = savedComponentState.component.render( | ||
const newForgoElement = componentState.component.render( | ||
forgoElement.props, | ||
savedComponentState.args | ||
componentState.args | ||
); | ||
@@ -369,3 +369,3 @@ | ||
forgoElement.props, | ||
savedComponentState.args, | ||
componentState.args, | ||
statesToAttach, | ||
@@ -405,3 +405,3 @@ fullRerender, | ||
// ... and push it to pendingAttachStates | ||
const componentState = { | ||
const newComponentState = { | ||
key: forgoElement.key, | ||
@@ -413,3 +413,3 @@ ctor, | ||
}; | ||
const statesToAttach = pendingAttachStates.concat(componentState); | ||
const statesToAttach = pendingAttachStates.concat(newComponentState); | ||
@@ -608,3 +608,6 @@ return boundaryFallback( | ||
if (componentState.component.unmount) { | ||
componentState.component.unmount(); | ||
componentState.component.unmount( | ||
componentState.props, | ||
componentState.args | ||
); | ||
} | ||
@@ -645,3 +648,3 @@ } | ||
if (oldState.component.unmount) { | ||
oldState.component.unmount(); | ||
oldState.component.unmount(oldState.props, oldState.args); | ||
} | ||
@@ -822,14 +825,17 @@ } | ||
if (state) { | ||
const component = state.components[element.componentIndex]; | ||
const componentState = state.components[element.componentIndex]; | ||
const effectiveProps = | ||
typeof props !== "undefined" ? props : component.props; | ||
typeof props !== "undefined" ? props : componentState.props; | ||
if ( | ||
!component.component.shouldUpdate || | ||
component.component.shouldUpdate(effectiveProps, component.props) | ||
!componentState.component.shouldUpdate || | ||
componentState.component.shouldUpdate( | ||
effectiveProps, | ||
componentState.props | ||
) | ||
) { | ||
const forgoNode = component.component.render( | ||
const forgoNode = componentState.component.render( | ||
effectiveProps, | ||
component.args | ||
componentState.args | ||
); | ||
@@ -840,3 +846,3 @@ | ||
.concat({ | ||
...component, | ||
...componentState, | ||
props: effectiveProps, | ||
@@ -843,0 +849,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
82491
1411