Is exit selection necessary in D3?

Icreated this simple example using data join in D3. It works: when user clicks on +1 a green is added to the list, when clicks on -1 the last color in the list is removed.

Here the code:

const colors = ["white", "yellow", "red", "brown", "orange"];
    const root = d3.select("#root");
    const addColor = d3.select("#add-color");
    addColor.on("click", (d) => {
      colors.push("green");
      update();
    });
    const removeColor = d3.select("#remove-color");
    removeColor.on("click", (d) => {
      colors.pop();
      update();
    });
    const ul = root.append("ul");
    ul.selectAll("li")
      .data(colors)
      .join(
        (enter) => enter.append("li").text((d) => d),
        (update) => update,
        (exit) => exit.remove()
      );
      
    function update(){
      ul.selectAll("li")
      .data(colors)
      .join(
        (enter) => enter.append("li").text((d) => d),
        (update) => update,
        (exit) => exit.remove()
      );
    }
#buttons-container {
      display: flex;
      margin-bottom: 30px;
    }
    #buttons-container div {
      min-width: 30px;
      text-align: center;
      cursor: pointer;
      border: 1px solid black;
      margin-right: 50px;
    }
<!DOCTYPE html>
    <meta charset="utf-8" />
    <html>
      <body>
        <div id="root">
          <div id="buttons-container">
            <div id="add-color">+1</div>
            <div id="remove-color">-1</div>
          </div>
        </root>
        <script
          type="text/javascript"
          src="https://cdnjs.cloudflare.com/ajax/libs/d3/6.5.0/d3.min.js"
        ></script>
        <script type="text/javascript" src="./index.js"></script>
        <script type="text/css" src="./styles.css"></script>
      </body>
    </html>

Then I commented the exit action:

function update() {
  ul.selectAll("li")
    .data(flavors, (d) => d)
    .join(
      (enter) =>
        enter
          .append("li")
          .text((d) => d)
          .style("color", "green"),
      (update) => update.style("color", "steelblue"),
      //(exit) => exit.style("color", "red").remove()
    );
}

And it works in the same way. What am I missing? Is exit necessary?

