Simplify usage of selection.join with transitions#286
Merged
Conversation
This was referenced May 25, 2021
mbostock
reviewed
May 25, 2021
src/selection/join.js
Outdated
| 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; |
Member
There was a problem hiding this comment.
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;
}
Contributor
Author
There was a problem hiding this comment.
Oh yes good catch! Thank you.
Contributor
Author
|
Remaining work:
|
Contributor
Author
Member
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; |
Contributor
Author
|
Added tests and docs. Ready for review. Thanks! |
Contributor
Author
|
Hooray! Thank you @mbostock 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #257, an alternative to #285, this change would allow
.jointo handle the case that transitions are returned byonenterand/oronupdate. It would support the same simplified usage documented in #257, but leave the behavior of.mergeunchanged. Just putting this out there as an alternative to consider, as it targets the main pain point, rather than introducing new behavior in.mergeto accomplish the same goal.This works because of selection.selection.