Skip to content

Commit

Permalink
Small optimizations for renderComponent()
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Apr 19, 2016
1 parent a4ca187 commit 5604f3a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/vdom/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ export function renderComponent(component, opts) {
previousProps = component.prevProps || props,
previousState = component.prevState || state,
previousContext = component.prevContext || context,
isUpdate = component.base;
isUpdate = component.base,
initialBase = isUpdate || component.nextBase;

// if updating
if (isUpdate) {
component.props = previousProps;
component.state = previousState;
Expand All @@ -100,7 +102,7 @@ export function renderComponent(component, opts) {
component.context = context;
}

component.prevProps = component.prevState = component.prevContext = null;
component.prevProps = component.prevState = component.prevContext = component.nextBase = null;
component._dirty = false;

if (!skip) {
Expand Down Expand Up @@ -128,31 +130,33 @@ export function renderComponent(component, opts) {
inst = createComponent(childComponent, childProps, childContext);
inst._parentComponent = component;
component._component = inst;
if (component.base) deepHook(inst, 'componentWillMount');
if (isUpdate) deepHook(inst, 'componentWillMount');
setComponentProps(inst, childProps, NO_RENDER, childContext);
renderComponent(inst, DOM_RENDER);
if (component.base) deepHook(inst, 'componentDidMount');
if (isUpdate) deepHook(inst, 'componentDidMount');
}

base = inst.base;
}
else {
let cbase = component.base || component.nextBase;
let cbase = initialBase;

// destroy high order component link
toUnmount = component._component;
if (toUnmount) {
cbase = component._component = null;
}

if (component.base || (opts && opts.build)) {
if (initialBase || (opts && opts.build)) {
base = diff(cbase, rendered || EMPTY_BASE, childContext);
}
}

if (component.base && base!==component.base) {
let p = component.base.parentNode;
if (p && base!==p) p.replaceChild(base, component.base);
if (initialBase && base!==initialBase) {
let p = initialBase.parentNode;
if (p && base!==p) p.replaceChild(base, initialBase);
initialBase._component = null;
recollectNodeTree(initialBase);
}

if (toUnmount) {
Expand Down

0 comments on commit 5604f3a

Please sign in to comment.