From aa95e77d8761f34ea87f6af9ca89376e19d60c29 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 28 Feb 2018 10:45:15 -0800 Subject: [PATCH] Add transition.end. Fixes #77. --- .eslintrc | 3 +++ src/transition/end.js | 9 +++++++++ src/transition/index.js | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/transition/end.js diff --git a/.eslintrc b/.eslintrc index d1da9f4..35c67db 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,9 @@ parserOptions: sourceType: module +env: + es6: true + extends: "eslint:recommended" diff --git a/src/transition/end.js b/src/transition/end.js new file mode 100644 index 0000000..55204d0 --- /dev/null +++ b/src/transition/end.js @@ -0,0 +1,9 @@ +// TODO Anonymous names for event listeners. +export default function() { + var that = this, size = that.size(); + return new Promise(function(resolve, reject) { + that.on("cancel.end interrupt.end", reject).on("end.end", function() { + if (--size === 0) resolve(); + }); + }); +} diff --git a/src/transition/index.js b/src/transition/index.js index b479b9f..ffb49ea 100644 --- a/src/transition/index.js +++ b/src/transition/index.js @@ -16,6 +16,7 @@ import transition_styleTween from "./styleTween"; import transition_text from "./text"; import transition_transition from "./transition"; import transition_tween from "./tween"; +import transition_end from "./end"; var id = 0; @@ -60,5 +61,6 @@ Transition.prototype = transition.prototype = { tween: transition_tween, delay: transition_delay, duration: transition_duration, - ease: transition_ease + ease: transition_ease, + end: transition_end };