Skip to content

Commit 3674d63

Browse files
committed
clean part1
1 parent 5d57cdb commit 3674d63

12 files changed

Lines changed: 190 additions & 367 deletions

File tree

dist/react-lite.common.js

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,6 @@ var pipe = function pipe(fn1, fn2) {
449449
};
450450
};
451451

452-
// export let flattenChildren = (list, iteratee, record) => {
453-
// record = record || { index: 0 }
454-
// for (let i = 0, len = list.length; i < len; i++) {
455-
// let item = list[i]
456-
// if (isArr(item)) {
457-
// flattenChildren(item, iteratee, record)
458-
// } else if (!isUndefined(item) && !isBln(item)) {
459-
// iteratee(item, record.index)
460-
// record.index += 1
461-
// }
462-
// }
463-
// }
464-
465452
var flattenChildren = function flattenChildren(list, iteratee) {
466453
return flat(list, iteratee, []);
467454
};
@@ -497,34 +484,19 @@ var mapValue = function mapValue(obj, iteratee) {
497484

498485
var mapKey = function mapKey(oldObj, newObj, iteratee) {
499486
var keyMap = {};
500-
var key = undefined;
501-
for (key in oldObj) {
487+
for (var key in oldObj) {
502488
if (oldObj.hasOwnProperty(key)) {
503489
keyMap[key] = true;
504490
iteratee(key);
505491
}
506492
}
507-
for (key in newObj) {
493+
for (var key in newObj) {
508494
if (newObj.hasOwnProperty(key) && keyMap[key] !== true) {
509495
iteratee(key);
510496
}
511497
}
512498
};
513499

514-
// export let extend = function(target) {
515-
// for (let i = 1, len = arguments.length; i < len; i++) {
516-
// let source = arguments[i]
517-
// if (source != null) {
518-
// for (let key in source) {
519-
// if (source.hasOwnProperty(key) && !isUndefined(source[key])) {
520-
// target[key] = source[key]
521-
// }
522-
// }
523-
// }
524-
// }
525-
// return target
526-
// }
527-
528500
function extend(to, from) {
529501
if (!from) {
530502
return to;
@@ -867,6 +839,14 @@ function Velem(type, props) {
867839
this.props = props;
868840
}
869841

842+
var getFlattenChildren = function getFlattenChildren(children, iteratee) {
843+
if (isArr(children)) {
844+
return flattenChildren(children, iteratee);
845+
} else if (!isUndefined(children) && !isBln(children)) {
846+
return [iteratee(children, 0)];
847+
}
848+
};
849+
870850
Velem.prototype = new Vtree({
871851
vtype: VNODE_TYPE.ELEMENT,
872852
initTree: function initTree(parentNode, parentContext) {
@@ -879,20 +859,12 @@ Velem.prototype = new Vtree({
879859
} else {
880860
node = document.createElement(type);
881861
}
882-
var children = props.children;
883-
884862
var initChildren = function initChildren(vchild) {
885863
vchild = getVnode(vchild);
886864
vchild.initTree(node, parentContext);
887865
return vchild;
888866
};
889-
if (isArr(children)) {
890-
props.children = flattenChildren(children, initChildren);
891-
} else if (!isUndefined(children) && !isBln(children)) {
892-
props.children = [initChildren(children)];
893-
} else {
894-
props.children = undefined;
895-
}
867+
props.children = getFlattenChildren(props.children, initChildren);
896868
setProps(node, props);
897869
appendNode(parentNode, node);
898870
this.attachRef(node);
@@ -920,7 +892,6 @@ Velem.prototype = new Vtree({
920892
var newProps = newVelem.props;
921893
var oldHtml = props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html;
922894
var children = props.children;
923-
var newChildren = newProps.children;
924895
if (oldHtml == null && children) {
925896
var childNodes = node.childNodes;
926897
var initNewChildren = function initNewChildren(newVchild, index) {
@@ -933,13 +904,7 @@ Velem.prototype = new Vtree({
933904
}
934905
return newVchild;
935906
};
936-
if (isArr(newChildren)) {
937-
newProps.children = flattenChildren(newChildren, initNewChildren);
938-
} else if (!isUndefined(newChildren) && !isBln(newChildren)) {
939-
newProps.children = [initNewChildren(newChildren, 0)];
940-
} else {
941-
newProps.children = undefined;
942-
}
907+
newProps.children = getFlattenChildren(newProps.children, initNewChildren);
943908
var childrenLen = children.length;
944909
var newChildrenLen = newProps.children && newProps.children.length || 0;
945910
// destroy old children not in the newChildren
@@ -955,13 +920,7 @@ Velem.prototype = new Vtree({
955920
newVchild.initTree(node, parentContext);
956921
return newVchild;
957922
};
958-
if (isArr(newChildren)) {
959-
newProps.children = flattenChildren(newChildren, _initNewChildren);
960-
} else if (!isUndefined(newChildren) && !isBln(newChildren)) {
961-
newProps.children = [_initNewChildren(newChildren)];
962-
} else {
963-
newProps.children = undefined;
964-
}
923+
newProps.children = getFlattenChildren(newProps.children, _initNewChildren);
965924
}
966925
this.updateRef(newVelem, node);
967926
return node;
@@ -1268,10 +1227,10 @@ Updater.prototype = {
12681227
var instance = this.instance;
12691228

12701229
if (pendingCallbacks.length > 0) {
1230+
this.pendingCallbacks = [];
12711231
eachItem(pendingCallbacks, function (callback) {
12721232
return callback.call(instance);
12731233
});
1274-
pendingCallbacks.length = 0;
12751234
}
12761235
},
12771236
addCallback: function addCallback(callback) {
@@ -1476,7 +1435,8 @@ var renderTreeIntoContainer = function renderTreeIntoContainer(vtree, container,
14761435
var id = container[COMPONENT_ID] || (container[COMPONENT_ID] = getUid());
14771436
var argsCache = pendingRendering[id];
14781437

1479-
// component lify cycle method maybe call root rendering, should bundle them and render by only one time
1438+
// component lify cycle method maybe call root rendering
1439+
// should bundle them and render by only one time
14801440
if (argsCache) {
14811441
if (argsCache === TRUE) {
14821442
pendingRendering[id] = argsCache = [vtree, callback, parentContext];
@@ -1514,7 +1474,7 @@ var renderTreeIntoContainer = function renderTreeIntoContainer(vtree, container,
15141474

15151475
updateQueue.batchUpdate();
15161476

1517-
if (isFn(callback)) {
1477+
if (callback) {
15181478
callback.call(result);
15191479
}
15201480

@@ -1626,7 +1586,7 @@ var map = function map(children, iteratee, context) {
16261586
data.isEqual = data.child === child;
16271587
var key = data.key = getKey(child, index);
16281588
if (keyMap.hasOwnProperty(key)) {
1629-
keyMap[key] = keyMap[key] + 1;
1589+
keyMap[key] += 1;
16301590
} else {
16311591
keyMap[key] = 0;
16321592
}

dist/react-lite.js

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -453,19 +453,6 @@
453453
};
454454
};
455455

456-
// export let flattenChildren = (list, iteratee, record) => {
457-
// record = record || { index: 0 }
458-
// for (let i = 0, len = list.length; i < len; i++) {
459-
// let item = list[i]
460-
// if (isArr(item)) {
461-
// flattenChildren(item, iteratee, record)
462-
// } else if (!isUndefined(item) && !isBln(item)) {
463-
// iteratee(item, record.index)
464-
// record.index += 1
465-
// }
466-
// }
467-
// }
468-
469456
var flattenChildren = function flattenChildren(list, iteratee) {
470457
return flat(list, iteratee, []);
471458
};
@@ -501,34 +488,19 @@
501488

502489
var mapKey = function mapKey(oldObj, newObj, iteratee) {
503490
var keyMap = {};
504-
var key = undefined;
505-
for (key in oldObj) {
491+
for (var key in oldObj) {
506492
if (oldObj.hasOwnProperty(key)) {
507493
keyMap[key] = true;
508494
iteratee(key);
509495
}
510496
}
511-
for (key in newObj) {
497+
for (var key in newObj) {
512498
if (newObj.hasOwnProperty(key) && keyMap[key] !== true) {
513499
iteratee(key);
514500
}
515501
}
516502
};
517503

518-
// export let extend = function(target) {
519-
// for (let i = 1, len = arguments.length; i < len; i++) {
520-
// let source = arguments[i]
521-
// if (source != null) {
522-
// for (let key in source) {
523-
// if (source.hasOwnProperty(key) && !isUndefined(source[key])) {
524-
// target[key] = source[key]
525-
// }
526-
// }
527-
// }
528-
// }
529-
// return target
530-
// }
531-
532504
function extend(to, from) {
533505
if (!from) {
534506
return to;
@@ -871,6 +843,14 @@
871843
this.props = props;
872844
}
873845

846+
var getFlattenChildren = function getFlattenChildren(children, iteratee) {
847+
if (isArr(children)) {
848+
return flattenChildren(children, iteratee);
849+
} else if (!isUndefined(children) && !isBln(children)) {
850+
return [iteratee(children, 0)];
851+
}
852+
};
853+
874854
Velem.prototype = new Vtree({
875855
vtype: VNODE_TYPE.ELEMENT,
876856
initTree: function initTree(parentNode, parentContext) {
@@ -883,20 +863,12 @@
883863
} else {
884864
node = document.createElement(type);
885865
}
886-
var children = props.children;
887-
888866
var initChildren = function initChildren(vchild) {
889867
vchild = getVnode(vchild);
890868
vchild.initTree(node, parentContext);
891869
return vchild;
892870
};
893-
if (isArr(children)) {
894-
props.children = flattenChildren(children, initChildren);
895-
} else if (!isUndefined(children) && !isBln(children)) {
896-
props.children = [initChildren(children)];
897-
} else {
898-
props.children = undefined;
899-
}
871+
props.children = getFlattenChildren(props.children, initChildren);
900872
setProps(node, props);
901873
appendNode(parentNode, node);
902874
this.attachRef(node);
@@ -924,7 +896,6 @@
924896
var newProps = newVelem.props;
925897
var oldHtml = props.dangerouslySetInnerHTML && props.dangerouslySetInnerHTML.__html;
926898
var children = props.children;
927-
var newChildren = newProps.children;
928899
if (oldHtml == null && children) {
929900
var childNodes = node.childNodes;
930901
var initNewChildren = function initNewChildren(newVchild, index) {
@@ -937,13 +908,7 @@
937908
}
938909
return newVchild;
939910
};
940-
if (isArr(newChildren)) {
941-
newProps.children = flattenChildren(newChildren, initNewChildren);
942-
} else if (!isUndefined(newChildren) && !isBln(newChildren)) {
943-
newProps.children = [initNewChildren(newChildren, 0)];
944-
} else {
945-
newProps.children = undefined;
946-
}
911+
newProps.children = getFlattenChildren(newProps.children, initNewChildren);
947912
var childrenLen = children.length;
948913
var newChildrenLen = newProps.children && newProps.children.length || 0;
949914
// destroy old children not in the newChildren
@@ -959,13 +924,7 @@
959924
newVchild.initTree(node, parentContext);
960925
return newVchild;
961926
};
962-
if (isArr(newChildren)) {
963-
newProps.children = flattenChildren(newChildren, _initNewChildren);
964-
} else if (!isUndefined(newChildren) && !isBln(newChildren)) {
965-
newProps.children = [_initNewChildren(newChildren)];
966-
} else {
967-
newProps.children = undefined;
968-
}
927+
newProps.children = getFlattenChildren(newProps.children, _initNewChildren);
969928
}
970929
this.updateRef(newVelem, node);
971930
return node;
@@ -1272,10 +1231,10 @@
12721231
var instance = this.instance;
12731232

12741233
if (pendingCallbacks.length > 0) {
1234+
this.pendingCallbacks = [];
12751235
eachItem(pendingCallbacks, function (callback) {
12761236
return callback.call(instance);
12771237
});
1278-
pendingCallbacks.length = 0;
12791238
}
12801239
},
12811240
addCallback: function addCallback(callback) {
@@ -1480,7 +1439,8 @@
14801439
var id = container[COMPONENT_ID] || (container[COMPONENT_ID] = getUid());
14811440
var argsCache = pendingRendering[id];
14821441

1483-
// component lify cycle method maybe call root rendering, should bundle them and render by only one time
1442+
// component lify cycle method maybe call root rendering
1443+
// should bundle them and render by only one time
14841444
if (argsCache) {
14851445
if (argsCache === TRUE) {
14861446
pendingRendering[id] = argsCache = [vtree, callback, parentContext];
@@ -1518,7 +1478,7 @@
15181478

15191479
updateQueue.batchUpdate();
15201480

1521-
if (isFn(callback)) {
1481+
if (callback) {
15221482
callback.call(result);
15231483
}
15241484

@@ -1630,7 +1590,7 @@
16301590
data.isEqual = data.child === child;
16311591
var key = data.key = getKey(child, index);
16321592
if (keyMap.hasOwnProperty(key)) {
1633-
keyMap[key] = keyMap[key] + 1;
1593+
keyMap[key] += 1;
16341594
} else {
16351595
keyMap[key] = 0;
16361596
}

dist/react-lite.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-lite.min.js.gz

-24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)