本文整理汇总了TypeScript中inferno-shared.isStringOrNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isStringOrNumber函数的具体用法?TypeScript isStringOrNumber怎么用?TypeScript isStringOrNumber使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isStringOrNumber函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createReactDOMComponent
/**
* Create a ReactDOMComponent-compatible object for a given DOM node rendered
* by Inferno.
*
* This implements the subset of the ReactDOMComponent interface that
* React DevTools requires in order to display DOM nodes in the inspector with
* the correct type and properties.
*/
function createReactDOMComponent(vNode, parentDom) {
const flags = vNode.flags;
if (flags & VNodeFlags.Void) {
return null;
}
const type = vNode.type;
const children =
vNode.children === 0 ? vNode.children.toString() : vNode.children;
const props = vNode.props;
const dom = vNode.dom;
const isText = flags & VNodeFlags.Text || isStringOrNumber(vNode);
return {
_currentElement: isText
? children || vNode
: {
props,
type
},
_inDevTools: false,
_renderedChildren: !isText && normalizeChildren(children, dom),
_stringText: isText ? (children || vNode).toString() : null,
node: dom || parentDom,
vNode
};
}
示例2: validateNodeTree
export function validateNodeTree(node: any): boolean {
if (!node) {
return true;
}
if (isStringOrNumber(node)) {
return true;
}
if (!node.dom) {
return false;
}
const children = node.children;
const flags = node.flags;
if ((flags & VNodeFlags.Element) > 0) {
if (!isNullOrUndef(children)) {
if (isArray(children)) {
for (const child of children) {
const val = validateNodeTree(child);
if (!val) {
return false;
}
}
} else {
const val = validateNodeTree(children);
if (!val) {
return false;
}
}
}
}
return true;
}
示例3: _normalizeVNodes
function _normalizeVNodes(
nodes: any[],
result: VNode[],
index: number,
currentKey
) {
for (const len = nodes.length; index < len; index++) {
let n = nodes[index];
const key = `${currentKey}.${index}`;
if (!isInvalid(n)) {
if (isArray(n)) {
_normalizeVNodes(n, result, 0, key);
} else {
if (isStringOrNumber(n)) {
n = createTextVNode(n, null);
} else if ((isVNode(n) && n.dom) || (n.key && n.key[0] === ".")) {
n = directClone(n);
}
if (isNull(n.key) || n.key[0] === ".") {
n = applyKey(key, n as VNode);
} else {
n = applyKeyPrefix(currentKey, n as VNode);
}
result.push(n);
}
}
}
}
示例4: createFunctionalComponentInput
export function createFunctionalComponentInput(
vNode: VNode,
component,
props: Props,
context: Object
) {
let input = component(props, context);
if (isArray(input)) {
if (process.env.NODE_ENV !== "production") {
throwError(
"a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object."
);
}
throwError();
} else if (isInvalid(input)) {
input = createVoidVNode();
} else if (isStringOrNumber(input)) {
input = createTextVNode(input, null);
} else {
if (input.dom) {
input = directClone(input);
}
if (input.flags & VNodeFlags.Component) {
// if we have an input that is also a component, we run into a tricky situation
// where the root vNode needs to always have the correct DOM entry
// so we break monomorphism on our input and supply it our vNode as parentVNode
// we can optimise this in the future, but this gets us out of a lot of issues
input.parentVNode = vNode;
}
}
return input;
}
示例5: hydrateChildren
function hydrateChildren(
children: InfernoChildren,
parentDom: Element,
lifecycle: LifecycleClass,
context: Object,
isSVG: boolean
): void {
normalizeChildNodes(parentDom);
let dom = parentDom.firstChild;
if (isStringOrNumber(children)) {
if (!isNull(dom) && dom.nodeType === 3) {
if (dom.nodeValue !== children) {
dom.nodeValue = children as string;
}
} else if (children === "") {
parentDom.appendChild(document.createTextNode(""));
} else {
parentDom.textContent = children as string;
}
if (!isNull(dom)) {
dom = (dom as Element).nextSibling;
}
} else if (isArray(children)) {
for (
let i = 0, len = (children as Array<string | number | VNode>).length;
i < len;
i++
) {
const child = children[i];
if (!isNull(child) && isObject(child)) {
if (!isNull(dom)) {
const nextSibling = dom.nextSibling;
hydrate(child as VNode, dom as Element, lifecycle, context, isSVG);
dom = nextSibling;
} else {
mount(child as VNode, parentDom, lifecycle, context, isSVG);
}
}
}
} else {
// It's VNode
if (!isNull(dom)) {
hydrate(children as VNode, dom as Element, lifecycle, context, isSVG);
dom = (dom as Element).nextSibling;
} else {
mount(children as VNode, parentDom, lifecycle, context, isSVG);
}
}
// clear any other DOM nodes, there should be only a single entry for the root
while (dom) {
const nextSibling = dom.nextSibling;
parentDom.removeChild(dom);
dom = nextSibling;
}
}
示例6: mountClassComponentCallbacks
export function mountClassComponentCallbacks(
vNode: VNode,
ref,
instance,
lifecycle: LifecycleClass
) {
if (ref) {
if (isFunction(ref)) {
ref(instance);
} else {
if (process.env.NODE_ENV !== "production") {
if (isStringOrNumber(ref)) {
throwError(
'string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'
);
} else if (isObject(ref) && vNode.flags & VNodeFlags.ComponentClass) {
throwError(
"functional component lifecycle events are not supported on ES2015 class components."
);
} else {
throwError(
`a bad value for "ref" was used on component: "${JSON.stringify(
ref
)}"`
);
}
}
throwError();
}
}
const hasDidMount = !isUndefined(instance.componentDidMount);
const afterMount = options.afterMount;
if (hasDidMount || !isNull(afterMount)) {
lifecycle.addListener(() => {
instance._updating = true;
if (afterMount) {
afterMount(vNode);
}
if (hasDidMount) {
instance.componentDidMount();
}
instance._updating = false;
});
}
}
示例7: normalizeVNodes
export function normalizeVNodes(nodes: any[]): VNode[] {
let newNodes;
// we assign $ which basically means we've flagged this array for future note
// if it comes back again, we need to clone it, as people are using it
// in an immutable way
// tslint:disable
if (nodes["$"] === true) {
nodes = nodes.slice();
} else {
nodes["$"] = true;
}
// tslint:enable
for (let i = 0, len = nodes.length; i < len; i++) {
const n = nodes[i];
if (isInvalid(n) || isArray(n)) {
const result = (newNodes || nodes).slice(0, i) as VNode[];
_normalizeVNodes(nodes, result, i, ``);
return result;
} else if (isStringOrNumber(n)) {
if (!newNodes) {
newNodes = nodes.slice(0, i) as VNode[];
}
newNodes.push(applyKeyIfMissing(i, createTextVNode(n, null)));
} else if (
(isVNode(n) && n.dom !== null) ||
(isNull(n.key) && (n.flags & VNodeFlags.HasNonKeyedChildren) === 0)
) {
if (!newNodes) {
newNodes = nodes.slice(0, i) as VNode[];
}
newNodes.push(applyKeyIfMissing(i, directClone(n)));
} else if (newNodes) {
newNodes.push(applyKeyIfMissing(i, directClone(n)));
}
}
return newNodes || (nodes as VNode[]);
}
示例8: patchComponent
export function patchComponent(
lastVNode,
nextVNode,
parentDom,
lifecycle: LifecycleClass,
context,
isSVG: boolean,
isClass: boolean,
isRecycling: boolean
) {
const lastType = lastVNode.type;
const nextType = nextVNode.type;
const lastKey = lastVNode.key;
const nextKey = nextVNode.key;
if (lastType !== nextType || lastKey !== nextKey) {
replaceWithNewNode(
lastVNode,
nextVNode,
parentDom,
lifecycle,
context,
isSVG,
isRecycling
);
return false;
} else {
const nextProps = nextVNode.props || EMPTY_OBJ;
if (isClass) {
const instance = lastVNode.children;
instance._updating = true;
if (instance._unmounted) {
if (isNull(parentDom)) {
return true;
}
replaceChild(
parentDom,
mountComponent(
nextVNode,
null,
lifecycle,
context,
isSVG,
(nextVNode.flags & VNodeFlags.ComponentClass) > 0
),
lastVNode.dom
);
} else {
const hasComponentDidUpdate = !isUndefined(instance.componentDidUpdate);
const nextState = instance.state;
// When component has componentDidUpdate hook, we need to clone lastState or will be modified by reference during update
const lastState = hasComponentDidUpdate
? combineFrom(nextState, null)
: nextState;
const lastProps = instance.props;
nextVNode.children = instance;
instance._isSVG = isSVG;
const lastInput = instance._lastInput;
let nextInput = instance._updateComponent(
lastState,
nextState,
lastProps,
nextProps,
context,
false,
false
);
// If this component was destroyed by its parent do nothing, this is no-op
// It can happen by using external callback etc during render / update
if (instance._unmounted) {
return false;
}
let didUpdate = true;
// Update component before getting child context
let childContext;
if (!isNullOrUndef(instance.getChildContext)) {
childContext = instance.getChildContext();
}
if (isNullOrUndef(childContext)) {
childContext = context;
} else {
childContext = combineFrom(context, childContext);
}
instance._childContext = childContext;
if (isInvalid(nextInput)) {
nextInput = createVoidVNode();
} else if (nextInput === NO_OP) {
nextInput = lastInput;
didUpdate = false;
} else if (isStringOrNumber(nextInput)) {
nextInput = createTextVNode(nextInput, null);
} else if (isArray(nextInput)) {
if (process.env.NODE_ENV !== "production") {
throwError(
"a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object."
);
}
//.........这里部分代码省略.........
示例9: patchChildren
function patchChildren(
lastFlags: VNodeFlags,
nextFlags: VNodeFlags,
lastChildren,
nextChildren,
dom: Element,
lifecycle: LifecycleClass,
context: Object,
isSVG: boolean,
isRecycling: boolean
) {
let patchArray = false;
let patchKeyed = false;
if (nextFlags & VNodeFlags.HasNonKeyedChildren) {
patchArray = true;
} else if (
(lastFlags & VNodeFlags.HasKeyedChildren) > 0 &&
(nextFlags & VNodeFlags.HasKeyedChildren) > 0
) {
patchKeyed = true;
patchArray = true;
} else if (isInvalid(nextChildren)) {
unmountChildren(lastChildren, dom, lifecycle, isRecycling);
} else if (isInvalid(lastChildren)) {
if (isStringOrNumber(nextChildren)) {
setTextContent(dom, nextChildren);
} else {
if (isArray(nextChildren)) {
mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
} else {
mount(nextChildren, dom, lifecycle, context, isSVG);
}
}
} else if (isStringOrNumber(nextChildren)) {
if (isStringOrNumber(lastChildren)) {
updateTextContent(dom, nextChildren);
} else {
unmountChildren(lastChildren, dom, lifecycle, isRecycling);
setTextContent(dom, nextChildren);
}
} else if (isArray(nextChildren)) {
if (isArray(lastChildren)) {
patchArray = true;
if (isKeyed(lastChildren, nextChildren)) {
patchKeyed = true;
}
} else {
unmountChildren(lastChildren, dom, lifecycle, isRecycling);
mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
}
} else if (isArray(lastChildren)) {
removeAllChildren(dom, lastChildren, lifecycle, isRecycling);
mount(nextChildren, dom, lifecycle, context, isSVG);
} else if (isVNode(nextChildren)) {
if (isVNode(lastChildren)) {
patch(
lastChildren,
nextChildren,
dom,
lifecycle,
context,
isSVG,
isRecycling
);
} else {
unmountChildren(lastChildren, dom, lifecycle, isRecycling);
mount(nextChildren, dom, lifecycle, context, isSVG);
}
}
if (patchArray) {
const lastLength = lastChildren.length;
const nextLength = nextChildren.length;
// Fast path's for both algorithms
if (lastLength === 0) {
if (nextLength > 0) {
mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
}
} else if (nextLength === 0) {
removeAllChildren(dom, lastChildren, lifecycle, isRecycling);
} else if (patchKeyed) {
patchKeyedChildren(
lastChildren,
nextChildren,
dom,
lifecycle,
context,
isSVG,
isRecycling,
lastLength,
nextLength
);
} else {
patchNonKeyedChildren(
lastChildren,
nextChildren,
dom,
lifecycle,
context,
//.........这里部分代码省略.........
示例10: createClassComponentInstance
export function createClassComponentInstance(
vNode: VNode,
Component,
props: Props,
context: Object,
isSVG: boolean,
lifecycle: LifecycleClass
) {
if (isUndefined(context)) {
context = EMPTY_OBJ; // Context should not be mutable
}
const instance = new Component(props, context);
vNode.children = instance;
instance._blockSetState = false;
instance.context = context;
if (instance.props === EMPTY_OBJ) {
instance.props = props;
}
// setState callbacks must fire after render is done when called from componentWillReceiveProps or componentWillMount
instance._lifecycle = lifecycle;
instance._unmounted = false;
instance._isSVG = isSVG;
if (!isNullOrUndef(instance.componentWillMount)) {
instance._blockRender = true;
instance.componentWillMount();
if (instance._pendingSetState) {
const state = instance.state;
const pending = instance._pendingState;
if (state === null) {
instance.state = pending;
} else {
for (const key in pending) {
state[key] = pending[key];
}
}
instance._pendingSetState = false;
instance._pendingState = null;
}
instance._blockRender = false;
}
let childContext;
if (!isNullOrUndef(instance.getChildContext)) {
childContext = instance.getChildContext();
}
if (isNullOrUndef(childContext)) {
instance._childContext = context;
} else {
instance._childContext = combineFrom(context, childContext);
}
if (!isNull(options.beforeRender)) {
options.beforeRender(instance);
}
let input = instance.render(props, instance.state, context);
if (!isNull(options.afterRender)) {
options.afterRender(instance);
}
if (isArray(input)) {
if (process.env.NODE_ENV !== "production") {
throwError(
"a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object."
);
}
throwError();
} else if (isInvalid(input)) {
input = createVoidVNode();
} else if (isStringOrNumber(input)) {
input = createTextVNode(input, null);
} else {
if (input.dom) {
input = directClone(input);
}
if (input.flags & VNodeFlags.Component) {
// if we have an input that is also a component, we run into a tricky situation
// where the root vNode needs to always have the correct DOM entry
// so we break monomorphism on our input and supply it our vNode as parentVNode
// we can optimise this in the future, but this gets us out of a lot of issues
input.parentVNode = vNode;
}
}
instance._lastInput = input;
return instance;
}