Skip to content

Commit

Permalink
Optimize renderFunctionalComponent better
Browse files Browse the repository at this point in the history
Oops

Oops
  • Loading branch information
trueadm committed Jun 2, 2020
1 parent 549bae9 commit 1af165f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
12 changes: 4 additions & 8 deletions packages/inferno-hydrate/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {isFunction, isInvalid, isNull, isNullOrUndef, throwError, warning} from 'inferno-shared';
import {ChildFlags, VNodeFlags} from 'inferno-vnode-flags';
import {_CI, _HI, _M, _MCCC, _ME, _MFCC, _MP, _MR, EMPTY_OBJ, render, VNode} from 'inferno';
import { isFunction, isInvalid, isNull, isNullOrUndef, throwError, warning } from 'inferno-shared';
import { ChildFlags, VNodeFlags } from 'inferno-vnode-flags';
import { _CI, _HI, _M, _MCCC, _ME, _MFCC, _MP, _MR, EMPTY_OBJ, render, VNode, _RFC as renderFunctionalComponent } from 'inferno';

function isSameInnerHTML(dom: Element, innerHTML: string): boolean {
const tempdom = document.createElement('i');
Expand Down Expand Up @@ -38,10 +38,6 @@ function isSamePropsInnerHTML(dom: Element, props): boolean {
return Boolean(props && props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html && isSameInnerHTML(dom, props.dangerouslySetInnerHTML.__html));
}

function renderFunctionalComponent(vNode: VNode, context, props) {
return vNode.flags & VNodeFlags.ForwardRef ? vNode.type.render(props, vNode.ref, context) : vNode.type(props, context);
}

function hydrateComponent(vNode: VNode, parentDOM: Element, dom: Element, context, isSVG: boolean, isClass: boolean, lifecycle: Function[]) {
const type = vNode.type as Function;
const ref = vNode.ref;
Expand All @@ -55,7 +51,7 @@ function hydrateComponent(vNode: VNode, parentDOM: Element, dom: Element, contex
currentNode = hydrateVNode(input, parentDOM, dom, instance.$CX, isSVG, lifecycle);
_MCCC(ref, instance, lifecycle);
} else {
const input = _HI(renderFunctionalComponent(vNode, context, props));
const input = _HI(renderFunctionalComponent(vNode, context));
currentNode = hydrateVNode(input, parentDOM, dom, context, isSVG, lifecycle);
vNode.children = input;
_MFCC(vNode, lifecycle);
Expand Down
6 changes: 1 addition & 5 deletions packages/inferno/src/DOM/mounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createVoidVNode, directClone, normalizeRoot } from '../core/implementat
import { VNode } from '../core/types';
import { documentCreateElement, EMPTY_OBJ, findDOMfromVNode, insertOrAppend, safeCall1, setTextContent } from './utils/common';
import { mountProps } from './props';
import { createClassComponentInstance } from './utils/componentUtil';
import { createClassComponentInstance, renderFunctionalComponent } from './utils/componentUtil';
import { validateKeys } from '../core/validate';
import { mountRef } from '../core/refs';

Expand Down Expand Up @@ -142,10 +142,6 @@ export function mountClassComponent(vNode: VNode, parentDOM: Element | null, con
mountClassComponentCallbacks(vNode.ref, instance, lifecycle);
}

function renderFunctionalComponent(vNode: VNode, context) {
return vNode.flags & VNodeFlags.ForwardRef ? vNode.type.render(vNode.props || EMPTY_OBJ, vNode.ref, context) : vNode.type(vNode.props || EMPTY_OBJ, context);
}

export function mountFunctionalComponent(vNode: VNode, parentDOM: Element | null, context: Object, isSVG: boolean, nextNode: Element | null, lifecycle): void {
mount((vNode.children = normalizeRoot(renderFunctionalComponent(vNode, context))), parentDOM, context, isSVG, nextNode, lifecycle);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/inferno/src/DOM/patching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './utils/common';
import { isControlledFormElement, processElement } from './wrappers/processElement';
import { patchProp } from './props';
import { renderNewInput } from './utils/componentUtil';
import { renderNewInput, renderFunctionalComponent } from './utils/componentUtil';
import { validateKeys } from '../core/validate';
import { mountRef, unmountRef } from '../core/refs';

Expand Down Expand Up @@ -458,8 +458,7 @@ function patchFunctionalComponent(lastVNode, nextVNode, parentDOM, context, isSV
if (nextHooksDefined && isFunction(nextRef.onComponentWillUpdate)) {
nextRef.onComponentWillUpdate(lastProps, nextProps);
}
const type = nextVNode.type;
const nextInput = normalizeRoot(nextVNode.flags & VNodeFlags.ForwardRef ? type.render(nextProps, nextRef, context) : type(nextProps, context));
const nextInput = normalizeRoot(renderFunctionalComponent(nextVNode, context));

patch(lastInput, nextInput, parentDOM, context, isSVG, nextNode, lifecycle);
nextVNode.children = nextInput;
Expand Down
14 changes: 10 additions & 4 deletions packages/inferno/src/DOM/utils/componentUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {combineFrom, isFunction, isNull, warning} from 'inferno-shared';
import {createDerivedState, EMPTY_OBJ, getComponentName} from './common';
import {VNode} from './../../core/types';
import {normalizeRoot} from "../../core/implementation";
import { combineFrom, isFunction, isNull, warning } from 'inferno-shared';
import { createDerivedState, EMPTY_OBJ, getComponentName } from './common';
import { VNodeFlags } from 'inferno-vnode-flags';
import { VNode } from './../../core/types';
import { normalizeRoot } from "../../core/implementation";

function warnAboutOldLifecycles(component) {
const oldLifecycles: string[] = [];
Expand Down Expand Up @@ -95,3 +96,8 @@ export function createClassComponentInstance(vNode: VNode, Component, props, con

return instance;
}

export function renderFunctionalComponent(vNode: VNode, context) {
const props = vNode.props || EMPTY_OBJ;
return vNode.flags & VNodeFlags.ForwardRef ? vNode.type.render(props, vNode.ref, context) : vNode.type(props, context);
}
29 changes: 15 additions & 14 deletions packages/inferno/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './core/types';
import {warning} from 'inferno-shared';
import { warning } from 'inferno-shared';
import {
createComponentVNode,
createFragment,
Expand All @@ -11,27 +11,27 @@ import {
normalizeProps,
normalizeRoot
} from './core/implementation';
import {linkEvent} from './DOM/events/linkEvent';
import {__render, createRenderer, render} from './DOM/rendering';
import {EMPTY_OBJ, findDOMfromVNode, Fragment, options} from './DOM/utils/common';
import {Component, ComponentType, rerender} from './core/component';
import {mountProps} from './DOM/props';
import {createClassComponentInstance} from './DOM/utils/componentUtil';
import {mount, mountClassComponentCallbacks, mountElement, mountFunctionalComponentCallbacks} from './DOM/mounting';
import {createRef, forwardRef, mountRef} from './core/refs';
import { linkEvent } from './DOM/events/linkEvent';
import { __render, createRenderer, render } from './DOM/rendering';
import { EMPTY_OBJ, findDOMfromVNode, Fragment, options } from './DOM/utils/common';
import { Component, ComponentType, rerender } from './core/component';
import { mountProps } from './DOM/props';
import { createClassComponentInstance, renderFunctionalComponent } from './DOM/utils/componentUtil';
import { mount, mountClassComponentCallbacks, mountElement, mountFunctionalComponentCallbacks } from './DOM/mounting';
import { createRef, forwardRef, mountRef } from './core/refs';

if (process.env.NODE_ENV !== 'production') {
/* tslint:disable-next-line:no-empty */
const testFunc = function testFn() {};
const testFunc = function testFn() { };
/* tslint:disable-next-line*/
console.log('Inferno is in development mode.');

if (((testFunc as Function).name || testFunc.toString()).indexOf('testFn') === -1) {
warning(
"It looks like you're using a minified copy of the development build " +
'of Inferno. When deploying Inferno apps to production, make sure to use ' +
'the production build which skips development warnings and is faster. ' +
'See http://infernojs.org for more details.'
'of Inferno. When deploying Inferno apps to production, make sure to use ' +
'the production build which skips development warnings and is faster. ' +
'See http://infernojs.org for more details.'
);
}
}
Expand Down Expand Up @@ -69,5 +69,6 @@ export {
mountFunctionalComponentCallbacks as _MFCC,
mountRef as _MR,
mountProps as _MP,
__render
__render,
renderFunctionalComponent as _RFC,
};

0 comments on commit 1af165f

Please sign in to comment.