-
Notifications
You must be signed in to change notification settings - Fork 48.5k
Allow namespacing in refs #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can do it so: |
Can you modify my example specifically to show how it can be done with existing implementation. Your case adds tight coupling with the render code. So if I, for instance (sometime in the future), remove all the I assumed that if this issue #221 is being considered, then might as well implement namespacing for references. |
I don't think #221 is being considered now. I was saying you could loop through them and check for the |
Nothing has happened on #221 recently, but I wouldn't count it out yet. I'm not convinced we want to make this sort of change to refs. By using a string we don't need to have complicated logic and we don't need to actually parse it, just use it. If somebody want's to use a period in their string, why not let them. Also, we don't really have the guarantee that the period is a real separator, The difference between refs and components (#221) is that we don't have any implied semantics for So based on that, I'm inclined to wontfix this... I would actually suggest maybe going in the opposite direction and storing a list of refs in an object (maybe namespace that), then iterating over that object instead of the refs, and seeing if that value exists in var SYNTAX_REFS = [
'syntax.javascript',
'syntax.html',
'syntax.css',
'syntax.c++'
]
// or maybe
var REFS = {
syntax: {
html: 'syntax.html',
...
'c++': 'syntax.c++'
}
}
var Editor = React.createClass({
componentDidMount: function() {
SYNTAX_REFS.forEach(function(ref) {
if (ref in this.refs) {
var editor = this.refs[ref];
editor.prettify().colorize();
}
}, this);
// OR if using REFS
for (lang in REFS.syntax) {
var ref = REFS.syntax[lang];
if (ref in this.refs) {
var editor = this.refs[ref];
editor.prettify().colorize();
}
}
this.refs.plain.prettify();
},
render: function() {
return (
<div id='content'>
<TextEditor ref='syntax.javascript' />
<TextEditor ref='syntax.html' />
<TextEditor ref='syntax.css' />
<TextEditor ref='plain' />
</div>
);
}
}); |
+1 @zpao. |
Good points @zpao. Another place where namespacing has been requested is in props:
Which would transform into:
That sounds like a good idea at first as well, but may also suffer from the same problems @zpao mentioned. |
@shripadk I'm going to wontfix this based on the above. I appreciate the discussion though and love hearing ideas people have for improving the way React works. Keep them coming :) |
It'll be great if one could namespace references to backing instances returned from render.
Silly example:
The text was updated successfully, but these errors were encountered: