Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. ReactJS - Add 10,000 nodes & select options

ReactJS - Add 10,000 nodes & select options

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascripthtmlcomdata-structuresregex
9 Posts 5 Posters 82 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • raddevusR Offline
    raddevusR Offline
    raddevus
    wrote on last edited by
    #1

    I've been learning React. It's quite amazing actually. I wanted to know what the impact of my simple Project* object would be if there were a lot of them. Questions I Had 1. What If I Added 10,000 div nodes to my page? 2. What if I added 10,000 choices to a drop list (html select tag - option values)? 2a. Additionally, what if I added each Project object (serialized to string) as the value on the select tag option? It performs amazingly well. Bonus Info Here's how you add a value to a drop list (select tag) in HTML / JavaScript:

    // get reference to the drop list
    let projectList = document.querySelector("#projectList");
    // Append a new Option to the drop list - p.name is the text you'll see
    // value (string) is the value returned when item is selected.
    projectList.append(new Option(p.name, value, false, false));

    Add Object As Value But, if you're an OOP person and you want to use a specific object whenever an item is selected int he drop list then you want to store the object as the value. That way, when the user selects the item you have the original object. Since value expects a string you will need to do this:

    projectList.append(new Option(p.name, JSON.stringify(p), false, false));

    Now when the user selects an item in the drop list you simply parse the thing back to your target object. The changehandler is my method which is fired when user selects a new value from drop list.

    changeHandler(e) {
    // changehandler receives event object which contains target (drop list item selected)
    // item's properties will match a Project
    let item = JSON.parse(e.target.value);
    console.log(`item.name: ${item.name}`); // original Name of the Project
    }

    But How Does It Perform With 10,000 Serialized Objects? It's amazing. Takes < 1 second for drop list to respond. Pics or it didn't happen. :rolleyes: See snapshot here[^]. *Project Class

    export class Project {
    constructor(name) {
    this.id = uuidv4();
    this.ownerId = localUser;
    this.name = name || '';
    this.created = new Date();
    }
    }

    File it under weird, but it is also quite wonderful. :laugh:

    Richard DeemingR G A J 4 Replies Last reply
    0
    • raddevusR raddevus

      I've been learning React. It's quite amazing actually. I wanted to know what the impact of my simple Project* object would be if there were a lot of them. Questions I Had 1. What If I Added 10,000 div nodes to my page? 2. What if I added 10,000 choices to a drop list (html select tag - option values)? 2a. Additionally, what if I added each Project object (serialized to string) as the value on the select tag option? It performs amazingly well. Bonus Info Here's how you add a value to a drop list (select tag) in HTML / JavaScript:

      // get reference to the drop list
      let projectList = document.querySelector("#projectList");
      // Append a new Option to the drop list - p.name is the text you'll see
      // value (string) is the value returned when item is selected.
      projectList.append(new Option(p.name, value, false, false));

      Add Object As Value But, if you're an OOP person and you want to use a specific object whenever an item is selected int he drop list then you want to store the object as the value. That way, when the user selects the item you have the original object. Since value expects a string you will need to do this:

      projectList.append(new Option(p.name, JSON.stringify(p), false, false));

      Now when the user selects an item in the drop list you simply parse the thing back to your target object. The changehandler is my method which is fired when user selects a new value from drop list.

      changeHandler(e) {
      // changehandler receives event object which contains target (drop list item selected)
      // item's properties will match a Project
      let item = JSON.parse(e.target.value);
      console.log(`item.name: ${item.name}`); // original Name of the Project
      }

      But How Does It Perform With 10,000 Serialized Objects? It's amazing. Takes < 1 second for drop list to respond. Pics or it didn't happen. :rolleyes: See snapshot here[^]. *Project Class

      export class Project {
      constructor(name) {
      this.id = uuidv4();
      this.ownerId = localUser;
      this.name = name || '';
      this.created = new Date();
      }
      }

      File it under weird, but it is also quite wonderful. :laugh:

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      But as we keep telling people in QA, a list of 10_000 items isn't much use to the user. :) Until we get proper support for the selectmenu[^] element, you'd probably want to use a plugin like Select2[^] to add a search to your list. But at that point, you might be better to use something closer to an "auto-complete" approach, and load the matching items on demand.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      raddevusR 1 Reply Last reply
      0
      • raddevusR raddevus

        I've been learning React. It's quite amazing actually. I wanted to know what the impact of my simple Project* object would be if there were a lot of them. Questions I Had 1. What If I Added 10,000 div nodes to my page? 2. What if I added 10,000 choices to a drop list (html select tag - option values)? 2a. Additionally, what if I added each Project object (serialized to string) as the value on the select tag option? It performs amazingly well. Bonus Info Here's how you add a value to a drop list (select tag) in HTML / JavaScript:

        // get reference to the drop list
        let projectList = document.querySelector("#projectList");
        // Append a new Option to the drop list - p.name is the text you'll see
        // value (string) is the value returned when item is selected.
        projectList.append(new Option(p.name, value, false, false));

        Add Object As Value But, if you're an OOP person and you want to use a specific object whenever an item is selected int he drop list then you want to store the object as the value. That way, when the user selects the item you have the original object. Since value expects a string you will need to do this:

        projectList.append(new Option(p.name, JSON.stringify(p), false, false));

        Now when the user selects an item in the drop list you simply parse the thing back to your target object. The changehandler is my method which is fired when user selects a new value from drop list.

        changeHandler(e) {
        // changehandler receives event object which contains target (drop list item selected)
        // item's properties will match a Project
        let item = JSON.parse(e.target.value);
        console.log(`item.name: ${item.name}`); // original Name of the Project
        }

        But How Does It Perform With 10,000 Serialized Objects? It's amazing. Takes < 1 second for drop list to respond. Pics or it didn't happen. :rolleyes: See snapshot here[^]. *Project Class

        export class Project {
        constructor(name) {
        this.id = uuidv4();
        this.ownerId = localUser;
        this.name = name || '';
        this.created = new Date();
        }
        }

        File it under weird, but it is also quite wonderful. :laugh:

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        I would suggest if you are liking React - make use of: TypeScript - it's Javascript with strong typing and makes Javasript so much better to work with. Redux - well worth doing the main Redux tutorial first and consider using it as it makes handling state much easier.

        “That which can be asserted without evidence, can be dismissed without evidence.”

        ― Christopher Hitchens

        raddevusR 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          But as we keep telling people in QA, a list of 10_000 items isn't much use to the user. :) Until we get proper support for the selectmenu[^] element, you'd probably want to use a plugin like Select2[^] to add a search to your list. But at that point, you might be better to use something closer to an "auto-complete" approach, and load the matching items on demand.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          raddevusR Offline
          raddevusR Offline
          raddevus
          wrote on last edited by
          #4

          Thanks for the info on SelectMenu I will check it out. :thumbsup:

          1 Reply Last reply
          0
          • G GuyThiebaut

            I would suggest if you are liking React - make use of: TypeScript - it's Javascript with strong typing and makes Javasript so much better to work with. Redux - well worth doing the main Redux tutorial first and consider using it as it makes handling state much easier.

            “That which can be asserted without evidence, can be dismissed without evidence.”

            ― Christopher Hitchens

            raddevusR Offline
            raddevusR Offline
            raddevus
            wrote on last edited by
            #5

            You are right about TypeScript. It would be a lot nicer if the type I store and deserialize were known by the language itself. :thumbsup:

            1 Reply Last reply
            0
            • raddevusR raddevus

              I've been learning React. It's quite amazing actually. I wanted to know what the impact of my simple Project* object would be if there were a lot of them. Questions I Had 1. What If I Added 10,000 div nodes to my page? 2. What if I added 10,000 choices to a drop list (html select tag - option values)? 2a. Additionally, what if I added each Project object (serialized to string) as the value on the select tag option? It performs amazingly well. Bonus Info Here's how you add a value to a drop list (select tag) in HTML / JavaScript:

              // get reference to the drop list
              let projectList = document.querySelector("#projectList");
              // Append a new Option to the drop list - p.name is the text you'll see
              // value (string) is the value returned when item is selected.
              projectList.append(new Option(p.name, value, false, false));

              Add Object As Value But, if you're an OOP person and you want to use a specific object whenever an item is selected int he drop list then you want to store the object as the value. That way, when the user selects the item you have the original object. Since value expects a string you will need to do this:

              projectList.append(new Option(p.name, JSON.stringify(p), false, false));

              Now when the user selects an item in the drop list you simply parse the thing back to your target object. The changehandler is my method which is fired when user selects a new value from drop list.

              changeHandler(e) {
              // changehandler receives event object which contains target (drop list item selected)
              // item's properties will match a Project
              let item = JSON.parse(e.target.value);
              console.log(`item.name: ${item.name}`); // original Name of the Project
              }

              But How Does It Perform With 10,000 Serialized Objects? It's amazing. Takes < 1 second for drop list to respond. Pics or it didn't happen. :rolleyes: See snapshot here[^]. *Project Class

              export class Project {
              constructor(name) {
              this.id = uuidv4();
              this.ownerId = localUser;
              this.name = name || '';
              this.created = new Date();
              }
              }

              File it under weird, but it is also quite wonderful. :laugh:

              A Offline
              A Offline
              Amarnath S
              wrote on last edited by
              #6

              Need a recommendation from you. Am planning to write a 3D game in JavaScript, a small hobby project, which uses Three.js library. Is it better written in ReactJS (which I have to still learn), or in plain Vanilla JS? What would you recommend?

              raddevusR 1 Reply Last reply
              0
              • A Amarnath S

                Need a recommendation from you. Am planning to write a 3D game in JavaScript, a small hobby project, which uses Three.js library. Is it better written in ReactJS (which I have to still learn), or in plain Vanilla JS? What would you recommend?

                raddevusR Offline
                raddevusR Offline
                raddevus
                wrote on last edited by
                #7

                If you're basically using HTML5 CANVAS which you probably are, then I would most likely go with vanilla JS. React basically gives you a way to manipulate the HTML DOM that is fast and easily updateable. But if you're not using much DOM because your game runs in the Canvas then you really won't get much out of React anyways. Also, if you are going to have a Canvas area and then DOM elements surrounding it you can even add React later to manipulate those DOM elements so you won't have to begin with React anyways and it will be easy to later incorporate React. That's actually one of the really nice things of the React framework. Hope this helps. Good luck! :thumbsup:

                A 1 Reply Last reply
                0
                • raddevusR raddevus

                  If you're basically using HTML5 CANVAS which you probably are, then I would most likely go with vanilla JS. React basically gives you a way to manipulate the HTML DOM that is fast and easily updateable. But if you're not using much DOM because your game runs in the Canvas then you really won't get much out of React anyways. Also, if you are going to have a Canvas area and then DOM elements surrounding it you can even add React later to manipulate those DOM elements so you won't have to begin with React anyways and it will be easy to later incorporate React. That's actually one of the really nice things of the React framework. Hope this helps. Good luck! :thumbsup:

                  A Offline
                  A Offline
                  Amarnath S
                  wrote on last edited by
                  #8

                  Thanks a lot. My app will have one big screen-wide canvas (except for a small controls area). I will go with plain Vanilla JS to start with.

                  1 Reply Last reply
                  0
                  • raddevusR raddevus

                    I've been learning React. It's quite amazing actually. I wanted to know what the impact of my simple Project* object would be if there were a lot of them. Questions I Had 1. What If I Added 10,000 div nodes to my page? 2. What if I added 10,000 choices to a drop list (html select tag - option values)? 2a. Additionally, what if I added each Project object (serialized to string) as the value on the select tag option? It performs amazingly well. Bonus Info Here's how you add a value to a drop list (select tag) in HTML / JavaScript:

                    // get reference to the drop list
                    let projectList = document.querySelector("#projectList");
                    // Append a new Option to the drop list - p.name is the text you'll see
                    // value (string) is the value returned when item is selected.
                    projectList.append(new Option(p.name, value, false, false));

                    Add Object As Value But, if you're an OOP person and you want to use a specific object whenever an item is selected int he drop list then you want to store the object as the value. That way, when the user selects the item you have the original object. Since value expects a string you will need to do this:

                    projectList.append(new Option(p.name, JSON.stringify(p), false, false));

                    Now when the user selects an item in the drop list you simply parse the thing back to your target object. The changehandler is my method which is fired when user selects a new value from drop list.

                    changeHandler(e) {
                    // changehandler receives event object which contains target (drop list item selected)
                    // item's properties will match a Project
                    let item = JSON.parse(e.target.value);
                    console.log(`item.name: ${item.name}`); // original Name of the Project
                    }

                    But How Does It Perform With 10,000 Serialized Objects? It's amazing. Takes < 1 second for drop list to respond. Pics or it didn't happen. :rolleyes: See snapshot here[^]. *Project Class

                    export class Project {
                    constructor(name) {
                    this.id = uuidv4();
                    this.ownerId = localUser;
                    this.name = name || '';
                    this.created = new Date();
                    }
                    }

                    File it under weird, but it is also quite wonderful. :laugh:

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    raddevus wrote:

                    What if I added 10,000 choices to a drop list

                    Myself I would tag that as a bad UX design. As a back end developer who was requested to populate it I would refuse to do it without paging. Since I know that if there are 10,000 now then there are going to be 100,000 next year. And when that blows up I can't point to the UI as the problem.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups