Allow h(sel, data, node) and h(sel, node) shortcut notations

pull/195/head
Alexandre Galays 8 years ago committed by André Staltz
parent 8286862fae
commit 5a5c0dc121

@ -22,9 +22,11 @@ export function h(sel: any, b?: any, c?: any): VNode {
data = b;
if (is.array(c)) { children = c; }
else if (is.primitive(c)) { text = c; }
else if (c && c.sel) { children = [c]; }
} else if (b !== undefined) {
if (is.array(b)) { children = b; }
else if (is.primitive(b)) { text = b; }
else if (b && b.sel) { children = [b]; }
else { data = b; }
}
if (is.array(children)) {
@ -37,4 +39,4 @@ export function h(sel: any, b?: any, c?: any): VNode {
}
return vnode(sel, data, children, text, undefined);
};
export default h;
export default h;

@ -42,6 +42,16 @@ describe('snabbdom', function() {
assert.equal(vnode.children[0].sel, 'span#hello');
assert.equal(vnode.children[1].sel, 'b.world');
});
it('can create vnode with one child vnode', function() {
var vnode = h('div', h('span#hello'));
assert.equal(vnode.sel, 'div');
assert.equal(vnode.children[0].sel, 'span#hello');
});
it('can create vnode with props and one child vnode', function() {
var vnode = h('div', {}, h('span#hello'));
assert.equal(vnode.sel, 'div');
assert.equal(vnode.children[0].sel, 'span#hello');
});
it('can create vnode with text content', function() {
var vnode = h('a', ['I am a string']);
assert.equal(vnode.children[0].text, 'I am a string');

Loading…
Cancel
Save