本文整理汇总了TypeScript中nerv-utils.isString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isString函数的具体用法?TypeScript isString怎么用?TypeScript isString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isString函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
function createElement<T> (
type: string | Function | Component<any, any>,
properties?: T & Props | null,
..._children: Array<VirtualChildren | null>
) {
let children: any = _children
if (_children) {
if (_children.length === 1) {
children = _children[0]
} else if (_children.length === 0) {
children = undefined
}
}
let props
if (isString(type)) {
props = transformPropsForRealTag(type, properties as Props)
props.owner = CurrentOwner.current
return h(type, props, children as any) as VNode
} else if (isFunction(type)) {
props = transformPropsForComponent(
properties as any,
(type as any).defaultProps
)
if (!props.children) {
props.children = children || EMPTY_CHILDREN
}
props.owner = CurrentOwner.current
return type.prototype && type.prototype.render
? new FullComponent(type, props)
: new StatelessComponent(type, props)
}
return type
}
示例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: renderStylesToString
function renderStylesToString (styles: string | object): string {
if (isString(styles)) {
return styles
} else {
let renderedString = ''
for (const styleName in styles) {
const value = styles[styleName]
if (isString(value)) {
renderedString += `${getCssPropertyName(styleName)}${value};`
} else if (isNumber(value)) {
renderedString += `${getCssPropertyName(
styleName
)}${value}${isUnitlessNumber[styleName] ? '' : 'px'};`
}
}
return renderedString
}
}
示例4: patchStyle
function patchStyle (lastAttrValue, nextAttrValue, dom) {
const domStyle = dom.style
let style
let value
if (isString(nextAttrValue)) {
domStyle.cssText = nextAttrValue
return
}
if (!isNullOrUndef(lastAttrValue) && !isString(lastAttrValue)) {
for (style in nextAttrValue) {
value = nextAttrValue[style]
if (value !== lastAttrValue[style]) {
setStyle(domStyle, style, value)
}
}
} else {
for (style in nextAttrValue) {
value = nextAttrValue[style]
setStyle(domStyle, style, value)
}
}
}
示例5: renderComponent
export function renderComponent (component: Component<any, any>) {
CurrentOwner.current = component
let rendered
errorCatcher(() => {
rendered = component.render()
}, component)
if (isNumber(rendered) || isString(rendered)) {
rendered = createVText(rendered)
} else if (isUndefined(rendered)) {
rendered = createVoid()
}
CurrentOwner.current = null
return rendered
}
示例6: 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)
}
}
}
示例7: cloneElement
export default function cloneElement (vnode, props?: object, ...children): any {
if (isVText(vnode)) {
vnode.dom = null
return vnode
}
if (isString(vnode)) {
return createVText(vnode)
}
const properties = clone(extend(clone(vnode.props), props))
if (vnode.namespace) {
properties.namespace = vnode.namespace
}
let childrenTmp =
(arguments.length > 2 ?
[].slice.call(arguments, 2) :
vnode.children || properties.children) || []
if (childrenTmp.length) {
if (childrenTmp.length === 1) {
childrenTmp = children[0]
}
}
if (isArray(vnode)) {
return vnode.map((item) => {
return cloneElement(item)
})
}
const newVNode = createElement(vnode.type, properties)
if (isArray(childrenTmp)) {
const _children = childrenTmp.map((child) => {
return cloneElement(child, child.props)
})
if (isVNode(newVNode)) {
newVNode.children = _children
}
newVNode.props.children = _children
} else if (childrenTmp) {
if (isVNode(newVNode)) {
newVNode.children = childrenTmp
}
newVNode.props.children = cloneElement(childrenTmp, childrenTmp.props)
}
return newVNode
}
示例8: 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
}
示例9: isVChild
function isVChild (vnode): vnode is string | number | VNode {
return isVNode(vnode) || isString(vnode) || isNumber(vnode)
}
示例10: update
update (lastVnode, nextVnode, domNode?) {
const prevRef = lastVnode != null && lastVnode.props.ref
const nextRef = nextVnode != null && nextVnode.props.ref
if (prevRef !== nextRef) {
if (!isFunction(prevRef) || !isFunction(nextRef)) {
this.detach(lastVnode, prevRef, lastVnode.dom)
}
this.attach(nextVnode, nextRef, domNode)
}
},
attach (vnode, ref, domNode: Element) {
const node = isComposite(vnode) ? vnode.component : domNode
if (isFunction(ref)) {
ref(node)
} else if (isString(ref)) {
const inst = vnode._owner
if (inst && isFunction(inst.render)) {
inst.refs[ref] = node
}
}
},
detach (vnode, ref, domNode: Element) {
const node = isComposite(vnode) ? vnode.component : domNode
if (isFunction(ref)) {
ref(null)
} else if (isString(ref)) {
const inst = vnode._owner
if (inst.refs[ref] === node && isFunction(inst.render)) {
delete inst.refs[ref]
}