From 7285f514578014f1a7630523cac88a7e5479e74a Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 24 Jan 2019 16:35:35 -0800 Subject: [PATCH] Use anonymous listeners. --- src/transition/end.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/transition/end.js b/src/transition/end.js index 55204d0..d3c0baf 100644 --- a/src/transition/end.js +++ b/src/transition/end.js @@ -1,9 +1,26 @@ -// TODO Anonymous names for event listeners. +import {set} from "./schedule"; + export default function() { - var that = this, size = that.size(); + var on0, on1, that = this, id = that._id, size = that.size(); return new Promise(function(resolve, reject) { - that.on("cancel.end interrupt.end", reject).on("end.end", function() { - if (--size === 0) resolve(); + var cancel = {value: reject}, + end = {value: function() { if (--size === 0) resolve(); }}; + + that.each(function() { + var schedule = set(this, id), + on = schedule.on; + + // If this node shared a dispatch with the previous node, + // just assign the updated shared dispatch and we’re done! + // Otherwise, copy-on-write. + if (on !== on0) { + on1 = (on0 = on).copy(); + on1._.cancel.push(cancel); + on1._.interrupt.push(cancel); + on1._.end.push(end); + } + + schedule.on = on1; }); }); }