Comments (3)
@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.
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:
- Is this application state? Does anything else in my application care about this state? Or do I think it will in the future?
- 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.
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)
- question on immutable in production HOT 6
- Memory leak when overwriting monkeys HOT 1
- how to remover a listener HOT 2
- Monkey in an array HOT 3
- Listening to elements in Array not working with strings HOT 2
- Events are not firing up in IE11 HOT 7
- Integration with flowtype HOT 5
- Option to disable monkeys HOT 3
- Class instance feature lost when altering the state. HOT 6
- Other parts of tree fire events when deepMerge HOT 2
- Using Baobab 2.5.1 is causing babel to fail HOT 5
- Support ES Modules HOT 3
- Question regarding releasing cursors HOT 2
- Compatiblity issue with babel-preset-env introduced in version 2.5.1 HOT 19
- Unify output from tree events and cursor events HOT 2
- Infinite loop when adding DOM element HOT 3
- Support structural equality for keys HOT 8
- Generic types for get, set, select, and apply; immutability for apply callback input HOT 9
- Add a security policy HOT 2
- Force monkey recalculation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baobab.