Git Product home page Git Product logo

Comments (3)

ctrlplusb avatar ctrlplusb commented on May 28, 2024

Hey @threehams yep you are correct. It walks in depth first fashion - i.e. resolving all the children for each component before continuing onto the next one.

Hmmm, there must be a bug in my example code then. It should only result in [1, 2, 4, 3].

from react-tree-walker.

mjadobson avatar mjadobson commented on May 28, 2024

To elaborate on this issue, it doesn't occur if the promises are removed:

class Foo extends React.Component {
  getData() {
    return Promise.resolve(this.props.value);
  }
  getDataSync() {
    return this.props.value;
  }
  render() {
    return <div>{this.props.children}</div>;
  }
}

function visitor(element, instance, context) {
  if (instance && typeof instance.getDataSync) {
    let value = instance.getDataSync();
    values.push(value);
    return value === 4 ? false : true;
  }
  return true;
}
// result: [1,2,4,3]

function visitor(element, instance, context) {
  if (instance && typeof instance.getData) {
    return instance.getData().then(value => {
      values.push(value);
      return value === 4 ? false : true;
    });
  }
  return true;
}
// result: [1,2,4,5,3]

from react-tree-walker.

ctrlplusb avatar ctrlplusb commented on May 28, 2024

This should be fixed with the upcoming release. Thanks for the report!

from react-tree-walker.

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.