From 4b4ea122ad1a37317f88186371f66a08d7c63cb0 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 10 Dec 2019 13:42:11 -0500 Subject: [PATCH] Fix performance issue where breathe behavior would be called for each selected element instead of just for the surface (close #3571) --- modules/behavior/breathe.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/behavior/breathe.js b/modules/behavior/breathe.js index 406d4af57..74bc0aa72 100644 --- a/modules/behavior/breathe.js +++ b/modules/behavior/breathe.js @@ -126,12 +126,19 @@ export function behaviorBreathe() { _selected = currSelected.call(calcAnimationParams); } + var didCallNextRun = false; + _selected .transition() .duration(duration) .call(setAnimationParams, fromTo) .on('end', function() { - surface.call(run, toFrom); + // `end` event is called for each selected element, but we want + // it to run only once + if (!didCallNextRun) { + surface.call(run, toFrom); + didCallNextRun = true; + } }); }