@@ -49,9 +49,7 @@ export interface RenderType {
49
49
class Tween extends EventClass {
50
50
public id : number
51
51
public object : Object
52
- public _valuesStart : Object
53
- public _valuesFunc : Object
54
- public _valuesEnd : Object
52
+ public _valuesEnd : any
55
53
public _duration : number
56
54
public _easingFunction : Function
57
55
public _easingReverse : Function
@@ -69,7 +67,6 @@ class Tween extends EventClass {
69
67
public _isFinite : boolean
70
68
public _isPlaying : boolean
71
69
public _elapsed : number
72
- public isArr : boolean
73
70
private _onStartCallbackFired : boolean
74
71
private _rendered : boolean
75
72
private __render : RenderType
@@ -133,10 +130,7 @@ class Tween extends EventClass {
133
130
this . object = object
134
131
}
135
132
}
136
- const isArr = this . isArr = Array . isArray ( object )
137
- this . _valuesStart = isArr ? [ ] : { }
138
133
this . _valuesEnd = null
139
- this . _valuesFunc = { }
140
134
141
135
this . _duration = 1000
142
136
this . _easingFunction = defaultEasing
@@ -313,53 +307,33 @@ class Tween extends EventClass {
313
307
*/
314
308
public render ( ) {
315
309
if ( this . _rendered ) {
316
- return this
310
+ return this ;
317
311
}
318
-
319
- let {
320
- _valuesEnd,
321
- _valuesFunc,
322
- _valuesStart,
323
- object,
324
- Renderer,
325
- node,
326
- InitialValues
327
- } = this
328
-
312
+ let { _valuesEnd, object, Renderer, node, InitialValues, _easingFunction } = this ;
329
313
if ( node && InitialValues ) {
330
314
if ( ! object ) {
331
- object = this . object = NodeCache ( node , InitialValues ( node , _valuesEnd ) )
332
- } else if ( ! _valuesEnd ) {
333
- _valuesEnd = this . _valuesEnd = InitialValues ( node , object )
315
+ object = this . object = NodeCache ( node , InitialValues ( node , _valuesEnd ) ) ;
316
+ }
317
+ else if ( ! _valuesEnd ) {
318
+ _valuesEnd = this . _valuesEnd = InitialValues ( node , object ) ;
334
319
}
335
320
}
336
-
337
321
for ( const property in _valuesEnd ) {
338
- const start = object && object [ property ]
339
- const end = _valuesEnd [ property ]
340
-
322
+ const start = object && object [ property ] ;
323
+ const end = _valuesEnd [ property ] ;
341
324
if ( Plugins [ property ] ) {
342
- const plugin = Plugins [ property ] . prototype . update ? new Plugins [ property ] ( this , start , end , property , object ) : Plugins [ property ] ( this , start , end , property , object )
325
+ const plugin = Plugins [ property ] . prototype . update ? new Plugins [ property ] ( this , start , end , property , object ) : Plugins [ property ] ( this , start , end , property , object ) ;
343
326
if ( plugin ) {
344
- _valuesFunc [ property ] = plugin
327
+ _valuesEnd [ property ] = plugin ;
345
328
}
346
- continue
347
- }
348
-
349
- if ( ! object || object [ property ] === undefined ) {
350
- continue
351
- }
352
-
353
- if ( typeof end === 'number' && typeof start === 'number' ) {
354
- _valuesStart [ property ] = start
355
- _valuesEnd [ property ] = end
356
- } else {
357
- _valuesFunc [ property ] = InterTween ( start , end )
329
+ continue ;
358
330
}
359
331
}
360
332
333
+ this . _valuesEnd = InterTween ( object , _valuesEnd , null , _easingFunction )
334
+
361
335
if ( Renderer && this . node ) {
362
- this . __render = new Renderer ( this , object , _valuesEnd )
336
+ this . __render = new Renderer ( this , object , _valuesEnd ) ;
363
337
}
364
338
365
339
return this
@@ -491,22 +465,17 @@ class Tween extends EventClass {
491
465
*/
492
466
public reassignValues ( ) {
493
467
const {
494
- _valuesStart,
495
468
_valuesEnd,
496
- object,
497
- isArr
469
+ object
498
470
} = this
499
471
500
- let property : any
501
- for ( property in _valuesEnd ) {
502
- if ( isArr ) {
503
- property = parseInt ( property )
504
- }
472
+ const _valuesStart : any = _valuesEnd ( 0 )
473
+
474
+ for ( const property in _valuesStart ) {
505
475
506
476
const start = _valuesStart [ property ]
507
- const end = _valuesEnd [ property ]
508
477
509
- object [ property ] = typeof end === 'function' ? end ( 0 ) : start
478
+ object [ property ] = start
510
479
}
511
480
512
481
return this
@@ -520,7 +489,7 @@ class Tween extends EventClass {
520
489
* @memberof Tween
521
490
*/
522
491
public update ( time : number , preserve ?: boolean ) {
523
- const {
492
+ let {
524
493
_onStartCallbackFired,
525
494
_easingFunction,
526
495
_easingReverse,
@@ -531,19 +500,15 @@ class Tween extends EventClass {
531
500
_reversed,
532
501
_startTime,
533
502
_duration,
534
- _valuesStart,
535
503
_valuesEnd,
536
- _valuesFunc,
537
504
object,
538
505
_isFinite,
539
506
_isPlaying,
540
507
__render
541
508
} = this
542
509
543
- let elapsed
544
- let value
545
- let property
546
- let currentEasing
510
+ let elapsed : number
511
+ let currentEasing : Function
547
512
548
513
time = time !== undefined ? time : now ( )
549
514
@@ -555,6 +520,7 @@ class Tween extends EventClass {
555
520
if ( ! this . _rendered ) {
556
521
this . render ( )
557
522
this . _rendered = true
523
+ _valuesEnd = this . _valuesEnd
558
524
}
559
525
560
526
this . emit ( EVENT_START , object )
@@ -568,27 +534,11 @@ class Tween extends EventClass {
568
534
569
535
currentEasing = _reversed ? _easingReverse : _easingFunction
570
536
571
- if ( ! object ) {
537
+ if ( typeof _valuesEnd !== 'function' || ! object ) {
572
538
return true
573
539
}
574
540
575
- for ( property in _valuesEnd ) {
576
- value = currentEasing [ property ] ? currentEasing [ property ] ( elapsed ) : typeof currentEasing === 'function' ? currentEasing ( elapsed ) : defaultEasing ( elapsed )
577
-
578
- const start = _valuesStart [ property ]
579
- const end = _valuesEnd [ property ]
580
- const fnc = _valuesFunc [ property ]
581
-
582
- if ( fnc && fnc . update ) {
583
- fnc . update ( value , elapsed )
584
- } else if ( fnc ) {
585
- object [ property ] = fnc ( value )
586
- } else if ( typeof end === 'number' ) {
587
- object [ property ] = start + ( end - start ) * value
588
- } else {
589
- object [ property ] = end
590
- }
591
- }
541
+ _valuesEnd ( elapsed , elapsed , currentEasing )
592
542
593
543
if ( __render ) {
594
544
__render . update ( object , elapsed )
0 commit comments