Use strings as the type for DOM elements#2287
Conversation
This makes ReactDOM a simple helper for creating ReactElements with the string tag as the type. The actual class is internal and created by instantiateReactComponent. Configurable using injection. There's not a separate class for each tag. There's just a generic ReactDOMComponent which could take any tag name. Invididual tags can be wrapped. When wrapping happens you can return the same tag again. If the wrapper returns the same string, then we fall back to the generic component. This avoids recursion in a single level wrapper.
2abc06b to
3aaccd2
Compare
There was a problem hiding this comment.
This still being an object seems fairly useless, why not an array?
There was a problem hiding this comment.
Helps with closure compiler advanced mode minification. Since we need both identifier symbol and the string symbol. If identifiers are renamed, then we lose the string. Also helps type systems to figure out the signature of the resulting object.
There was a problem hiding this comment.
@sebmarkbage Huh? mapObject({a: 'a', ...}, createDOMFactory); function createDOMFactory(tag) { ... as far as I can make out the key is discarded and never used... ?
There was a problem hiding this comment.
The key is used on the resulting object:
react/src/vendor/core/mapObject.js
Line 52 in aae31ae
Meaning that React.DOM.div is the identifier name that can be mungled to a.b.c.
Use strings as the type for DOM elements
This makes ReactDOM a simple helper for creating ReactElements with the string tag as the type. The actual class is internal and created by instantiateReactComponent. Configurable using injection.
There's not a separate class for each tag. There's just a generic ReactDOMComponent which could take any tag name.
Invididual tags can be wrapped. When wrapping happens you can return the same tag again. If the wrapper returns the same string, then we fall back to the generic component. This avoids recursion in a single level wrapper.