Commit c859340e authored by Mike Bostock's avatar Mike Bostock
Browse files

Fix #1364 - construct transition.event lazily.

parent 747c523e
......@@ -7639,7 +7639,8 @@ d3 = function() {
d3_transitionInheritId = inheritId;
} else {
d3_selection_each(this, function(node) {
node.__transition__[id].event.on(type, listener);
var transition = node.__transition__[id];
(transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
});
}
return this;
......@@ -7668,7 +7669,6 @@ d3 = function() {
var time = inherit.time;
transition = lock[id] = {
tween: new d3_Map(),
event: d3.dispatch("start", "end"),
time: time,
ease: inherit.ease,
delay: inherit.delay,
......@@ -7676,12 +7676,12 @@ d3 = function() {
};
++lock.count;
d3.timer(function(elapsed) {
var d = node.__data__, ease = transition.ease, event = transition.event, delay = transition.delay, duration = transition.duration, tweened = [];
var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, tweened = [];
return delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time), 1;
function start(elapsed) {
if (lock.active > id) return stop();
lock.active = id;
event.start.call(node, d, i);
transition.event && transition.event.start.call(node, d, i);
transition.tween.forEach(function(key, value) {
if (value = value.call(node, d, i)) {
tweened.push(value);
......@@ -7698,7 +7698,7 @@ d3 = function() {
}
if (t >= 1) {
stop();
event.end.call(node, d, i);
transition.event && transition.event.end.call(node, d, i);
return 1;
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -15,7 +15,8 @@ d3_transitionPrototype.each = function(type, listener) {
d3_transitionInheritId = inheritId;
} else {
d3_selection_each(this, function(node) {
node.__transition__[id].event.on(type, listener);
var transition = node.__transition__[id];
(transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
});
}
return this;
......
......@@ -54,7 +54,6 @@ function d3_transitionNode(node, i, id, inherit) {
transition = lock[id] = {
tween: new d3_Map,
event: d3.dispatch("start", "end"), // TODO construct lazily?
time: time,
ease: inherit.ease,
delay: inherit.delay,
......@@ -66,7 +65,6 @@ function d3_transitionNode(node, i, id, inherit) {
d3.timer(function(elapsed) {
var d = node.__data__,
ease = transition.ease,
event = transition.event,
delay = transition.delay,
duration = transition.duration,
tweened = [];
......@@ -78,7 +76,7 @@ function d3_transitionNode(node, i, id, inherit) {
function start(elapsed) {
if (lock.active > id) return stop();
lock.active = id;
event.start.call(node, d, i);
transition.event && transition.event.start.call(node, d, i);
transition.tween.forEach(function(key, value) {
if (value = value.call(node, d, i)) {
......@@ -103,7 +101,7 @@ function d3_transitionNode(node, i, id, inherit) {
if (t >= 1) {
stop();
event.end.call(node, d, i);
transition.event && transition.event.end.call(node, d, i);
return 1;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment