本文整理匯總了TypeScript中inferno.createVNode函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createVNode函數的具體用法?TypeScript createVNode怎麽用?TypeScript createVNode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createVNode函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('Patch operation when nextChildren is NOT Invalid/Array/StringOrNumber/VNode', () => {
const validNode = createVNode(
VNodeFlags.HtmlElement,
'span',
null,
createVNode(
VNodeFlags.HtmlElement,
'span',
null,
createTextVNode('a'),
null,
null,
false
),
null,
null,
false
);
const invalidChildNode = createVNode(
VNodeFlags.HtmlElement,
'span',
null,
createVNode(0, 'span'),
null,
null,
false
);
render(validNode, container);
render(invalidChildNode, container);
});
示例2: it
it('Should create new object when dom exists', () => {
const bar = createVNode(2, 'div', null, '123', null, null, true);
const foo = createVNode(2, 'div', null, bar, null, null, true);
render(foo, container);
expect(container.innerHTML).to.eql('<div><div>123</div></div>');
render(null, container);
render(foo, container);
expect(container.innerHTML).to.eql('<div><div>123</div></div>');
});
示例3: renderLink
function renderLink(classNm, children, otherProps) {
return createVNode(
VNodeFlags.HtmlElement,
"a",
classNm,
children,
otherProps
);
}
示例4: hyperscript
/**
* Creates virtual node
* @param {string|VNode|Function} _tag Name for virtual node
* @param {object=} _props Additional properties for virtual node
* @param {string|number|VNode|Array<string|number|VNode>|null=} _children Optional children for virtual node
* @returns {VNode} returns new virtual node
*/
export default function hyperscript(
_tag: string | VNode | Function,
_props?: any,
_children?: InfernoChildren
): VNode {
// If a child array or text node are passed as the second argument, shift them
if (!_children && isChildren(_props)) {
_children = _props;
_props = {};
}
const isElement = isString(_tag);
const { tag, props, key, ref, children, className } = extractProps(
_props,
isElement,
_tag as VNode
);
if (isElement) {
return createVNode(
getFlagsForElementVnode(tag),
tag,
className,
_children || children,
props,
key,
ref
);
} else {
if (children || _children) {
(props as any).children = children || _children;
}
return createVNode(
VNodeFlags.ComponentUnknown,
tag,
className,
null,
props,
key,
ref
);
}
}
示例5: renderIntoDocument
export function renderIntoDocument(input): Wrapper {
const wrappedInput = createVNode(
VNodeFlags.ComponentClass,
Wrapper,
null,
null,
{ children: input }
);
const parent = document.createElement("div");
document.body.appendChild(parent);
return render(wrappedInput, parent) as any;
}
示例6: hyperscript
export default function hyperscript(_tag: string | VNode, _props?: any, _children?: InfernoChildren): VNode {
// If a child array or text node are passed as the second argument, shift them
if (!_children && isChildren(_props)) {
_children = _props;
_props = {};
}
const { tag, props, key, ref, children, events } = extractProps(_props, _tag);
if (isString(tag)) {
let flags = VNodeFlags.HtmlElement;
switch (tag) {
case 'svg':
flags = VNodeFlags.SvgElement;
break;
case 'input':
flags = VNodeFlags.InputElement;
break;
case 'textarea':
flags = VNodeFlags.TextareaElement;
break;
case 'select':
flags = VNodeFlags.SelectElement;
break;
default:
}
return createVNode(flags, tag, props, _children || children, events, key, ref);
} else {
const flags = isStatefulComponent(tag) ? VNodeFlags.ComponentClass : VNodeFlags.ComponentFunction;
if (children) {
(props as any).children = children;
}
return createVNode(flags, tag, props, null, null, key, ref);
}
}
示例7: render
public render(props): VNode | null {
const hit = match(props.children, this.state.url);
if (hit.redirect) {
setTimeout(() => {
this.router.replace(hit.redirect);
}, 0);
return null;
}
return createVNode(VNodeFlags.ComponentClass, RouterContext, null, null, {
location: this.state.url,
matched: hit.matched,
router: this.router
});
}