Giter Site home page Giter Site logo

rowRenderer onclick about infinite-tree HOT 3 CLOSED

cheton avatar cheton commented on July 26, 2024
rowRenderer onclick

from infinite-tree.

Comments (3)

cheton avatar cheton commented on July 26, 2024

A click event will call row renderer twice, this is the expected behavior. The first call is to render the next selected node, the second call is to render previous selected node so it will display the unselected state:

// Select this node
if (this.state.selectedNode !== node) {
    node.state.selected = true;

    // Update the row corresponding to the node
    this.rows[nodeIndex] = this.options.rowRenderer(node, this.options);
}

// Deselect the current node
if (this.state.selectedNode) {
    const selectedNode = this.state.selectedNode;
    const selectedIndex = this.nodes.indexOf(this.state.selectedNode);
    selectedNode.state.selected = false;
    this.rows[selectedIndex] = this.options.rowRenderer(selectedNode, this.options);
}

In your case, the updateNode method does not remove unused id from the lookup table (e.g. this.nodeTable) because I didn't expect one would ever change the node id. I think that would be the problem that caused an error.

Lets take a look at getNodeById, it will lookup the node by id from the nodeTable, if an unused node id was not removed from the nodeTable, it will return the node immediately, and therefore caused unexpected behavior.

 getNodeById(id) {
    let node = this.nodeTable.get(id);
    if (!node) {
        // Find the first node that matches the id
        node = this.nodes.filter((node) => {
            return (node.id === id);
        })[0];
        if (!node) {
            return null;
        }
        this.nodeTable.set(node.id, node);
    }
    return node;
}

from infinite-tree.

cheton avatar cheton commented on July 26, 2024

The lookup table should be refreshed when changing the node id with updateNode. I will fix it in the next release.

from infinite-tree.

cheton avatar cheton commented on July 26, 2024

Fixed in v1.8.2

from infinite-tree.

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.