@@ -20,7 +20,7 @@ import {
20
20
} from './utils' ;
21
21
import AnimTypes from './animTypes' ;
22
22
23
- import { IObject , IProps , IKeys , IQueueType } from './type' ;
23
+ import type { IObject , IProps , IKeys , IQueueType } from './type' ;
24
24
25
25
const noop = ( ) => { } ;
26
26
@@ -117,8 +117,8 @@ export default forwardRef((props: IProps, ref: any) => {
117
117
return getTweenSingleConfig ( data , num , enterOrLeave ) ;
118
118
} ;
119
119
120
- const getTweenType = ( type : IQueueType , num : number ) => {
121
- const data = AnimTypes [ type ] ;
120
+ const getTweenType = ( $ type : IQueueType , num : number ) => {
121
+ const data = AnimTypes [ $ type] ;
122
122
return getTweenAnimConfig ( data , num ) ;
123
123
} ;
124
124
@@ -136,13 +136,13 @@ export default forwardRef((props: IProps, ref: any) => {
136
136
)
137
137
: getTweenType ( transformArguments ( type , key , i ) [ enterOrLeave ] , startOrEnd ) ;
138
138
139
- const getTweenData = ( key : string | number , i : number , type : string ) => {
140
- const enterOrLeave = type === 'enter' ? 0 : 1 ;
141
- const start = type === 'enter' ? 1 : 0 ;
142
- const end = type === 'enter' ? 0 : 1 ;
139
+ const getTweenData = ( key : string | number , i : number , $ type : string ) => {
140
+ const enterOrLeave = $ type === 'enter' ? 0 : 1 ;
141
+ const start = $ type === 'enter' ? 1 : 0 ;
142
+ const end = $ type === 'enter' ? 0 : 1 ;
143
143
const animate = getAnimData ( key , i , enterOrLeave , end ) ;
144
144
const startAnim =
145
- type === 'enter' && ( forcedReplay || ! childrenShow . current [ key ] )
145
+ $ type === 'enter' && ( forcedReplay || ! childrenShow . current [ key ] )
146
146
? getAnimData ( key , i , enterOrLeave , start )
147
147
: null ;
148
148
let $ease = transformArguments ( ease , key , i ) [ enterOrLeave ] ;
@@ -231,28 +231,32 @@ export default forwardRef((props: IProps, ref: any) => {
231
231
} , $interval * i + $delay ) ;
232
232
} ;
233
233
234
- const performLeave = ( key : string | number , i : number ) => {
234
+ const performLeave = ( key : string | number ) => {
235
235
Ticker . clear ( placeholderTimeoutIds . current [ key ] ) ;
236
236
delete placeholderTimeoutIds . current [ key ] ;
237
237
} ;
238
238
239
239
const getTweenOneEnterOrLeave = (
240
240
key : string | number ,
241
241
i : number ,
242
- delay : number ,
243
- type : string ,
242
+ $ delay : number ,
243
+ $ type : string ,
244
244
) => {
245
- const animateData = getTweenData ( key , i , type ) ;
246
- const onStart = ( type === 'enter' ? enterBegin : leaveBegin ) . bind ( this , key ) ;
247
- const onComplete = ( type === 'enter' ? enterComplete : leaveComplete ) . bind ( this , key ) ;
245
+ const animateData = getTweenData ( key , i , $type ) ;
246
+ const onStart = ( e : any ) => {
247
+ ( $type === 'enter' ? enterBegin : leaveBegin ) ( key , e ) ;
248
+ } ;
249
+ const onComplete = ( e : any ) => {
250
+ ( $type === 'enter' ? enterComplete : leaveComplete ) ( key , e ) ;
251
+ } ;
248
252
if ( Array . isArray ( animateData . animate ) ) {
249
253
const length = animateData . animate . length - 1 ;
250
254
const animation = animateData . animate . map ( ( item , ii ) => {
251
255
return {
252
256
...item ,
253
257
startAt : animateData . startAnim ? animateData . startAnim [ ii ] : undefined ,
254
258
duration : animateData . duration / length ,
255
- delay : ! ii && type === 'leave' ? delay : 0 ,
259
+ delay : ! ii && $ type === 'leave' ? $ delay : 0 ,
256
260
onStart : ! ii ? onStart : undefined ,
257
261
onComplete : ii === length ? onComplete : undefined ,
258
262
} ;
@@ -266,7 +270,7 @@ export default forwardRef((props: IProps, ref: any) => {
266
270
duration : animateData . duration ,
267
271
onStart,
268
272
onComplete,
269
- delay,
273
+ delay : $delay ,
270
274
} ;
271
275
} ;
272
276
useEffect (
@@ -283,17 +287,17 @@ export default forwardRef((props: IProps, ref: any) => {
283
287
) ;
284
288
useEffect ( ( ) => {
285
289
const nextChildren = toArrayChildren ( props . children ) . filter ( ( c ) => c ) ;
286
- let currentChildren = originalChildren . current . filter ( ( item ) => item ) ;
290
+ const currentChildren = originalChildren . current . filter ( ( item ) => item ) ;
287
291
const newChildren = mergeChildren ( currentChildren , nextChildren ) ;
288
292
const $keysToEnter : IKeys = [ ] ;
289
293
const $keysToLeave : IKeys = [ ] ;
290
294
if ( ! appear && ! oneEnterBool . current ) {
291
295
const $childShow : IObject = { } ;
292
- newChildren . forEach ( ( child : any ) => {
293
- if ( ! child || ! child . key ) {
296
+ newChildren . forEach ( ( c : any ) => {
297
+ if ( ! c || ! c . key ) {
294
298
return ;
295
299
}
296
- $childShow [ child . key ] = true ;
300
+ $childShow [ c . key ] = true ;
297
301
} ) ;
298
302
originalChildren . current = newChildren ;
299
303
childrenShow . current = { ...$childShow } ;
@@ -303,7 +307,7 @@ export default forwardRef((props: IProps, ref: any) => {
303
307
if ( ! c ) {
304
308
return ;
305
309
}
306
- const key = c . key ;
310
+ const { key } = c ;
307
311
const hasNext = findChildInChildrenByKey ( nextChildren , key ) ;
308
312
if ( ! hasNext && key ) {
309
313
$keysToLeave . push ( key ) ;
@@ -359,13 +363,13 @@ export default forwardRef((props: IProps, ref: any) => {
359
363
return ;
360
364
}
361
365
let animation ;
362
- let index = keysToLeave . current . indexOf ( key ) ; //children.findIndex(c => c.key === key);
366
+ let index = keysToLeave . current . indexOf ( key ) ; // children.findIndex(c => c.key === key);
363
367
const $interval = transformArguments ( interval , key , index ) ;
364
- let $delay = transformArguments ( delay , key , index ) ;
368
+ const $delay = transformArguments ( delay , key , index ) ;
365
369
366
370
// 处理出场
367
371
if ( index >= 0 ) {
368
- if ( recordAnimKeys . current [ key ] == 'leave' ) {
372
+ if ( recordAnimKeys . current [ key ] === 'leave' ) {
369
373
return ;
370
374
}
371
375
@@ -402,7 +406,6 @@ export default forwardRef((props: IProps, ref: any) => {
402
406
recordTweenKeys . current [ key ] = TweenOne ( dom , {
403
407
animation,
404
408
} ) ;
405
-
406
409
} ) ;
407
410
}
408
411
} , [ childShow , child ] ) ;
0 commit comments