Skip to content

Commit

Permalink
Use anonymous listeners.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 25, 2019
1 parent e7494d7 commit 7285f51
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions 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;
});
});
}

0 comments on commit 7285f51

Please sign in to comment.