本文整理汇总了TypeScript中nerv-shared.isInvalid函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isInvalid函数的具体用法?TypeScript isInvalid怎么用?TypeScript isInvalid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isInvalid函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: unmount
export function unmount (vnode, parentDom?) {
if (isInvalid(vnode)) {
return
}
const vtype = vnode.vtype
// Bitwise operators for better performance
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
const dom = vtype & VType.Composite ? vnode.component.dom : vnode.dom
if ((vtype & (VType.Composite | VType.Stateless)) > 0) {
options.beforeUnmount(vnode)
vnode.destroy()
} else if ((vtype & VType.Node) > 0) {
const { props, children, ref } = vnode
unmountChildren(children)
for (const propName in props) {
if (isAttrAnEvent(propName)) {
detachEvent(dom, propName, props[propName])
}
}
if (ref !== null) {
Ref.detach(vnode, ref, dom)
}
}
if (!isNullOrUndef(parentDom) && !isNullOrUndef(dom)) {
parentDom.removeChild(dom)
}
// vnode.dom = null
}
开发者ID:lineCode,项目名称:nerv,代码行数:30,代码来源:unmount.ts
示例2: createElement
vnode.forEach((child) => {
if (!isInvalid(child)) {
const childNode = createElement(child, isSvg, parentContext, parentComponent)
if (childNode) {
domNode.appendChild(childNode)
}
}
})
开发者ID:lineCode,项目名称:nerv,代码行数:8,代码来源:create-element.ts
示例3: isSameVNode
function isSameVNode (a, b) {
if (isInvalid(a) || isInvalid(b)) {
return false
}
return a.type === b.type && a.key === b.key
}
开发者ID:lineCode,项目名称:nerv,代码行数:6,代码来源:patch.ts
示例4: forEach
return children.map(fn)
},
forEach (
children: Array<VirtualChildren | any>,
fn: IterateFn,
ctx: any
): void {
if (isNullOrUndef(children)) {
return
}
children = Children.toArray(children)
if (ctx && ctx !== children) {
fn = fn.bind(ctx)
}
for (let i = 0, len = children.length; i < len; i++) {
const child = isInvalid(children[i]) ? null : children[i]
fn(child, i, children)
}
},
count (children: Array<VirtualChildren | any>): number {
children = Children.toArray(children)
return children.length
},
only (children: Array<VirtualChildren | any>): VirtualChildren | any {
children = Children.toArray(children)
if (children.length !== 1) {
throw new Error('Children.only() expects only one child.')
}
return children[0]
},
开发者ID:lineCode,项目名称:nerv,代码行数:31,代码来源:children.ts
示例5: renderVNodeToString
function renderVNodeToString (vnode, parent, context, isSvg?: boolean) {
if (isInvalid(vnode)) {
return ''
}
const { type, props, children } = vnode
if (isVText(vnode)) {
return encodeEntities(vnode.text)
} else if (isVNode(vnode)) {
let renderedString = `<${type}`
let html
if (!isNullOrUndef(props)) {
for (let prop in props) {
const value = props[prop]
if (skipAttributes[prop]) {
continue
}
if (prop === 'dangerouslySetInnerHTML') {
html = value.__html
} else if (prop === 'style') {
const styleStr = renderStylesToString(value)
renderedString += styleStr ? ` style="${renderStylesToString(value)}"` : ''
} else if (prop === 'class' || prop === 'className') {
renderedString += ` class="${isString(value)
? value
: hashToClassName(value)}"`
} else if (prop === 'defaultValue') {
if (!props.value) {
renderedString += ` value="${encodeEntities(value)}"`
}
} else if (prop === 'defaultChecked') {
if (!props.checked) {
renderedString += ` checked="${value}"`
}
} else if (isSvg && prop.match(/^xlink\:?(.+)/)) {
prop = prop.toLowerCase().replace(/^xlink\:?(.+)/, 'xlink:$1')
renderedString += ` ${prop}="${encodeEntities(value)}"`
} else {
if (isString(value)) {
renderedString += ` ${prop}="${encodeEntities(value)}"`
} else if (isNumber(value)) {
renderedString += ` ${prop}="${value}"`
} else if (value === true) {
renderedString += ` ${prop}`
}
}
}
}
if (isVoidElements[type]) {
renderedString += `/>`
} else {
renderedString += `>`
if (html) {
renderedString += html
} else if (!isInvalid(children)) {
if (isString(children)) {
renderedString += children === '' ? ' ' : encodeEntities(children)
} else if (isNumber(children)) {
renderedString += children + ''
} else if (isArray(children)) {
for (let i = 0, len = children.length; i < len; i++) {
const child = children[i]
if (isString(child)) {
renderedString += child === '' ? ' ' : encodeEntities(child)
} else if (isNumber(child)) {
renderedString += child
} else if (!isInvalid(child)) {
isSvg = type === 'svg' ? true : type === 'foreignObject' ? false : isSvg
renderedString += renderVNodeToString(
child,
vnode,
context,
isSvg
)
}
}
} else {
isSvg = type === 'svg' ? true : type === 'foreignObject' ? false : isSvg
renderedString += renderVNodeToString(children, vnode, context, isSvg)
}
}
if (!isVoidElements[type]) {
renderedString += `</${type}>`
}
}
return renderedString
} else if (isComposite(vnode)) {
const instance = new type(props, context)
instance._disable = true
instance.props = props
instance.context = context
if (isFunction(instance.componentWillMount)) {
instance.componentWillMount()
}
const rendered = instance.render()
if (isFunction(instance.getChildContext)) {
context = extend(clone(context), instance.getChildContext())
}
return renderVNodeToString(rendered, vnode, context, isSvg)
} else if (isStateless(vnode)) {
const rendered = type(props, context)
//.........这里部分代码省略.........
开发者ID:lineCode,项目名称:nerv,代码行数:101,代码来源:index.ts
注:本文中的nerv-shared.isInvalid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论