Closed mbostock closed 5 years ago
When the target value is specified as a function, the target value is not known until the tween is initialized and the function is called. And a transition’s tweens are initialized immediately after the transition starts; at that point, it’s too late to register an end event listener, as is done in the constant case. Per the README:
The transition then dispatches a start event to registered listeners. This is the last moment at which the transition may be modified: after starting, the transition’s timing, tweens, and listeners may no longer be changed.
So either: (1) we need to defer the state change from STARTING to STARTED until after the tweens are initialized, allowing them to add or remote transition event listeners (which is a bit confusing since at that point the start event was already dispatched… but probably okay) or (2) we need to use a different mechanism for removing the style after the transition ends, say by registering a tween that removes the style when t === 1 (which is icky because due to easing that could occur at times other than the exact end of the transition) or perhaps a tween that checks that state === ENDING.
We do remove the style on transition end in this case:
But we don’t in this case: