Skip to content

Commit cd588d4

Browse files
committed
refactor: Drop kebab to camel name conversion
1 parent e27626e commit cd588d4

File tree

2 files changed

+0
-44
lines changed

2 files changed

+0
-44
lines changed

src/index.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ function connectedCallback(options) {
118118
(this.hasAttribute('hydrate') ? hydrate : render)(this._vdom, this._root);
119119
}
120120

121-
/**
122-
* Camel-cases a string
123-
* @param {string} str The string to transform to camelCase
124-
* @returns camel case version of the string
125-
*/
126-
function toCamelCase(str) {
127-
return str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : ''));
128-
}
129-
130121
/**
131122
* Changed whenver an attribute of the HTML element changed
132123
* @this {PreactCustomElement}
@@ -143,7 +134,6 @@ function attributeChangedCallback(name, oldValue, newValue) {
143134
newValue = newValue == null ? undefined : newValue;
144135
const props = {};
145136
props[name] = newValue;
146-
props[toCamelCase(name)] = newValue;
147137
this._vdom = cloneElement(this._vdom, props);
148138
render(this._vdom, this._root);
149139
}
@@ -192,7 +182,6 @@ function toVdom(element, nodeName, options) {
192182
for (i = a.length; i--; ) {
193183
if (a[i].name !== 'slot') {
194184
props[a[i].name] = a[i].value;
195-
props[toCamelCase(a[i].name)] = a[i].value;
196185
}
197186
}
198187

test/index.test.jsx

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -210,39 +210,6 @@ describe('web components', () => {
210210
);
211211
});
212212

213-
const kebabName = 'custom-date-long-name';
214-
const camelName = 'customDateLongName';
215-
const lowerName = camelName.toLowerCase();
216-
function PropNameTransform(props) {
217-
return (
218-
<span>
219-
{props[kebabName]} {props[lowerName]} {props[camelName]}
220-
</span>
221-
);
222-
}
223-
registerElement(PropNameTransform, 'x-prop-name-transform', [
224-
kebabName,
225-
camelName,
226-
]);
227-
228-
it('handles kebab-case attributes with passthrough', () => {
229-
const el = document.createElement('x-prop-name-transform');
230-
el.setAttribute(kebabName, '11/11/2011');
231-
el.setAttribute(camelName, 'pretended to be camel');
232-
233-
root.appendChild(el);
234-
assert.equal(
235-
root.innerHTML,
236-
`<x-prop-name-transform ${kebabName}="11/11/2011" ${lowerName}="pretended to be camel"><span>11/11/2011 pretended to be camel 11/11/2011</span></x-prop-name-transform>`
237-
);
238-
239-
el.setAttribute(kebabName, '01/01/2001');
240-
assert.equal(
241-
root.innerHTML,
242-
`<x-prop-name-transform ${kebabName}="01/01/2001" ${lowerName}="pretended to be camel"><span>01/01/2001 pretended to be camel 01/01/2001</span></x-prop-name-transform>`
243-
);
244-
});
245-
246213
const Theme = createContext('light');
247214

248215
function DisplayTheme() {

0 commit comments

Comments
 (0)