Skip to content

Commit 9addb8e

Browse files
committed
Component attributes now converts to camelCase before sending to mapStateToProps
1 parent 0ed2860 commit 9addb8e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/connect.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ var _normalizeProps2 = _interopRequireDefault(_normalizeProps);
1414

1515
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1616

17+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18+
1719
function noop() {}
1820

1921
function getStore(component) {
2022
return component.$store;
2123
}
2224

2325
function getAttrs(component) {
24-
return component._self.$options._parentVnode.data.attrs;
26+
var attrs = component._self.$options._parentVnode.data.attrs;
27+
// Convert props from kebab-case to camelCase notation
28+
return Object.keys(attrs).reduce(function (memo, key) {
29+
return _extends({}, memo, _defineProperty({}, key.replace(/[-](.)/g, function (match, group) {
30+
return group.toUpperCase();
31+
}), attrs[key]));
32+
}, {});
2533
}
2634

2735
function getStates(component, mapStateToProps) {

src/connect.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ function getStore(component) {
88
}
99

1010
function getAttrs(component) {
11-
return component._self.$options._parentVnode.data.attrs;
11+
const attrs = component._self.$options._parentVnode.data.attrs;
12+
// Convert props from kebab-case to camelCase notation
13+
return Object.keys(attrs).reduce((memo, key) => ({
14+
...memo,
15+
[key.replace(/[-](.)/g, (match, group) => group.toUpperCase())]: attrs[key],
16+
}), {})
1217
}
1318

1419
function getStates(component, mapStateToProps) {

0 commit comments

Comments
 (0)