Skip to content

Commit

Permalink
fixed typo with fastUnmount and added types for Lifecycle to avoid re…
Browse files Browse the repository at this point in the history
…gression
  • Loading branch information
Havunen committed Dec 18, 2016
1 parent 00f5c72 commit e072ab9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/inferno/dist/inferno.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ function patchComponent(lastVNode, nextVNode, parentDom, lifecycle, context, isS
var subLifecycle = instance._lifecycle;
lifecycle.fastUnmount = subLifecycle.fastUnmount;
patch(lastInput$1, nextInput$1, parentDom, lifecycle, childContext, isSVG, isRecycling);
subLifecycle.fastUnmount = lifecycle.unmount;
subLifecycle.fastUnmount = lifecycle.fastUnmount;
lifecycle.fastUnmount = fastUnmount;
instance.componentDidUpdate(lastProps, lastState);
findDOMNodeEnabled && componentToDOMNodeMap.set(instance, nextInput$1.dom);
Expand Down
2 changes: 1 addition & 1 deletion packages/inferno/dist/inferno.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/DOM/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function normalizeChildNodes(dom) {
}
}

function hydrateComponent(vNode, dom, lifecycle, context, isSVG, isClass) {
function hydrateComponent(vNode, dom, lifecycle: Lifecycle, context, isSVG, isClass) {
const type = vNode.type;
const props = vNode.props || EMPTY_OBJ;
const ref = vNode.ref;
Expand Down Expand Up @@ -100,7 +100,7 @@ function hydrateComponent(vNode, dom, lifecycle, context, isSVG, isClass) {
}
}

function hydrateElement(vNode, dom, lifecycle, context, isSVG) {
function hydrateElement(vNode, dom, lifecycle: Lifecycle, context, isSVG) {
const tag = vNode.type;
const children = vNode.children;
const props = vNode.props;
Expand Down Expand Up @@ -132,7 +132,7 @@ function hydrateElement(vNode, dom, lifecycle, context, isSVG) {
}
}

function hydrateChildren(children, dom, lifecycle, context, isSVG) {
function hydrateChildren(children, dom, lifecycle: Lifecycle, context, isSVG) {
normalizeChildNodes(dom);
const domNodes = Array.prototype.slice.call(dom.childNodes);
let childNodeIndex = 0;
Expand Down Expand Up @@ -165,7 +165,7 @@ function hydrateVoid(vNode, dom) {
vNode.dom = dom;
}

function hydrate(vNode, dom, lifecycle, context, isSVG) {
function hydrate(vNode, dom, lifecycle: Lifecycle, context, isSVG) {
if (process.env.NODE_ENV !== 'production') {
if (isInvalid(dom)) {
throwError(`failed to hydrate. The server-side render doesn't match client side.`);
Expand Down
14 changes: 7 additions & 7 deletions src/DOM/mounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from './patching';
import processElement from './wrappers/processElement';

export function mount(vNode, parentDom, lifecycle, context, isSVG) {
export function mount(vNode, parentDom, lifecycle: Lifecycle, context, isSVG) {
const flags = vNode.flags;

if (flags & VNodeFlags.Element) {
Expand Down Expand Up @@ -72,7 +72,7 @@ export function mountVoid(vNode, parentDom) {
return dom;
}

export function mountElement(vNode, parentDom, lifecycle, context, isSVG) {
export function mountElement(vNode, parentDom, lifecycle: Lifecycle, context, isSVG) {
if (recyclingEnabled) {
const dom = recycleElement(vNode, lifecycle, context, isSVG);

Expand Down Expand Up @@ -129,7 +129,7 @@ export function mountElement(vNode, parentDom, lifecycle, context, isSVG) {
return dom;
}

export function mountArrayChildren(children, dom, lifecycle, context, isSVG) {
export function mountArrayChildren(children, dom, lifecycle: Lifecycle, context, isSVG) {
for (let i = 0; i < children.length; i++) {
let child = children[i];

Expand All @@ -142,7 +142,7 @@ export function mountArrayChildren(children, dom, lifecycle, context, isSVG) {
}
}

export function mountComponent(vNode, parentDom, lifecycle, context, isSVG, isClass) {
export function mountComponent(vNode, parentDom, lifecycle: Lifecycle, context, isSVG: boolean, isClass: number) {
if (recyclingEnabled) {
const dom = recycleComponent(vNode, lifecycle, context, isSVG);

Expand Down Expand Up @@ -199,7 +199,7 @@ export function mountComponent(vNode, parentDom, lifecycle, context, isSVG, isCl
return dom;
}

export function mountStatefulComponentCallbacks(ref, instance, lifecycle) {
export function mountStatefulComponentCallbacks(ref, instance, lifecycle: Lifecycle) {
if (ref) {
if (isFunction(ref)) {
ref(instance);
Expand All @@ -217,7 +217,7 @@ export function mountStatefulComponentCallbacks(ref, instance, lifecycle) {
}
}

export function mountStatelessComponentCallbacks(ref, dom, lifecycle) {
export function mountStatelessComponentCallbacks(ref, dom, lifecycle: Lifecycle) {
if (ref) {
if (!isNullOrUndef(ref.onComponentWillMount)) {
lifecycle.fastUnmount = false;
Expand All @@ -230,7 +230,7 @@ export function mountStatelessComponentCallbacks(ref, dom, lifecycle) {
}
}

export function mountRef(dom, value, lifecycle) {
export function mountRef(dom, value, lifecycle: Lifecycle) {
if (isFunction(value)) {
lifecycle.fastUnmount = false;
lifecycle.addListener(() => value(dom));
Expand Down
18 changes: 9 additions & 9 deletions src/DOM/patching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { componentToDOMNodeMap, findDOMNodeEnabled } from './rendering';
import processElement from './wrappers/processElement';
import { unmount } from './unmounting';

export function patch(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG: boolean, isRecycling: boolean) {
export function patch(lastVNode, nextVNode, parentDom, lifecycle: Lifecycle, context, isSVG: boolean, isRecycling: boolean) {
if (lastVNode !== nextVNode) {
const lastFlags = lastVNode.flags;
const nextFlags = nextVNode.flags;
Expand Down Expand Up @@ -140,7 +140,7 @@ export function patch(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG
}
}

function unmountChildren(children, dom, lifecycle, isRecycling) {
function unmountChildren(children, dom, lifecycle: Lifecycle, isRecycling: boolean) {
if (isVNode(children)) {
unmount(children, dom, lifecycle, true, false, isRecycling);
} else if (isArray(children)) {
Expand Down Expand Up @@ -200,7 +200,7 @@ export function patchElement(lastVNode: VNode, nextVNode: VNode, parentDom: Node
}
}

function patchChildren(lastFlags, nextFlags, lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling) {
function patchChildren(lastFlags: VNodeFlags, nextFlags: VNodeFlags, lastChildren, nextChildren, dom, lifecycle: Lifecycle, context, isSVG: boolean, isRecycling: boolean) {
let patchArray = false;
let patchKeyed = false;

Expand Down Expand Up @@ -263,7 +263,7 @@ function patchChildren(lastFlags, nextFlags, lastChildren, nextChildren, dom, li
}
}

export function patchComponent(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG, isClass, isRecycling: boolean) {
export function patchComponent(lastVNode, nextVNode, parentDom, lifecycle: Lifecycle, context, isSVG: boolean, isClass: number, isRecycling: boolean) {
const lastType = lastVNode.type;
const nextType = nextVNode.type;
const nextProps = nextVNode.props || EMPTY_OBJ;
Expand Down Expand Up @@ -362,7 +362,7 @@ export function patchComponent(lastVNode, nextVNode, parentDom, lifecycle, conte

lifecycle.fastUnmount = subLifecycle.fastUnmount;
patch(lastInput, nextInput, parentDom, lifecycle, childContext, isSVG, isRecycling);
subLifecycle.fastUnmount = lifecycle.unmount;
subLifecycle.fastUnmount = lifecycle.fastUnmount;
lifecycle.fastUnmount = fastUnmount;
instance.componentDidUpdate(lastProps, lastState);
findDOMNodeEnabled && componentToDOMNodeMap.set(instance, nextInput.dom);
Expand Down Expand Up @@ -434,11 +434,11 @@ export function patchText(lastVNode: VNode, nextVNode: VNode) {
}
}

export function patchVoid(lastVNode, nextVNode) {
export function patchVoid(lastVNode: VNode, nextVNode: VNode) {
nextVNode.dom = lastVNode.dom;
}

export function patchNonKeyedChildren(lastChildren, nextChildren, dom, lifecycle, context, isSVG, isRecycling) {
export function patchNonKeyedChildren(lastChildren, nextChildren, dom, lifecycle: Lifecycle, context, isSVG: boolean, isRecycling: boolean) {
let lastChildrenLength = lastChildren.length;
let nextChildrenLength = nextChildren.length;
let commonLength = lastChildrenLength > nextChildrenLength ? nextChildrenLength : lastChildrenLength;
Expand Down Expand Up @@ -781,7 +781,7 @@ function lis_algorithm(a) {
return result;
}

export function patchProp(prop, lastValue, nextValue, dom, isSVG: boolean, lifecycle) {
export function patchProp(prop, lastValue, nextValue, dom, isSVG: boolean, lifecycle: Lifecycle) {
if (skipProps[prop]) {
return;
}
Expand Down Expand Up @@ -879,7 +879,7 @@ export function patchEvent(name, lastValue, nextValue, dom, lifecycle) {
}
}

function patchProps(lastProps, nextProps, dom, lifecycle, context, isSVG) {
function patchProps(lastProps, nextProps, dom, lifecycle: Lifecycle, context, isSVG: boolean) {
lastProps = lastProps || EMPTY_OBJ;
nextProps = nextProps || EMPTY_OBJ;

Expand Down
5 changes: 3 additions & 2 deletions src/DOM/recycling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
patchComponent,
patchElement,
} from './patching';
import Lifecycle from "./lifecycle";

export let recyclingEnabled = true;
let componentPools = new Map<Function | null, Pools>();
Expand All @@ -27,7 +28,7 @@ export function enableRecycling() {
recyclingEnabled = true;
}

export function recycleElement(vNode, lifecycle, context, isSVG) {
export function recycleElement(vNode, lifecycle: Lifecycle, context, isSVG) {
const tag = vNode.type;
const key = vNode.key;
let pools: Pools = elementPools.get(tag);
Expand Down Expand Up @@ -72,7 +73,7 @@ export function poolElement(vNode) {
}
}

export function recycleComponent(vNode: VNode, lifecycle, context, isSVG) {
export function recycleComponent(vNode: VNode, lifecycle: Lifecycle, context, isSVG) {
const type = vNode.type as Function;
const key = vNode.key;
let pools: Pools = componentPools.get(type);
Expand Down
9 changes: 5 additions & 4 deletions src/DOM/unmounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import {
import { VNodeFlags } from '../core/shapes';
import { componentToDOMNodeMap, findDOMNodeEnabled } from './rendering';
import { removeChild } from './utils';
import Lifecycle from "./lifecycle";

export function unmount(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling) {
export function unmount(vNode, parentDom, lifecycle: Lifecycle, canRecycle, shallowUnmount, isRecycling) {
const flags = vNode.flags;

if (flags & VNodeFlags.Component) {
Expand All @@ -38,7 +39,7 @@ function unmountVoidOrText(vNode, parentDom) {
}
}

export function unmountComponent(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling) {
export function unmountComponent(vNode, parentDom, lifecycle: Lifecycle, canRecycle, shallowUnmount, isRecycling) {
const instance = vNode.children;
const flags = vNode.flags;
const isStatefulComponent = flags & VNodeFlags.ComponentClass;
Expand Down Expand Up @@ -87,7 +88,7 @@ export function unmountComponent(vNode, parentDom, lifecycle, canRecycle, shallo
}
}

export function unmountElement(vNode, parentDom, lifecycle, canRecycle, shallowUnmount, isRecycling) {
export function unmountElement(vNode, parentDom, lifecycle: Lifecycle, canRecycle, shallowUnmount, isRecycling) {
const dom = vNode.dom;
const ref = vNode.ref;
const events = vNode.events;
Expand Down Expand Up @@ -117,7 +118,7 @@ export function unmountElement(vNode, parentDom, lifecycle, canRecycle, shallowU
}
}

function unmountChildren(children, lifecycle, shallowUnmount, isRecycling) {
function unmountChildren(children, lifecycle: Lifecycle, shallowUnmount, isRecycling) {
if (isArray(children)) {
for (let i = 0; i < children.length; i++) {
const child = children[i];
Expand Down
15 changes: 8 additions & 7 deletions src/DOM/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
VNodeFlags,
createVoidVNode,
createVoidVNode, VNode,
} from '../core/shapes';
import {
isArray,
Expand All @@ -19,8 +19,9 @@ import { svgNS } from './constants';
import {
unmount,
} from './unmounting';
import Lifecycle from "./lifecycle";

export function createStatefulComponentInstance(vNode, Component, props, context, isSVG, devToolsStatus) {
export function createStatefulComponentInstance(vNode: VNode, Component, props, context, isSVG: boolean, devToolsStatus) {
if (isUndefined(context)) {
context = {};
}
Expand Down Expand Up @@ -73,11 +74,11 @@ export function createStatefulComponentInstance(vNode, Component, props, context
instance._lastInput = input;
return instance;
}
export function replaceLastChildAndUnmount(lastInput, nextInput, parentDom, lifecycle, context, isSVG, isRecycling) {
export function replaceLastChildAndUnmount(lastInput, nextInput, parentDom, lifecycle: Lifecycle, context, isSVG, isRecycling) {
replaceVNode(parentDom, mount(nextInput, null, lifecycle, context, isSVG), lastInput, lifecycle, isRecycling);
}

export function replaceVNode(parentDom, dom, vNode, lifecycle, isRecycling) {
export function replaceVNode(parentDom, dom, vNode, lifecycle: Lifecycle, isRecycling) {
let shallowUnmount = false;
// we cannot cache nodeType here as vNode might be re-assigned below
if (vNode.flags & VNodeFlags.Component) {
Expand Down Expand Up @@ -148,7 +149,7 @@ export function documentCreateElement(tag, isSVG) {
}
}

export function replaceWithNewNode(lastNode, nextNode, parentDom, lifecycle, context, isSVG, isRecycling) {
export function replaceWithNewNode(lastNode, nextNode, parentDom, lifecycle: Lifecycle, context, isSVG, isRecycling) {
unmount(lastNode, null, lifecycle, false, false, isRecycling);
const dom = mount(nextNode, null, lifecycle, context, isSVG);

Expand All @@ -167,14 +168,14 @@ export function removeChild(parentDom, dom) {
parentDom.removeChild(dom);
}

export function removeAllChildren(dom, children, lifecycle, shallowUnmount, isRecycling) {
export function removeAllChildren(dom, children, lifecycle: Lifecycle, shallowUnmount, isRecycling) {
dom.textContent = '';
if (!lifecycle.fastUnmount) {
removeChildren(null, children, lifecycle, shallowUnmount, isRecycling);
}
}

export function removeChildren(dom, children, lifecycle, shallowUnmount, isRecycling) {
export function removeChildren(dom, children, lifecycle: Lifecycle, shallowUnmount, isRecycling) {
for (let i = 0; i < children.length; i++) {
const child = children[i];

Expand Down

0 comments on commit e072ab9

Please sign in to comment.