@samitouri / QOS-React / commits / e5f9ae2705

Avoid object iteration when creating DOM factories (#7493)

Andres Suarez committed Aug 13, 2016 at 19:30 UTC e5f9ae27058052e72d6fb6d89c6ca93075e4089a
1 file changed +138 -144
src/isomorphic/classic/element/ReactDOMFactories.js
+138 -144
@@ -13,20 +13,15 @@
13
14 var ReactElement = require('ReactElement');
15
16 -var mapObject = require('mapObject');
17 -
16 /**
17 * Create a factory that creates HTML tag elements.
18 *
21 - * @param {string} tag Tag name (e.g. `div`).
19 * @private
20 */
24 -function createDOMFactory(tag) {
25 - if (__DEV__) {
26 - var ReactElementValidator = require('ReactElementValidator');
27 - return ReactElementValidator.createFactory(tag);
28 - }
29 - return ReactElement.createFactory(tag);
21 +var createDOMFactory = ReactElement.createFactory;
22 +if (__DEV__) {
23 + var ReactElementValidator = require('ReactElementValidator');
24 + createDOMFactory = ReactElementValidator.createFactory;
25 }
26
27 /**
@@ -35,142 +30,141 @@ function createDOMFactory(tag) {
30 *
31 * @public
32 */
38 -var ReactDOMFactories = mapObject({
39 - a: 'a',
40 - abbr: 'abbr',
41 - address: 'address',
42 - area: 'area',
43 - article: 'article',
44 - aside: 'aside',
45 - audio: 'audio',
46 - b: 'b',
47 - base: 'base',
48 - bdi: 'bdi',
49 - bdo: 'bdo',
50 - big: 'big',
51 - blockquote: 'blockquote',
52 - body: 'body',
53 - br: 'br',
54 - button: 'button',
55 - canvas: 'canvas',
56 - caption: 'caption',
57 - cite: 'cite',
58 - code: 'code',
59 - col: 'col',
60 - colgroup: 'colgroup',
61 - data: 'data',
62 - datalist: 'datalist',
63 - dd: 'dd',
64 - del: 'del',
65 - details: 'details',
66 - dfn: 'dfn',
67 - dialog: 'dialog',
68 - div: 'div',
69 - dl: 'dl',
70 - dt: 'dt',
71 - em: 'em',
72 - embed: 'embed',
73 - fieldset: 'fieldset',
74 - figcaption: 'figcaption',
75 - figure: 'figure',
76 - footer: 'footer',
77 - form: 'form',
78 - h1: 'h1',
79 - h2: 'h2',
80 - h3: 'h3',
81 - h4: 'h4',
82 - h5: 'h5',
83 - h6: 'h6',
84 - head: 'head',
85 - header: 'header',
86 - hgroup: 'hgroup',
87 - hr: 'hr',
88 - html: 'html',
89 - i: 'i',
90 - iframe: 'iframe',
91 - img: 'img',
92 - input: 'input',
93 - ins: 'ins',
94 - kbd: 'kbd',
95 - keygen: 'keygen',
96 - label: 'label',
97 - legend: 'legend',
98 - li: 'li',
99 - link: 'link',
100 - main: 'main',
101 - map: 'map',
102 - mark: 'mark',
103 - menu: 'menu',
104 - menuitem: 'menuitem',
105 - meta: 'meta',
106 - meter: 'meter',
107 - nav: 'nav',
108 - noscript: 'noscript',
109 - object: 'object',
110 - ol: 'ol',
111 - optgroup: 'optgroup',
112 - option: 'option',
113 - output: 'output',
114 - p: 'p',
115 - param: 'param',
116 - picture: 'picture',
117 - pre: 'pre',
118 - progress: 'progress',
119 - q: 'q',
120 - rp: 'rp',
121 - rt: 'rt',
122 - ruby: 'ruby',
123 - s: 's',
124 - samp: 'samp',
125 - script: 'script',
126 - section: 'section',
127 - select: 'select',
128 - small: 'small',
129 - source: 'source',
130 - span: 'span',
131 - strong: 'strong',
132 - style: 'style',
133 - sub: 'sub',
134 - summary: 'summary',
135 - sup: 'sup',
136 - table: 'table',
137 - tbody: 'tbody',
138 - td: 'td',
139 - textarea: 'textarea',
140 - tfoot: 'tfoot',
141 - th: 'th',
142 - thead: 'thead',
143 - time: 'time',
144 - title: 'title',
145 - tr: 'tr',
146 - track: 'track',
147 - u: 'u',
148 - ul: 'ul',
149 - 'var': 'var',
150 - video: 'video',
151 - wbr: 'wbr',
33 +var ReactDOMFactories = {
34 + a: createDOMFactory('a'),
35 + abbr: createDOMFactory('abbr'),
36 + address: createDOMFactory('address'),
37 + area: createDOMFactory('area'),
38 + article: createDOMFactory('article'),
39 + aside: createDOMFactory('aside'),
40 + audio: createDOMFactory('audio'),
41 + b: createDOMFactory('b'),
42 + base: createDOMFactory('base'),
43 + bdi: createDOMFactory('bdi'),
44 + bdo: createDOMFactory('bdo'),
45 + big: createDOMFactory('big'),
46 + blockquote: createDOMFactory('blockquote'),
47 + body: createDOMFactory('body'),
48 + br: createDOMFactory('br'),
49 + button: createDOMFactory('button'),
50 + canvas: createDOMFactory('canvas'),
51 + caption: createDOMFactory('caption'),
52 + cite: createDOMFactory('cite'),
53 + code: createDOMFactory('code'),
54 + col: createDOMFactory('col'),
55 + colgroup: createDOMFactory('colgroup'),
56 + data: createDOMFactory('data'),
57 + datalist: createDOMFactory('datalist'),
58 + dd: createDOMFactory('dd'),
59 + del: createDOMFactory('del'),
60 + details: createDOMFactory('details'),
61 + dfn: createDOMFactory('dfn'),
62 + dialog: createDOMFactory('dialog'),
63 + div: createDOMFactory('div'),
64 + dl: createDOMFactory('dl'),
65 + dt: createDOMFactory('dt'),
66 + em: createDOMFactory('em'),
67 + embed: createDOMFactory('embed'),
68 + fieldset: createDOMFactory('fieldset'),
69 + figcaption: createDOMFactory('figcaption'),
70 + figure: createDOMFactory('figure'),
71 + footer: createDOMFactory('footer'),
72 + form: createDOMFactory('form'),
73 + h1: createDOMFactory('h1'),
74 + h2: createDOMFactory('h2'),
75 + h3: createDOMFactory('h3'),
76 + h4: createDOMFactory('h4'),
77 + h5: createDOMFactory('h5'),
78 + h6: createDOMFactory('h6'),
79 + head: createDOMFactory('head'),
80 + header: createDOMFactory('header'),
81 + hgroup: createDOMFactory('hgroup'),
82 + hr: createDOMFactory('hr'),
83 + html: createDOMFactory('html'),
84 + i: createDOMFactory('i'),
85 + iframe: createDOMFactory('iframe'),
86 + img: createDOMFactory('img'),
87 + input: createDOMFactory('input'),
88 + ins: createDOMFactory('ins'),
89 + kbd: createDOMFactory('kbd'),
90 + keygen: createDOMFactory('keygen'),
91 + label: createDOMFactory('label'),
92 + legend: createDOMFactory('legend'),
93 + li: createDOMFactory('li'),
94 + link: createDOMFactory('link'),
95 + main: createDOMFactory('main'),
96 + map: createDOMFactory('map'),
97 + mark: createDOMFactory('mark'),
98 + menu: createDOMFactory('menu'),
99 + menuitem: createDOMFactory('menuitem'),
100 + meta: createDOMFactory('meta'),
101 + meter: createDOMFactory('meter'),
102 + nav: createDOMFactory('nav'),
103 + noscript: createDOMFactory('noscript'),
104 + object: createDOMFactory('object'),
105 + ol: createDOMFactory('ol'),
106 + optgroup: createDOMFactory('optgroup'),
107 + option: createDOMFactory('option'),
108 + output: createDOMFactory('output'),
109 + p: createDOMFactory('p'),
110 + param: createDOMFactory('param'),
111 + picture: createDOMFactory('picture'),
112 + pre: createDOMFactory('pre'),
113 + progress: createDOMFactory('progress'),
114 + q: createDOMFactory('q'),
115 + rp: createDOMFactory('rp'),
116 + rt: createDOMFactory('rt'),
117 + ruby: createDOMFactory('ruby'),
118 + s: createDOMFactory('s'),
119 + samp: createDOMFactory('samp'),
120 + script: createDOMFactory('script'),
121 + section: createDOMFactory('section'),
122 + select: createDOMFactory('select'),
123 + small: createDOMFactory('small'),
124 + source: createDOMFactory('source'),
125 + span: createDOMFactory('span'),
126 + strong: createDOMFactory('strong'),
127 + style: createDOMFactory('style'),
128 + sub: createDOMFactory('sub'),
129 + summary: createDOMFactory('summary'),
130 + sup: createDOMFactory('sup'),
131 + table: createDOMFactory('table'),
132 + tbody: createDOMFactory('tbody'),
133 + td: createDOMFactory('td'),
134 + textarea: createDOMFactory('textarea'),
135 + tfoot: createDOMFactory('tfoot'),
136 + th: createDOMFactory('th'),
137 + thead: createDOMFactory('thead'),
138 + time: createDOMFactory('time'),
139 + title: createDOMFactory('title'),
140 + tr: createDOMFactory('tr'),
141 + track: createDOMFactory('track'),
142 + u: createDOMFactory('u'),
143 + ul: createDOMFactory('ul'),
144 + 'var': createDOMFactory('var'),
145 + video: createDOMFactory('video'),
146 + wbr: createDOMFactory('wbr'),
147
148 // SVG
154 - circle: 'circle',
155 - clipPath: 'clipPath',
156 - defs: 'defs',
157 - ellipse: 'ellipse',
158 - g: 'g',
159 - image: 'image',
160 - line: 'line',
161 - linearGradient: 'linearGradient',
162 - mask: 'mask',
163 - path: 'path',
164 - pattern: 'pattern',
165 - polygon: 'polygon',
166 - polyline: 'polyline',
167 - radialGradient: 'radialGradient',
168 - rect: 'rect',
169 - stop: 'stop',
170 - svg: 'svg',
171 - text: 'text',
172 - tspan: 'tspan',
173 -
174 -}, createDOMFactory);
149 + circle: createDOMFactory('circle'),
150 + clipPath: createDOMFactory('clipPath'),
151 + defs: createDOMFactory('defs'),
152 + ellipse: createDOMFactory('ellipse'),
153 + g: createDOMFactory('g'),
154 + image: createDOMFactory('image'),
155 + line: createDOMFactory('line'),
156 + linearGradient: createDOMFactory('linearGradient'),
157 + mask: createDOMFactory('mask'),
158 + path: createDOMFactory('path'),
159 + pattern: createDOMFactory('pattern'),
160 + polygon: createDOMFactory('polygon'),
161 + polyline: createDOMFactory('polyline'),
162 + radialGradient: createDOMFactory('radialGradient'),
163 + rect: createDOMFactory('rect'),
164 + stop: createDOMFactory('stop'),
165 + svg: createDOMFactory('svg'),
166 + text: createDOMFactory('text'),
167 + tspan: createDOMFactory('tspan'),
168 +};
169
170 module.exports = ReactDOMFactories;