115 thoughts on “Is exit selection necessary in D3?”

  1. Pingback: viagra overnight
  2. I have been surfing on-line more than three hours nowadays, but I never discovered any attention-grabbing
    article like yours. It is pretty price sufficient for me.
    In my view, if all web owners and bloggers made excellent content material as you did, the internet can be a lot more useful than ever before.

    Reply
  3. Greetings from Los angeles! I’m bored to tears at work
    so I decided to browse your blog on my iphone during lunch break.

    I love the info you provide here and can’t wait to
    take a look when I get home. I’m amazed at how quick your blog loaded
    on my mobile .. I’m not even using WIFI, just 3G .. Anyways, great blog!

    Reply
  4. It’s the best time to make some plans for the future and it is time to be
    happy. I’ve read this post and if I could I desire to suggest
    you few interesting things or advice. Maybe you
    can write next articles referring to this article.
    I want to read even more things about it!

    Reply
  5. Hey! Someone in my Myspace group shared this website with
    us so I came to take a look. I’m definitely enjoying the information. I’m book-marking and will be tweeting this
    to my followers! Outstanding blog and excellent design.

    Reply
  6. Hi, i think that i saw you visited my site so i came to “return the favor”.I’m attempting to find
    things to enhance my site!I suppose its ok to use some
    of your ideas!

    Reply
  7. Hello there, I discovered your web site via Google at the same time as looking for a comparable matter, your website came up, it appears to be like good.
    I have bookmarked it in my google bookmarks. Hello there, just become
    alert to your weblog thru Google, and located that it is truly informative.
    I am going to be careful for brussels. I’ll be grateful if you proceed this in future.
    Numerous other folks will probably be benefited out
    of your writing. Cheers!

    Reply
  8. Heya i am for the first time here. I found this board and I to find It truly useful & it helped me out a lot. I hope to offer one thing back and help others such as you helped me.

    Reply
  9. Howdy just wanted to give you a quick heads up. The words in your post seem to
    be running off the screen in Opera. I’m not sure if this is
    a format issue or something to do with internet browser compatibility but I thought
    I’d post to let you know. The style and design look
    great though! Hope you get the issue solved soon. Kudos

    Reply
  10. Have you ever considered about including a little bit more than just your
    articles? I mean, what you say is important and all.
    But think about if you added some great images or video clips to
    give your posts more, “pop”! Your content is excellent but with pics
    and videos, this site could certainly be one of the best in its field.
    Amazing blog!

    Reply
  11. I will right away clutch your rss as I can not find your
    email subscription hyperlink or newsletter service. Do you’ve any?
    Kindly let me recognize so that I may subscribe.
    Thanks.

    Reply
  12. I’ve been browsing online greater than 3 hours as of late, yet I by no means discovered any attention-grabbing article
    like yours. It’s lovely value enough for me. In my view, if
    all website owners and bloggers made good content as you probably did, the net shall
    be a lot more useful than ever before.

    Reply
  13. I carry on listening to the news broadcast lecture about getting boundless online grant applications so I have been looking around for the most excellent site to get one. Could you tell me please, where could i acquire some?

    Reply
  14. I’ll right away take hold of your rss as I can not
    find your e-mail subscription hyperlink or newsletter service.
    Do you have any? Kindly allow me know in order that I may
    just subscribe. Thanks.

    Reply
  15. Great goods from you, man. I’ve understand your stuff previous to and you’re just
    extremely excellent. I really like what you have acquired
    here, really like what you are saying and the way
    in which you say it. You make it enjoyable and you still care for
    to keep it sensible. I cant wait to read far more from you.

    This is actually a tremendous web site.

    Reply
  16. Definitely imagine that that you said. Your favorite reason appeared to be at
    the web the simplest thing to understand of.
    I say to you, I definitely get annoyed whilst other people think about worries that they plainly do not recognize about.
    You managed to hit the nail upon the highest and outlined
    out the whole thing without having side effect , other folks could take a signal.

    Will likely be back to get more. Thank you

    Reply
  17. Hey! Someone in my Facebook group shared this website with us so I
    came to give it a look. I’m definitely loving
    the information. I’m bookmarking and will be tweeting this to my followers!

    Great blog and excellent design and style.

    Reply
  18. I’ll immediately ttake hold oof youir rss feed as I can’t too find
    yoir eail subscription hyperlink oor newsletter service.
    Do you’ve any? Kindly permkt me realize sso hat I could
    subscribe. Thanks.

    Reply
  19. Howdy, i read your blog occasionally and i own a similar one and i was just wondering
    if you get a lot of spam remarks? If so how do you prevent it, any
    plugin or anything you can advise? I get so much lately it’s driving me insane so any help is very much appreciated.

    Reply
  20. I have been browsing online more than 3 hours nowadays, yet I never discovered any attention-grabbing article like yours.
    It is lovely price enough for me. In my view, if
    all webmasters and bloggers made excellent
    content as you probably did, the internet will
    likely be a lot more useful than ever before.

    Reply
  21. It is appropriate time to make some plans for the future and it’s time
    to be happy. I’ve read this post and if I could I wish to suggest you some interesting things or tips.
    Maybe you could write next articles referring to this article.
    I wish to read more things about it!

    Reply
  22. I have been surfing online greater than 3 hours lately, but I
    never discovered any interesting article like yours. It’s pretty price sufficient for me.
    Personally, if all web owners and bloggers made excellent content
    as you did, the internet will be much more helpful than ever before.

    Reply
  23. I’ve been browsing online more than 3 hours lately,
    yet I never found any attention-grabbing article like yours.
    It is beautiful value enough for me. In my view,
    if all website owners and bloggers made excellent content material as you probably did, the web might be much more useful than ever before.

    Reply
  24. I wanted to follow along and allow you to know how great I loved discovering your blog today. I will consider it a good honor to work at my business office and be able to utilize the tips shared on your blog and also get involved in visitors’ opinions like this. Should a position of guest article writer become offered at your end, you should let me know.

    Reply
  25. Hi there! Someone in my Facebook group shared this website with us so I came to look
    it over. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this
    to my followers! Great blog and great design.

    Reply
  26. These days of austerity and also relative anxiety about having debt, many individuals balk against the idea of having a credit card in order to make purchase of merchandise or even pay for any gift giving occasion, preferring, instead to rely on the particular tried and trusted procedure for making settlement – cash. However, if you possess cash there to make the purchase completely, then, paradoxically, this is the best time for them to use the cards for several causes.

    Reply
  27. It is perfect time to make some plans for the future
    and it’s time to be happy. I’ve read this post and if I could I wish to suggest you some
    interesting things or advice. Perhaps you can write next articles referring to this article.
    I wish to read even more things about it!

    Reply
  28. It is appropriate time to make some plans for the longer
    term and it’s time to be happy. I’ve learn this publish and if I may
    just I desire to counsel you few interesting things or suggestions.
    Maybe you can write subsequent articles referring to this article.
    I wish to read more things approximately it!

    Reply

Leave a Comment