Skip to content

Commit

Permalink
回滚
Browse files Browse the repository at this point in the history
  • Loading branch information
qitmac000408 authored and qitmac000408 committed Jun 2, 2017
1 parent 2cce990 commit f33339a
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 81 deletions.
63 changes: 36 additions & 27 deletions dist/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@
* @returns
*/
function createElement(type, configs) {
var props = {};
var key = null,
var props = {},
key = null,
ref = null,
pChildren = null,
//位于props中的children
Expand Down Expand Up @@ -368,26 +368,24 @@
};
// 如果是组件的虚拟DOM,如果它
/**
* 遍平化children,并合并相邻的简单数据类型
*
* @param {array} children
* @param {any} [ret=[]]
* @returns
*/
* 遍平化children,并合并相邻的简单数据类型
*
* @param {array} children
* @param {any} [ret=[]]
* @returns
*/

function flatChildren(children, ret, deep) {
ret = ret || [];
deep = deep || 0;
for (var i = children.length; i--;) {
//从后向前添加
var el = children[i];
if (el == null) {
el = '';
}
var type = typeof el === 'undefined' ? 'undefined' : _typeof(el);
if (el === '' || type === 'boolean') {
if (el === undefined || el === null || el === false || el === true) {
continue;
}
var type = typeof el === 'undefined' ? 'undefined' : _typeof(el);

if (/number|string/.test(type) || el.type === '#text') {
if (el === '' || el.text == '') {
continue;
Expand Down Expand Up @@ -523,6 +521,7 @@
instance._updateBatchNumber = options.updateBatchNumber + 1;
}
transaction.queueComponent(instance);

if (!transaction.isInTransation) {
options.updateBatchNumber++;
transaction.dequeue();
Expand Down Expand Up @@ -1585,21 +1584,18 @@
function alignVnodes(vnode, newVnode, node, parentContext) {
var newNode = node;
if (newVnode == null) {
// remove
disposeVnode(vnode, node);
node.parentNode.removeChild(node);
} else if (vnode.type !== newVnode.type || vnode.key !== newVnode.key) {

// replace
//replace
disposeVnode(vnode, node);
newNode = mountVnode(newVnode, parentContext);
node.parentNode.replaceChild(newNode, node);
} else if (vnode !== newVnode) {
// same type and same key -> update
newNode = updateVnode(vnode, newVnode, node, parentContext);
}
// else if (vnode._prevRendered) { newNode = updateVnode(vnode, newVnode,
// node, parentContext) }

return newNode;
}

Expand All @@ -1610,7 +1606,8 @@
_removeNodes.unshift(node);
}
if (!vtype) {
// vnode._hostNode = null vnode._hostParent = null
vnode._hostNode = null;
vnode._hostParent = null;
} else if (vtype === 1) {
// destroy element
disposeElement(vnode, node);
Expand Down Expand Up @@ -1756,13 +1753,21 @@
if (childrenLen === 0) {
if (newVchildrenLen > 0) {
for (var i = 0; i < newVchildrenLen; i++) {
patches.creates.push({ vnode: newVchildren[i], parentNode: node, parentContext: parentContext, index: i });
patches.creates.push({
vnode: newVchildren[i],
parentNode: node,
parentContext: parentContext,
index: i
});
}
}
return;
} else if (newVchildrenLen === 0) {
for (var _i = 0; _i < childrenLen; _i++) {
patches.removes.push({ vnode: children[_i], node: childNodes[_i] });
patches.removes.push({
vnode: children[_i],
node: childNodes[_i]
});
}
return;
}
Expand Down Expand Up @@ -1818,15 +1823,23 @@
}
}
if (shouldRemove) {
removes.push({ vnode: _vnode2, node: childNodes[_i3] });
removes.push({
vnode: _vnode2,
node: childNodes[_i3]
});
}
}

for (var _i4 = 0; _i4 < newVchildrenLen; _i4++) {
var item = updates[_i4];
if (!item) {

creates.push({ vnode: newVchildren[_i4], parentNode: node, parentContext: parentContext, index: _i4 });
creates.push({
vnode: newVchildren[_i4],
parentNode: node,
parentContext: parentContext,
index: _i4
});
} else if (item.vnode.vtype === 1) {
diffChildren(patches, item.vnode, item.newVnode, item.node, item.parentContext);
}
Expand Down Expand Up @@ -1880,10 +1893,6 @@
});

_removeNodes = [];
// data
// .node
// .parentNode
// .removeChild(data.node)
var node = data.node;
var nodeName = node.__n || (node.__n = toLowerCase(node.nodeName));
if (recyclables[nodeName] && recyclables[nodeName].length < 72) {
Expand Down
5 changes: 2 additions & 3 deletions src/createElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function flatChildren(children, ret, deep) {
deep = deep || 0
for (var i = children.length; i--;) { //从后向前添加
var el = children[i]
if (el === undefined || el === null || el === false || el === true) {
if (el === undefined || el === null || el === false || el === true) {
continue
}
var type = typeof el
Expand All @@ -144,8 +144,7 @@ function flatChildren(children, ret, deep) {
el) + ret[0].text
} else {
ret.unshift(el.type ?
el :
{
el : {
type: '#text',
text: String(el),
_deep: deep
Expand Down
Loading

0 comments on commit f33339a

Please sign in to comment.