本文整理汇总了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)] : []
}
}
开发者ID:lineCode,项目名称:nerv,代码行数:7,代码来源:devtools.ts
示例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
}
开发者ID:lineCode,项目名称:nerv,代码行数:26,代码来源:h.ts
示例3: unmountComponentAtNode
export function unmountComponentAtNode (dom) {
const component = dom._component
if (isValidElement(component)) {
unmount(component, dom)
delete dom._component
return true
}
return false
}
开发者ID:lineCode,项目名称:nerv,代码行数:9,代码来源:dom.ts
示例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)
}
}
}
开发者ID:lineCode,项目名称:nerv,代码行数:15,代码来源:h.ts
示例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
}
开发者ID:lineCode,项目名称:nerv,代码行数:39,代码来源:create-element.ts
示例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
}
}
}
}
开发者ID:lineCode,项目名称:nerv,代码行数:69,代码来源:patch.ts
注:本文中的nerv-shared.isValidElement函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论