本文整理汇总了TypeScript中nerv-shared.isValidElement函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isValidElement函数的具体用法?TypeScript isValidElement怎么用?TypeScript isValidElement使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isValidElement函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: normalizeChildren
function normalizeChildren (children) {
if (isArray(children)) {
return children.filter(isValidElement).map(updateReactComponent)
} else {
return isValidElement(children) ? [updateReactComponent(children)] : []
}
}
示例2: h
function h (type: string, props: Props, children?: VirtualChildren) {
let childNodes
if (props.children) {
if (!children) {
children = props.children
}
delete props.children
}
if (isArray(children)) {
childNodes = []
addChildren(childNodes, children as any, type)
} else if (isString(children) || isNumber(children)) {
children = createVText(String(children))
} else if (!isValidElement(children)) {
children = EMPTY_CHILDREN
}
return createVNode(
type,
props,
childNodes !== undefined ? childNodes : children,
props.key,
props.namespace,
props.owner,
props.ref
) as VNode
}
示例3: unmountComponentAtNode
export function unmountComponentAtNode (dom) {
const component = dom._component
if (isValidElement(component)) {
unmount(component, dom)
delete dom._component
return true
}
return false
}
示例4: addChildren
function addChildren (
childNodes: VirtualNode[],
children: VirtualNode | VirtualNode[],
type: string
) {
if (isString(children) || isNumber(children)) {
childNodes.push(createVText(String(children)))
} else if (isValidElement(children)) {
childNodes.push(children)
} else if (isArray(children)) {
for (let i = 0; i < children.length; i++) {
addChildren(childNodes, children[i], type)
}
}
}
示例5: createElement
function createElement (
vnode: VirtualNode | VirtualNode[],
isSvg?: boolean,
parentContext?,
parentComponent?
): Element | Text | Comment | DocumentFragment | null {
let domNode
if (isValidElement(vnode)) {
const vtype = vnode.vtype
if (vtype & (VType.Composite | VType.Stateless)) {
domNode = (vnode as CompositeComponent).init(parentContext, parentComponent)
options.afterMount(vnode as CompositeComponent)
} else if (vtype & VType.Text) {
domNode = doc.createTextNode((vnode as any).text);
(vnode as any).dom = domNode
} else if (vtype & VType.Node) {
domNode = mountVNode(vnode as any, isSvg, parentContext, parentComponent)
} else if (vtype & VType.Void) {
domNode = (vnode as any).dom
}
} else if (isString(vnode) || isNumber(vnode)) {
domNode = doc.createTextNode(vnode as string)
} else if (isNullOrUndef(vnode) || (vnode as any) === false) {
domNode = doc.createTextNode('')
} else if (isArray(vnode)) {
domNode = doc.createDocumentFragment()
vnode.forEach((child) => {
if (!isInvalid(child)) {
const childNode = createElement(child, isSvg, parentContext, parentComponent)
if (childNode) {
domNode.appendChild(childNode)
}
}
})
} else {
throw new Error('Unsupported VNode.')
}
return domNode
}
示例6: patchProp
export function patchProp (
domNode: Element,
prop: string,
lastValue,
nextValue,
lastVnode: VNode | null,
isSvg?: boolean
) {
if (lastValue !== nextValue) {
if (prop === 'className') {
prop = 'class'
}
if (skipProps[prop] === 1) {
return
} else if (prop === 'class' && !isSvg) {
domNode.className = nextValue
} else if (prop === 'dangerouslySetInnerHTML') {
const lastHtml = lastValue && lastValue.__html
const nextHtml = nextValue && nextValue.__html
if (lastHtml !== nextHtml) {
if (!isNullOrUndef(nextHtml)) {
if (
isValidElement(lastVnode) &&
lastVnode.children !== EMPTY_CHILDREN
) {
unmountChildren(lastVnode.children)
lastVnode.children = []
}
domNode.innerHTML = nextHtml
}
}
} else if (isAttrAnEvent(prop)) {
patchEvent(prop, lastValue, nextValue, domNode)
} else if (prop === 'style') {
patchStyle(lastValue, nextValue, domNode)
} else if (
prop !== 'list' &&
prop !== 'type' &&
!isSvg &&
prop in domNode
) {
setProperty(domNode, prop, nextValue == null ? '' : nextValue)
if (nextValue == null || nextValue === false) {
domNode.removeAttribute(prop)
}
} else if (isNullOrUndef(nextValue) || nextValue === false) {
domNode.removeAttribute(prop)
} else {
const namespace = SVGPropertyConfig.DOMAttributeNamespaces[prop]
if (isSvg && namespace) {
if (nextValue) {
domNode.setAttributeNS(namespace, prop, nextValue)
} else {
const colonPosition = prop.indexOf(':')
const localName =
colonPosition > -1 ? prop.substr(colonPosition + 1) : prop
domNode.removeAttributeNS(namespace, localName)
}
} else {
if (!isFunction(nextValue)) {
domNode.setAttribute(prop, nextValue)
}
// WARNING: Non-event attributes with function values:
// https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html#changes-in-detail
}
}
}
}