@@ -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-
465452var flattenChildren = function flattenChildren ( list , iteratee ) {
466453 return flat ( list , iteratee , [ ] ) ;
467454} ;
@@ -497,34 +484,19 @@ var mapValue = function mapValue(obj, iteratee) {
497484
498485var 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-
528500function 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+
870850Velem . 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 }
0 commit comments