Giter VIP home page Giter VIP logo

Comments (3)

Yomguithereal avatar Yomguithereal commented on May 28, 2024

@christianalfoni, you might know about this one. I cannot seem to make a controlled react input work correctly with asynchronous tree updates:

var tree = new Boabab({inputValue: null});

var Input = React.createClass({
  mixins: [tree.mixin],
  cursor: ['inputValue'],
  onChange: function(e) {
    var newValue = e.target.value;

    // If one edits the tree normally, i.e. asynchronously, the cursor will hop
    this.cursor.edit(newValue);

    // One has to commit synchronously the update for the input to work correctly
    this.cursor.edit(newValue).commit();
  },
  render: function() {
    return <input onChange={this.onChange} value={this.cursor.get()} />;
  }
});

If update is made asynchronously, the cursor will hop. Do you know a workaround? Or does the user need to commit changes synchronously?

from baobab.

christianalfoni avatar christianalfoni commented on May 28, 2024

Hi again,

Yeah, this might seem a bit unfortunate. I do not believe you could do anything better than using commit(). You would have to intercept and prevent the keydown, translate the key and manually update the tree which then updates the input... even that may cause some strange behavior.

But I do not think you should get into these situations. Referring to my comment on "touch". Baobab is great for flux architecture. I also ask myself two questions when creating/updating state in an application:

  1. Is this application state? Does anything else in my application care about this state? Or do I think it will in the future?
  2. Or is this component state? Is it only related to this component and//or its children

In the case of binding an input to a state I can not see that it would be valuable to the application to know about that "live update". Places you use binding of inputs is on typeaheads, validation in forms etc. And those are typically only related to component state.

So yeah, I would not worry about it. And as you state, you can force synchronous behavior in this "edge case", as I would call it.

from baobab.

Yomguithereal avatar Yomguithereal commented on May 28, 2024

Yes, I admit this case is quite rare. I stumbled upon such a case when building an admin for neo4j needing to have a query input synchronized with several different user interactions and archived within the localStorage for convenience.

I should probably document it somewhere and close the issue.

from baobab.

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.