-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify usage of selection.join with transitions #286
Conversation
src/selection/join.js
Outdated
@@ -3,5 +3,5 @@ export default function(onenter, onupdate, onexit) { | |||
enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + ""); | |||
if (onupdate != null) update = onupdate(update); | |||
if (onexit == null) exit.remove(); else onexit(exit); | |||
return enter && update ? enter.merge(update).order() : update; | |||
return enter && update ? enter.selection().merge(update.selection()).order() : update; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do this earlier so that selection.join is guaranteed to return a selection, like so:
function(onenter, onupdate, onexit) {
var enter = this.enter(), update = this, exit = this.exit();
if (typeof onenter === "function") {
enter = onenter(enter);
if (enter) enter = enter.selection();
} else {
enter = enter.append(onenter + "");
}
if (onupdate != null) {
update = onupdate(update);
if (update) update = update.selection();
}
if (onexit == null) exit.remove(); else onexit(exit);
return enter && update ? enter.merge(update).order() : update;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes good catch! Thank you.
Remaining work:
|
No, you’ll still want it because otherwise selection.join could return a transition if there’s no enter selection: return enter && update ? enter.merge(update).order() : update; |
Added tests and docs. Ready for review. Thanks! |
Hooray! Thank you @mbostock 🙏 |
Related to #257, an alternative to #285, this change would allow
.join
to handle the case that transitions are returned byonenter
and/oronupdate
. It would support the same simplified usage documented in #257, but leave the behavior of.merge
unchanged. Just putting this out there as an alternative to consider, as it targets the main pain point, rather than introducing new behavior in.merge
to accomplish the same goal.This works because of selection.selection.