Skip to content

Commit

Permalink
Feature/attributes (#9)
Browse files Browse the repository at this point in the history
* Remove special properties

parcel@next (2) introduce these special properties to map back to where the element originates.
Neat stuff. Crashes everything.

* Make sure domdom doesn't crash and burn when a attribute is undefined

* 4.11.12
  • Loading branch information
eirikb authored Jun 18, 2020
1 parent be60e3d commit 807fbbb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eirikb/domdom",
"version": "4.11.11",
"version": "4.11.12",
"description": "The proactive web front-end framework for the unprofessional",
"scripts": {
"build": "tsdx build",
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ export function domdom(parent?: HTMLElement, view?: Domponent): Domdom | Data {
}
}

for (let [key, value] of Object.entries(props || {})) {
for (let [key, value] of Object.entries(props || {}).filter(
([key]) => !key.startsWith('__')
)) {
const valueAsHodor = value as Hodor;
if (valueAsHodor.isHodor) {
if (valueAsHodor && valueAsHodor.isHodor) {
valueAsHodor.element = element;
}

Expand All @@ -79,7 +81,7 @@ export function domdom(parent?: HTMLElement, view?: Domponent): Domdom | Data {
const event = key[2].toLowerCase() + key.slice(3);
element.addEventListener(event, (...args) => {
const valueFn = value as Function;
if (valueFn !== null) {
if (valueFn !== undefined) {
return valueFn(...args);
}
});
Expand Down
5 changes: 5 additions & 0 deletions test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1539,3 +1539,8 @@ test('on with properties', async t => {
});
t.is(await html(), '<div><div>a: A!</div><div>b: B!</div></div>');
});

test('properties without value should not crash', async t => {
append(document.body, () => <div style={undefined}></div>);
t.is(await html(), '<div style=""></div>');
});

0 comments on commit 807fbbb

Please sign in to comment.