Skip to content

Commit

Permalink
interim commit of component recycler rip-out for @NekR
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Apr 23, 2017
1 parent 3911ccb commit 7cde363
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
15 changes: 1 addition & 14 deletions src/vdom/component-recycler.js
Expand Up @@ -9,15 +9,12 @@ const components = {};

/** Reclaim a component for later re-use by the recycler. */
export function collectComponent(component) {
let name = component.constructor.name;
(components[name] || (components[name] = [])).push(component);
}


/** Create a component. Normalizes differences between PFC's and classful Components. */
export function createComponent(Ctor, props, context) {
let list = components[Ctor.name],
inst;
let inst;

if (Ctor.prototype && Ctor.prototype.render) {
inst = new Ctor(props, context);
Expand All @@ -29,16 +26,6 @@ export function createComponent(Ctor, props, context) {
inst.render = doRender;
}


if (list) {
for (let i=list.length; i--; ) {
if (list[i].constructor===Ctor) {
inst.nextBase = list[i].nextBase;
list.splice(i, 1);
break;
}
}
}
return inst;
}

Expand Down
19 changes: 8 additions & 11 deletions src/vdom/component.js
Expand Up @@ -215,16 +215,11 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) {
}
else {
if (originalComponent && !isDirectOwner) {
unmountComponent(originalComponent);
dom = oldDom = null;
unmountComponent(originalComponent, false);
}

c = createComponent(vnode.nodeName, props, context);
if (dom && !c.nextBase) {
c.nextBase = dom;
// passing dom/oldDom as nextBase will recycle it if unused, so bypass recycling on L229:
oldDom = null;
}
c.nextBase = dom;
setComponentProps(c, props, SYNC_RENDER, context, mountAll);
dom = c.base;

Expand All @@ -243,7 +238,7 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) {
* @param {Component} component The Component instance to unmount
* @private
*/
export function unmountComponent(component) {
export function unmountComponent(component, remove) {
if (options.beforeUnmount) options.beforeUnmount(component);

let base = component.base;
Expand All @@ -257,15 +252,17 @@ export function unmountComponent(component) {
// recursively tear down & recollect high-order component children:
let inner = component._component;
if (inner) {
unmountComponent(inner);
unmountComponent(inner, remove);
}
else if (base) {
if (base[ATTR_KEY] && base[ATTR_KEY].ref) base[ATTR_KEY].ref(null);

component.nextBase = base;

removeNode(base);
collectComponent(component);
if (remove!==false) {
removeNode(base);
collectComponent(component);
}

removeChildren(base);
}
Expand Down
4 changes: 2 additions & 2 deletions src/vdom/diff.js
Expand Up @@ -249,14 +249,14 @@ export function recollectNodeTree(node, unmountOnly) {
let component = node._component;
if (component) {
// if node is owned by a Component, unmount that component (ends up recursing back here)
unmountComponent(component);
unmountComponent(component, !unmountOnly);
}
else {
// If the node's VNode had a ref function, invoke it with null here.
// (this is part of the React spec, and smart for unsetting references)
if (node[ATTR_KEY]!=null && node[ATTR_KEY].ref) node[ATTR_KEY].ref(null);

if (unmountOnly===false || node[ATTR_KEY]==null) {
if (unmountOnly===false) {
removeNode(node);
}

Expand Down

0 comments on commit 7cde363

Please sign in to comment.