Skip to content

Commit

Permalink
add a new option to control element comparison (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jun 10, 2018
1 parent 7e49a91 commit ad765ac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export default {
*/
//vnode(vnode) { }

/**
* Compares two Components
* @param {Component} component1 First Component to compare
* @param {Component} component2 Second Component to compare
* @returns Boolean, true if components are equal
*/
areComponentsEqual(component1, component2) {
// default implementation is 4x times faster than optional object property access
return component1 === component2;
}

/** Hook invoked after a component is mounted. */
// afterMount(component) { }

Expand Down
6 changes: 3 additions & 3 deletions src/vdom/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SYNC_RENDER, NO_RENDER, FORCE_RENDER, ASYNC_RENDER, ATTR_KEY } from '..
import options from '../options';
import { extend } from '../util';
import { enqueueRender } from '../render-queue';
import { getNodeProps } from './index';
import { areComponentsEqual, getNodeProps } from './index';
import { diff, mounts, diffLevel, flushMounts, recollectNodeTree, removeChildren } from './diff';
import { createComponent, collectComponent } from './component-recycler';
import { removeNode } from '../dom/index';
Expand Down Expand Up @@ -212,11 +212,11 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) {
let c = dom && dom._component,
originalComponent = c,
oldDom = dom,
isDirectOwner = c && dom._componentConstructor===vnode.nodeName,
isDirectOwner = c && areComponentsEqual(dom._componentConstructor, vnode.nodeName),
isOwner = isDirectOwner,
props = getNodeProps(vnode);
while (c && !isOwner && (c=c._parentComponent)) {
isOwner = c.constructor===vnode.nodeName;
isOwner = areComponentsEqual(c.constructor, vnode.nodeName);
}

if (c && isOwner && (!mountAll || c._component)) {
Expand Down
1 change: 0 additions & 1 deletion src/vdom/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function flushMounts() {
}
}


/**
* Apply differences in a given vnode (and it's deep children) to a real DOM Node.
* @param {Element} [dom=null] A DOM node to mutate into the shape of the `vnode`
Expand Down
13 changes: 12 additions & 1 deletion src/vdom/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { extend } from '../util';
import options from '../options';

/**
* Checks that two components are equal
* @param {Component} component1 First component to compare
* @param {Component} component2 Second component to compare
* @return {boolean}
* @private
*/
export function areComponentsEqual(component1, component2) {
return options.areComponentsEqual(component1, component2);
}

/**
* Check if two nodes are equivalent.
Expand All @@ -16,7 +27,7 @@ export function isSameNodeType(node, vnode, hydrating) {
if (typeof vnode.nodeName==='string') {
return !node._componentConstructor && isNamedNode(node, vnode.nodeName);
}
return hydrating || node._componentConstructor===vnode.nodeName;
return hydrating || areComponentsEqual(node._componentConstructor, vnode.nodeName);
}


Expand Down

0 comments on commit ad765ac

Please sign in to comment.