@@ -41,28 +41,30 @@ class Controller<DS extends object = any> {
41
41
42
42
getValues = ( ) => this . interpolations
43
43
44
- /** update(props)
45
- * This function filters input props and creates an array of tasks which are executed in .start()
46
- * Each task is allowed to carry a delay, which means it can execute asnychroneously */
47
- update ( args : UpdateProps < DS > ) {
44
+ /**
45
+ * Update the controller by merging the given props into an array of tasks.
46
+ * Individual tasks may be async and/or delayed.
47
+ */
48
+ update ( props : UpdateProps < DS > ) {
48
49
// Extract delay and the to-prop from props
49
- const { delay = 0 , to, ...props } = interpolateTo ( args ) as any
50
+ const { delay = 0 , to, ...restProps } = interpolateTo ( props ) as any
50
51
51
52
// If config is either a function or an array, queue it up as is
52
53
if ( is . arr ( to ) || is . fun ( to ) ) {
53
- this . queue . push ( { ...props , delay, to } )
54
+ this . queue . push ( { ...restProps , delay, to } )
54
55
}
55
56
// Otherwise go through each key since it could be delayed individually
56
57
else if ( to ) {
57
58
let ops : any [ ] = [ ]
58
59
Object . entries ( to ) . forEach ( ( [ k , v ] ) => {
59
- // Fetch delay and create an entry, consisting of the to-props, the delay, and basic props
60
- const entry = { to : { [ k ] : v } , delay : callProp ( delay , k ) , ...props }
61
- const previous = ops [ entry . delay ] && ops [ entry . delay ] . to
62
- ops [ entry . delay ] = {
63
- ...ops [ entry . delay ] ,
64
- ...entry ,
65
- to : { ...previous , ...entry . to } ,
60
+ // Merge entries with the same delay
61
+ const dt = callProp ( delay , k )
62
+ const previous = ops [ dt ]
63
+ ops [ dt ] = {
64
+ ...previous ,
65
+ ...restProps ,
66
+ delay : dt ,
67
+ to : { ...previous . to , [ k ] : v } ,
66
68
}
67
69
} )
68
70
ops . forEach ( op => this . queue . push ( op ) )
@@ -72,7 +74,7 @@ class Controller<DS extends object = any> {
72
74
this . queue . sort ( ( a , b ) => a . delay - b . delay )
73
75
74
76
// Diff the reduced props immediately (they'll contain the from-prop and some config)
75
- if ( hasKeys ( props ) ) this . _diff ( props )
77
+ if ( hasKeys ( restProps ) ) this . _diff ( restProps )
76
78
77
79
return this
78
80
}
@@ -105,12 +107,12 @@ class Controller<DS extends object = any> {
105
107
this . onEndQueue . length = 0
106
108
107
109
// Never assume that the last update always finishes last, since that's
108
- // not true when 2+ async animations have indeterminate durations.
110
+ // not true when 2+ async updates have indeterminate durations.
109
111
let remaining = queue . length
110
112
const didEnd =
111
113
onEnd &&
112
114
( ( finished ?: boolean ) => {
113
- if ( -- remaining < 0 || guid !== this . guid ) return
115
+ if ( -- remaining > 0 || guid !== this . guid ) return
114
116
onEnd ( finished )
115
117
} )
116
118
0 commit comments