Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Unable to create plain text nodes #198

Closed
anthonybennett opened this issue Nov 30, 2016 · 1 comment
Closed

BUG: Unable to create plain text nodes #198

anthonybennett opened this issue Nov 30, 2016 · 1 comment

Comments

@anthonybennett
Copy link

If I pass in an undefined "sel", this line blows up, even though everything after that seems to work fine.

https://github.com/snabbdom/snabbdom/blob/master/src/h.ts#L35

@mightyiam
Copy link
Contributor

According to issue creation date, you were looking at

snabbdom/src/h.ts

Lines 35 to 37 in 091dc5f

if (sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g') {
addNS(data, children, sel);
}

And it seems like to this day an undefined first argument to h is not supported:

snabbdom/src/h.ts

Lines 20 to 49 in aac0233

export function h(sel: string): VNode;
export function h(sel: string, data: VNodeData | null): VNode;
export function h(sel: string, children: VNodeChildren): VNode;
export function h(sel: string, data: VNodeData | null, children: VNodeChildren): VNode;
export function h(sel: any, b?: any, c?: any): VNode {
var data: VNodeData = {}, children: any, text: any, i: number;
if (c !== undefined) {
if (b !== null) { 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 && b !== null) {
if (is.array(b)) { children = b; }
else if (is.primitive(b)) { text = b; }
else if (b && b.sel) { children = [b]; }
else { data = b; }
}
if (children !== undefined) {
for (i = 0; i < children.length; ++i) {
if (is.primitive(children[i])) children[i] = vnode(undefined, undefined, undefined, children[i], undefined);
}
}
if (
sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g' &&
(sel.length === 3 || sel[3] === '.' || sel[3] === '#')
) {
addNS(data, children, sel);
}
return vnode(sel, data, children, text, undefined);
};

So I'm going to close this as unsupported. Text nodes can be created as children of elements using h or using vnode in this way:

snabbdom/src/h.ts

Lines 37 to 41 in aac0233

if (children !== undefined) {
for (i = 0; i < children.length; ++i) {
if (is.primitive(children[i])) children[i] = vnode(undefined, undefined, undefined, children[i], undefined);
}
}

Or manually:

snabbdom/src/vnode.ts

Lines 13 to 20 in aac0233

export interface VNode {
sel: string | undefined;
data: VNodeData | undefined;
children: Array<VNode | string> | undefined;
elm: Node | undefined;
text: string | undefined;
key: Key | undefined;
}

Seems like it's something like { text: 'foo' } and that's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants