Skip to content

Commit 1a1104f

Browse files
committed
Merge pull request #2287 from sebmarkbage/stringelements2
Use strings as the type for DOM elements
2 parents 35764c5 + 3aaccd2 commit 1a1104f

16 files changed

+329
-216
lines changed

src/browser/ReactDOM.js

Lines changed: 134 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,23 @@
2222
var ReactDescriptor = require('ReactDescriptor');
2323
var ReactDescriptorValidator = require('ReactDescriptorValidator');
2424
var ReactLegacyDescriptor = require('ReactLegacyDescriptor');
25-
var ReactDOMComponent = require('ReactDOMComponent');
2625

27-
var mergeInto = require('mergeInto');
2826
var mapObject = require('mapObject');
2927

3028
/**
31-
* Creates a new React class that is idempotent and capable of containing other
32-
* React components. It accepts event listeners and DOM properties that are
33-
* valid according to `DOMProperty`.
29+
* Create a factory that creates HTML tag descriptors.
3430
*
35-
* - Event listeners: `onClick`, `onMouseDown`, etc.
36-
* - DOM properties: `className`, `name`, `title`, etc.
37-
*
38-
* The `style` property functions differently from the DOM API. It accepts an
39-
* object mapping of style properties to values.
40-
*
41-
* @param {boolean} omitClose True if the close tag should be omitted.
4231
* @param {string} tag Tag name (e.g. `div`).
4332
* @private
4433
*/
45-
function createDOMComponentClass(omitClose, tag) {
46-
var Constructor = function(props) {
47-
// This constructor and it's argument is currently used by mocks.
48-
};
49-
Constructor.prototype = new ReactDOMComponent(tag, omitClose);
50-
Constructor.prototype.constructor = Constructor;
51-
Constructor.displayName = tag;
52-
34+
function createDOMFactory(tag) {
5335
if (__DEV__) {
5436
return ReactLegacyDescriptor.wrapFactory(
55-
ReactDescriptorValidator.createFactory(Constructor)
37+
ReactDescriptorValidator.createFactory(tag)
5638
);
5739
}
5840
return ReactLegacyDescriptor.wrapFactory(
59-
ReactDescriptor.createFactory(Constructor)
41+
ReactDescriptor.createFactory(tag)
6042
);
6143
}
6244

@@ -67,145 +49,138 @@ function createDOMComponentClass(omitClose, tag) {
6749
* @public
6850
*/
6951
var ReactDOM = mapObject({
70-
a: false,
71-
abbr: false,
72-
address: false,
73-
area: true,
74-
article: false,
75-
aside: false,
76-
audio: false,
77-
b: false,
78-
base: true,
79-
bdi: false,
80-
bdo: false,
81-
big: false,
82-
blockquote: false,
83-
body: false,
84-
br: true,
85-
button: false,
86-
canvas: false,
87-
caption: false,
88-
cite: false,
89-
code: false,
90-
col: true,
91-
colgroup: false,
92-
data: false,
93-
datalist: false,
94-
dd: false,
95-
del: false,
96-
details: false,
97-
dfn: false,
98-
dialog: false,
99-
div: false,
100-
dl: false,
101-
dt: false,
102-
em: false,
103-
embed: true,
104-
fieldset: false,
105-
figcaption: false,
106-
figure: false,
107-
footer: false,
108-
form: false, // NOTE: Injected, see `ReactDOMForm`.
109-
h1: false,
110-
h2: false,
111-
h3: false,
112-
h4: false,
113-
h5: false,
114-
h6: false,
115-
head: false,
116-
header: false,
117-
hr: true,
118-
html: false,
119-
i: false,
120-
iframe: false,
121-
img: true,
122-
input: true,
123-
ins: false,
124-
kbd: false,
125-
keygen: true,
126-
label: false,
127-
legend: false,
128-
li: false,
129-
link: true,
130-
main: false,
131-
map: false,
132-
mark: false,
133-
menu: false,
134-
menuitem: false, // NOTE: Close tag should be omitted, but causes problems.
135-
meta: true,
136-
meter: false,
137-
nav: false,
138-
noscript: false,
139-
object: false,
140-
ol: false,
141-
optgroup: false,
142-
option: false,
143-
output: false,
144-
p: false,
145-
param: true,
146-
picture: false,
147-
pre: false,
148-
progress: false,
149-
q: false,
150-
rp: false,
151-
rt: false,
152-
ruby: false,
153-
s: false,
154-
samp: false,
155-
script: false,
156-
section: false,
157-
select: false,
158-
small: false,
159-
source: true,
160-
span: false,
161-
strong: false,
162-
style: false,
163-
sub: false,
164-
summary: false,
165-
sup: false,
166-
table: false,
167-
tbody: false,
168-
td: false,
169-
textarea: false, // NOTE: Injected, see `ReactDOMTextarea`.
170-
tfoot: false,
171-
th: false,
172-
thead: false,
173-
time: false,
174-
title: false,
175-
tr: false,
176-
track: true,
177-
u: false,
178-
ul: false,
179-
'var': false,
180-
video: false,
181-
wbr: true,
52+
a: 'a',
53+
abbr: 'abbr',
54+
address: 'address',
55+
area: 'area',
56+
article: 'article',
57+
aside: 'aside',
58+
audio: 'audio',
59+
b: 'b',
60+
base: 'base',
61+
bdi: 'bdi',
62+
bdo: 'bdo',
63+
big: 'big',
64+
blockquote: 'blockquote',
65+
body: 'body',
66+
br: 'br',
67+
button: 'button',
68+
canvas: 'canvas',
69+
caption: 'caption',
70+
cite: 'cite',
71+
code: 'code',
72+
col: 'col',
73+
colgroup: 'colgroup',
74+
data: 'data',
75+
datalist: 'datalist',
76+
dd: 'dd',
77+
del: 'del',
78+
details: 'details',
79+
dfn: 'dfn',
80+
dialog: 'dialog',
81+
div: 'div',
82+
dl: 'dl',
83+
dt: 'dt',
84+
em: 'em',
85+
embed: 'embed',
86+
fieldset: 'fieldset',
87+
figcaption: 'figcaption',
88+
figure: 'figure',
89+
footer: 'footer',
90+
form: 'form',
91+
h1: 'h1',
92+
h2: 'h2',
93+
h3: 'h3',
94+
h4: 'h4',
95+
h5: 'h5',
96+
h6: 'h6',
97+
head: 'head',
98+
header: 'header',
99+
hr: 'hr',
100+
html: 'html',
101+
i: 'i',
102+
iframe: 'iframe',
103+
img: 'img',
104+
input: 'input',
105+
ins: 'ins',
106+
kbd: 'kbd',
107+
keygen: 'keygen',
108+
label: 'label',
109+
legend: 'legend',
110+
li: 'li',
111+
link: 'link',
112+
main: 'main',
113+
map: 'map',
114+
mark: 'mark',
115+
menu: 'menu',
116+
menuitem: 'menuitem',
117+
meta: 'meta',
118+
meter: 'meter',
119+
nav: 'nav',
120+
noscript: 'noscript',
121+
object: 'object',
122+
ol: 'ol',
123+
optgroup: 'optgroup',
124+
option: 'option',
125+
output: 'output',
126+
p: 'p',
127+
param: 'param',
128+
picture: 'picture',
129+
pre: 'pre',
130+
progress: 'progress',
131+
q: 'q',
132+
rp: 'rp',
133+
rt: 'rt',
134+
ruby: 'ruby',
135+
s: 's',
136+
samp: 'samp',
137+
script: 'script',
138+
section: 'section',
139+
select: 'select',
140+
small: 'small',
141+
source: 'source',
142+
span: 'span',
143+
strong: 'strong',
144+
style: 'style',
145+
sub: 'sub',
146+
summary: 'summary',
147+
sup: 'sup',
148+
table: 'table',
149+
tbody: 'tbody',
150+
td: 'td',
151+
textarea: 'textarea',
152+
tfoot: 'tfoot',
153+
th: 'th',
154+
thead: 'thead',
155+
time: 'time',
156+
title: 'title',
157+
tr: 'tr',
158+
track: 'track',
159+
u: 'u',
160+
ul: 'ul',
161+
'var': 'var',
162+
video: 'video',
163+
wbr: 'wbr',
182164

183165
// SVG
184-
circle: false,
185-
defs: false,
186-
ellipse: false,
187-
g: false,
188-
line: false,
189-
linearGradient: false,
190-
mask: false,
191-
path: false,
192-
pattern: false,
193-
polygon: false,
194-
polyline: false,
195-
radialGradient: false,
196-
rect: false,
197-
stop: false,
198-
svg: false,
199-
text: false,
200-
tspan: false
201-
}, createDOMComponentClass);
202-
203-
var injection = {
204-
injectComponentClasses: function(componentClasses) {
205-
mergeInto(ReactDOM, componentClasses);
206-
}
207-
};
166+
circle: 'circle',
167+
defs: 'defs',
168+
ellipse: 'ellipse',
169+
g: 'g',
170+
line: 'line',
171+
linearGradient: 'linearGradient',
172+
mask: 'mask',
173+
path: 'path',
174+
pattern: 'pattern',
175+
polygon: 'polygon',
176+
polyline: 'polyline',
177+
radialGradient: 'radialGradient',
178+
rect: 'rect',
179+
stop: 'stop',
180+
svg: 'svg',
181+
text: 'text',
182+
tspan: 'tspan'
208183

209-
ReactDOM.injection = injection;
184+
}, createDOMFactory);
210185

211186
module.exports = ReactDOM;

src/browser/server/ReactServerRendering.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function renderComponentToString(component) {
4949
transaction = ReactServerRenderingTransaction.getPooled(false);
5050

5151
return transaction.perform(function() {
52-
var componentInstance = instantiateReactComponent(component);
52+
var componentInstance = instantiateReactComponent(component, null);
5353
var markup = componentInstance.mountComponent(id, transaction, 0);
5454
return ReactMarkupChecksum.addChecksumToMarkup(markup);
5555
}, null);
@@ -75,7 +75,7 @@ function renderComponentToStaticMarkup(component) {
7575
transaction = ReactServerRenderingTransaction.getPooled(true);
7676

7777
return transaction.perform(function() {
78-
var componentInstance = instantiateReactComponent(component);
78+
var componentInstance = instantiateReactComponent(component, null);
7979
return componentInstance.mountComponent(id, transaction, 0);
8080
}, null);
8181
} finally {

0 commit comments

Comments
 (0)