Skip to content

Commit 7da9deb

Browse files
committed
refactor: Drop kebab to camel name conversion
1 parent f12ce8c commit 7da9deb

File tree

2 files changed

+0
-46
lines changed

2 files changed

+0
-46
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/browser/index.test.jsx

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -204,41 +204,6 @@ describe('web components', () => {
204204
);
205205
});
206206

207-
describe('attribute/property name transformation', () => {
208-
const kebabName = 'custom-date-long-name';
209-
const camelName = 'customDateLongName';
210-
const lowerName = camelName.toLowerCase();
211-
function PropNameTransform(props) {
212-
return (
213-
<span>
214-
{props[kebabName]} {props[lowerName]} {props[camelName]}
215-
</span>
216-
);
217-
}
218-
registerElement(PropNameTransform, 'x-prop-name-transform', [
219-
kebabName,
220-
camelName,
221-
]);
222-
223-
it('handles kebab-case attributes with passthrough', () => {
224-
const el = document.createElement('x-prop-name-transform');
225-
el.setAttribute(kebabName, '11/11/2011');
226-
el.setAttribute(camelName, 'pretended to be camel');
227-
228-
root.appendChild(el);
229-
assert.equal(
230-
root.innerHTML,
231-
`<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>`
232-
);
233-
234-
el.setAttribute(kebabName, '01/01/2001');
235-
assert.equal(
236-
root.innerHTML,
237-
`<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>`
238-
);
239-
});
240-
});
241-
242207
describe('children', () => {
243208
/** @param {string} name */
244209
function createTestElement(name) {

0 commit comments

Comments
 (0)