Skip to content

Commit d6274b9

Browse files
feat(attributes-to-props): replace react-dom with react-property
Save `[email protected]` to package.json dependencies and remove `react-dom-core`. Delete `lib/property-config.js` given that the mapping is already created in `react-property`. Fix incorrect test since both `ychannelselector` and `yChannelSelector` are applicable SVG attribute names. Resolves #107
1 parent 0ae8a11 commit d6274b9

File tree

4 files changed

+18
-77
lines changed

4 files changed

+18
-77
lines changed

lib/attributes-to-props.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
var DOMProperty = require('react-dom-core/lib/DOMProperty');
2-
var propertyConfig = require('./property-config');
1+
var reactProperty = require('react-property');
32
var styleToObject = require('style-to-object');
43
var utilities = require('./utilities');
5-
var camelCase = utilities.camelCase;
64

7-
var config = propertyConfig.config;
8-
var isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute;
9-
DOMProperty.injection.injectDOMPropertyConfig(
10-
propertyConfig.HTMLDOMPropertyConfig
11-
);
5+
var camelCase = utilities.camelCase;
6+
var HTMLDOMPropertyConfig = reactProperty.HTMLDOMPropertyConfig;
7+
var SVGDOMPropertyConfig = reactProperty.SVGDOMPropertyConfig;
8+
var isCustomAttribute = reactProperty.isCustomAttribute;
129

1310
/**
1411
* Converts HTML/SVG DOM attributes to React props.
@@ -34,30 +31,24 @@ function attributesToProps(attributes) {
3431
}
3532

3633
// convert HTML attribute to React prop
37-
property = config.html[attributeName.toLowerCase()];
34+
property = HTMLDOMPropertyConfig[attributeName.toLowerCase()];
3835
if (property) {
39-
if (
40-
Object.prototype.hasOwnProperty.call(
41-
DOMProperty.properties,
42-
property
43-
) &&
44-
DOMProperty.properties[property].hasBooleanValue
45-
) {
46-
props[property] = true;
36+
if (property.hasBooleanValue) {
37+
props[property.propertyName] = true;
4738
} else {
48-
props[property] = attributeValue;
39+
props[property.propertyName] = attributeValue;
4940
}
5041
continue;
5142
}
5243

5344
// convert SVG attribute to React prop
54-
property = config.svg[attributeName];
45+
property = SVGDOMPropertyConfig[attributeName];
5546
if (property) {
56-
props[property] = attributeValue;
47+
props[property.propertyName] = attributeValue;
5748
continue;
5849
}
5950

60-
// custom attribute
51+
// preserve custom attribute if React >=16
6152
if (utilities.PRESERVE_CUSTOM_ATTRIBUTES) {
6253
props[attributeName] = attributeValue;
6354
}

lib/property-config.js

-50
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dependencies": {
3838
"@types/domhandler": "2.4.1",
3939
"html-dom-parser": "0.2.2",
40-
"react-dom-core": "0.1.1",
40+
"react-property": "0.1.0",
4141
"style-to-object": "0.2.3"
4242
},
4343
"devDependencies": {

test/attributes-to-props.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ describe('attributesToProps', () => {
135135
);
136136
});
137137

138-
it('includes but does not convert incorrectly capitalized properties', () => {
138+
it('keeps incorrectly capitalized attributes', () => {
139139
assert.deepEqual(
140140
attributesToProps({
141141
'XLINK:HREF': '#',
142-
ychannelselector: 'G',
142+
YChannelSelector: 'G',
143143
ZoomAndPan: 'disable'
144144
}),
145145
{
146146
'XLINK:HREF': '#',
147-
ychannelselector: 'G',
147+
YChannelSelector: 'G',
148148
ZoomAndPan: 'disable'
149149
}
150150
);
@@ -253,11 +253,11 @@ describe('attributesToProps', () => {
253253
);
254254
});
255255

256-
it('does not include incorrectly capitalized properties', () => {
256+
it('omits incorrectly capitalized attributes', () => {
257257
assert.deepEqual(
258258
attributesToProps({
259259
'XLINK:HREF': '#',
260-
ychannelselector: 'G',
260+
YChannelSelector: 'G',
261261
ZoomAndPan: 'disable'
262262
}),
263263
{}

0 commit comments

Comments
 (0)