@@ -130,7 +130,7 @@ const getParentNode = (fiber: IFiber): HTMLElement | undefined => {
130130const diffKids = ( fiber : any , children : FreNode ) : void => {
131131 let aCh = fiber . kids || [ ] ,
132132 bCh = ( fiber . kids = arrayfy ( children ) as any )
133- const actions = idiff ( aCh , bCh )
133+ const actions = diff ( aCh , bCh )
134134
135135 for ( let i = 0 , prev = null , len = bCh . length ; i < len ; i ++ ) {
136136
@@ -165,13 +165,11 @@ const side = (effects: IEffect[]): void => {
165165 effects . length = 0
166166}
167167
168- const diff = function ( opts ) {
168+ const diff = function ( a , b ) {
169169 var actions = [ ] ,
170170 aIdx = { } ,
171171 bIdx = { } ,
172- a = opts . old ,
173- b = opts . cur ,
174- key = opts . key ,
172+ key = v => v . key + v . type ,
175173 i , j ;
176174 for ( i = 0 ; i < a . length ; i ++ ) {
177175 aIdx [ key ( a [ i ] ) ] = i ;
@@ -184,27 +182,27 @@ const diff = function (opts) {
184182 if ( aElm === null ) {
185183 i ++ ;
186184 } else if ( b . length <= j ) {
187- opts . remove ( i )
185+ removeElement ( a [ i ] )
188186 i ++ ;
189187 } else if ( a . length <= i ) {
190- opts . add ( bElm , i )
188+ actions . push ( { op : TAG . INSERT , elm : bElm , before : a [ i ] } )
191189 j ++ ;
192190 } else if ( key ( aElm ) === key ( bElm ) ) {
193191 clone ( aElm , bElm )
194- opts . update ( aElm , bElm )
192+ actions . push ( { op : TAG . UPDATE } )
195193 i ++ ; j ++ ;
196194 } else {
197195 var curElmInNew = bIdx [ key ( aElm ) ]
198196 var wantedElmInOld = aIdx [ key ( bElm ) ]
199197 if ( curElmInNew === undefined ) {
200- opts . remove ( i ) ;
198+ removeElement ( a [ i ] )
201199 i ++ ;
202200 } else if ( wantedElmInOld === undefined ) {
203- opts . add ( bElm , i )
201+ actions . push ( { op : TAG . INSERT , elm : bElm , before : a [ i ] } )
204202 j ++
205203 } else {
206204 clone ( a [ wantedElmInOld ] , bElm )
207- opts . move ( wantedElmInOld , i )
205+ actions . push ( { op : TAG . MOVE , elm : a [ wantedElmInOld ] , before : a [ i ] } )
208206 a [ wantedElmInOld ] = null
209207 j ++
210208 }
@@ -213,26 +211,6 @@ const diff = function (opts) {
213211 return actions
214212}
215213
216- var idiff = function ( a , b ) {
217- var actions = [ ] // 必须保持和 b 一致的顺序
218- var extr = ( v ) => v . key + v . type
219- var update = ( a , b ) => actions . push ( { op : TAG . UPDATE } )
220- var move = ( from , to ) => actions . push ( { op : TAG . MOVE , elm : a [ from ] , before : a [ to ] } )
221- var add = ( elm , i ) => actions . push ( { op : TAG . INSERT , elm : elm , before : a [ i ] } )
222- var remove = ( i ) => {
223- const fiber = a [ i ]
224- removeElement ( fiber )
225- }
226-
227- diff ( {
228- old : a ,
229- cur : b ,
230- key : extr ,
231- add, move, remove, update
232- } )
233- return actions
234- }
235-
236214export const getCurrentFiber = ( ) => currentFiber || null
237215export const isFn = ( x : any ) : x is Function => typeof x === 'function'
238216export const isStr = ( s : any ) : s is number | string =>
0 commit comments