本文整理匯總了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
}
}
}
}