Code Monkey home page Code Monkey logo

Comments (10)

mbraak avatar mbraak commented on May 22, 2024

Yes, I think that getNodeById should compare the ids 'unstrict'. Converting the ids to strings is probably a good way to do this.

from jqtree.

rosenfeld avatar rosenfeld commented on May 22, 2024

I've thought in a better way. There is another issue I guess with the way getNodeByXXX is currently implemented. jqTree should keep they indexed by an object/hash. That way, not only it should perform better but CoffeeScript wouldn't do any strict comparison if you're accessing the hash by id.

For example: @nodeById[id] and @nodeByName[id] would translate to this.nodeByXXX[xxx] and then no strict comparison would be performed.

And it would also perform much better than iterating over the entire tree. What do you think?

from jqtree.

mbraak avatar mbraak commented on May 22, 2024

In which situation do you use the function getNodeById? Are there any performance issues?

from jqtree.

rosenfeld avatar rosenfeld commented on May 22, 2024

Actually, I'm not using getNodeById anymore since yesterday and just using my internal map. This is more of a design decision than one based on performance. But here is the typical usage for getting the node from an id:

You have a button set in a <div data-id=2>buttons here</div>. Then you have a live event handler on those buttons and you get the id from their parent's div. Then you'll issue some AJAX request. Usually in my request's response I have access to the id of the created/updated new element so that I don't even need to store the id from the button's parent div.

Finally I need to do some operation where I need the id. For example, if it is a create action I'll need to append some node and I'll need a node as returned by getNodeById for that. But actually I've added the node information to my internal fields hash on onCreateLi handler.

from jqtree.

mbraak avatar mbraak commented on May 22, 2024

I can see the use for a fast getNodeById function. Do you also use getNodeByName? I only use it in the unit tests myself.

from jqtree.

rosenfeld avatar rosenfeld commented on May 22, 2024

Never used it.

from jqtree.

mbraak avatar mbraak commented on May 22, 2024

The getNodeById comparison is now less strict. It uses the javascript '=='.

I'm working on a performance improvement getNodeById that uses an index.

from jqtree.

rosenfeld avatar rosenfeld commented on May 22, 2024

Great, thanks :)

from jqtree.

mbraak avatar mbraak commented on May 22, 2024

Performance improvement is implemented in version 0.10

from jqtree.

rosenfeld avatar rosenfeld commented on May 22, 2024

Thanks, @mbraak :)

from jqtree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.