Skip to content

Commit e47d055

Browse files
Create config that maps out DOM attributes to React props
The config will be used when converting DOM node attributes to React props. Map out the following: - DOM attribute names - standard properties - RDFa properties - non-standard properties Used React's HTMLDOMPropertyConfig as source: https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
1 parent 1406e3c commit e47d055

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/property-config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig');
7+
var utilities = require('./utilities');
8+
9+
// first map out the DOM attribute names
10+
// e.g., { className: 'class' } => { class: 'className' }
11+
// https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L204
12+
var config = utilities.invertObject(
13+
HTMLDOMPropertyConfig.DOMAttributeNames
14+
);
15+
16+
// then map out the rest of the DOM properties
17+
// e.g., { charSet: 0 } => { charset: 'charSet' }
18+
// https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L28
19+
for (var key in HTMLDOMPropertyConfig.Properties) {
20+
config[key.toLowerCase()] = key;
21+
}
22+
23+
/**
24+
* Export React property config.
25+
*/
26+
module.exports = config;

0 commit comments

Comments
 (0)