Skip to content

Commit

Permalink
Fix softof components use children without args (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
NekR authored and developit committed Dec 12, 2016
1 parent f7489d9 commit 539b9b8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function h(name, attrs) {

// Sortof component support!
if (typeof name==='function') {
if (attrs) attrs.children = stack.reverse();
(attrs || (attrs = {})).children = stack.reverse();
return name(attrs);
// return name(attrs, stack.reverse());
}
Expand Down
51 changes: 51 additions & 0 deletions test/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,57 @@ describe('vhtml', () => {
);
});

it('should support sortof components without args', () => {
let items = ['one', 'two'];

const Item = () => (
<li>
<h4></h4>
</li>
);

expect(
<div class="foo">
<h1>Hi!</h1>
<ul>
{ items.map( (item, index) => (
<Item>
This is item {item}!
</Item>
)) }
</ul>
</div>
).to.equal(
`<div class="foo"><h1>Hi!</h1><ul><li><h4></h4></li><li><h4></h4></li></ul></div>`
);
});

it('should support sortof components without args but with children', () => {
let items = ['one', 'two'];

const Item = ({ children }) => (
<li>
<h4></h4>
{children}
</li>
);

expect(
<div class="foo">
<h1>Hi!</h1>
<ul>
{ items.map( (item, index) => (
<Item>
This is item {item}!
</Item>
)) }
</ul>
</div>
).to.equal(
`<div class="foo"><h1>Hi!</h1><ul><li><h4></h4>This is item one!</li><li><h4></h4>This is item two!</li></ul></div>`
);
});

it('should support empty (void) tags', () => {
expect(
<div>
Expand Down

0 comments on commit 539b9b8

Please sign in to comment.