本文整理汇总了TypeScript中inferno-shared.isInvalid函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isInvalid函数的具体用法?TypeScript isInvalid怎么用?TypeScript isInvalid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isInvalid函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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;
}
示例2: _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);
}
}
}
}
示例3: removeChildren
export function removeChildren(
dom: Element | null,
children,
lifecycle: LifecycleClass,
isRecycling: boolean
) {
for (let i = 0, len = children.length; i < len; i++) {
const child = children[i];
if (!isInvalid(child)) {
unmount(child, dom, lifecycle, true, isRecycling);
}
}
}
示例4: mountRef
export function mountRef(dom: Element, value, lifecycle: LifecycleClass) {
if (isFunction(value)) {
lifecycle.addListener(() => value(dom));
} else {
if (isInvalid(value)) {
return;
}
if (process.env.NODE_ENV !== "production") {
throwError(
'string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.'
);
}
throwError();
}
}
示例5: mountArrayChildren
export function mountArrayChildren(
children,
dom: Element,
lifecycle: LifecycleClass,
context: Object,
isSVG: boolean
) {
for (let i = 0, len = children.length; i < len; i++) {
let child = children[i];
// Verify can string/number be here. might cause de-opt. - Normalization takes care of it.
if (!isInvalid(child)) {
if (child.dom) {
children[i] = child = directClone(child);
}
mount(children[i], dom, lifecycle, context, isSVG);
}
}
}
示例6: applyValue
export function applyValue(vNode, dom, nextPropsOrEmpty, mounting: boolean) {
if (nextPropsOrEmpty.multiple !== dom.multiple) {
dom.multiple = nextPropsOrEmpty.multiple;
}
const children = vNode.children;
if (!isInvalid(children)) {
let value = nextPropsOrEmpty.value;
if (mounting && isNullOrUndef(value)) {
value = nextPropsOrEmpty.defaultValue;
}
if (isArray(children)) {
for (let i = 0, len = children.length; i < len; i++) {
updateChildOptionGroup(children[i], value);
}
} else if (isVNode(children)) {
updateChildOptionGroup(children, value);
}
}
}
示例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: renderVNodeToString
function renderVNodeToString(
vNode,
parent,
context,
firstChild
): string | undefined {
const flags = vNode.flags;
const type = vNode.type;
const props = vNode.props || EMPTY_OBJ;
const children = vNode.children;
if ((flags & VNodeFlags.Component) > 0) {
const isClass = flags & VNodeFlags.ComponentClass;
if (isClass) {
const instance = new type(props, context);
instance._blockSetState = false;
let childContext;
if (isFunction(instance.getChildContext)) {
childContext = instance.getChildContext();
}
if (isNullOrUndef(childContext)) {
childContext = context;
} else {
childContext = combineFrom(context, childContext);
}
if (instance.props === EMPTY_OBJ) {
instance.props = props;
}
instance.context = context;
instance._unmounted = false;
if (isFunction(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;
}
const nextVNode = instance.render(props, instance.state, instance.context);
// In case render returns invalid stuff
if (isInvalid(nextVNode)) {
return "<!--!-->";
}
return renderVNodeToString(nextVNode, vNode, childContext, true);
} else {
const nextVNode = type(props, context);
if (isInvalid(nextVNode)) {
return "<!--!-->";
}
return renderVNodeToString(nextVNode, vNode, context, true);
}
} else if ((flags & VNodeFlags.Element) > 0) {
let renderedString = `<${type}`;
let html;
const isVoidElement = voidElements.has(type);
const className = vNode.className;
if (isString(className)) {
renderedString += ` class="${escapeText(className)}"`;
} else if (isNumber(className)) {
renderedString += ` class="${className}"`;
}
if (!isNull(props)) {
for (const prop in props) {
const value = props[prop];
if (prop === "dangerouslySetInnerHTML") {
html = value.__html;
} else if (prop === "style") {
renderedString += ` style="${renderStylesToString(props.style)}"`;
} else if (prop === "children") {
// Ignore children as prop.
} else if (prop === "defaultValue") {
// Use default values if normal values are not present
if (!props.value) {
renderedString += ` value="${isString(value)
? escapeText(value)
: value}"`;
}
} else if (prop === "defaultChecked") {
// Use default values if normal values are not present
if (!props.checked) {
renderedString += ` checked="${value}"`;
}
} else {
//.........这里部分代码省略.........
示例9: isInvalidChild
function isInvalidChild(child) {
return isInvalid(child) || child === "";
}
示例10: normalize
export function normalize(vNode: VNode): void {
let props = vNode.props;
let children = vNode.children;
// convert a wrongly created type back to element
// Primitive node doesn't have defaultProps, only Component
if (vNode.flags & VNodeFlags.Component) {
// set default props
const type = vNode.type;
const defaultProps = (type as any).defaultProps;
if (!isNullOrUndef(defaultProps)) {
if (!props) {
props = vNode.props = defaultProps; // Create new object if only defaultProps given
} else {
for (const prop in defaultProps) {
if (isUndefined(props[prop])) {
props[prop] = defaultProps[prop];
}
}
}
}
if (isString(type)) {
vNode.flags = getFlagsForElementVnode(type as string);
if (props && props.children) {
vNode.children = props.children;
children = props.children;
}
}
}
if (props) {
normalizeProps(vNode, props, children);
if (!isInvalid(props.children)) {
props.children = normalizeChildren(props.children);
}
}
if (!isInvalid(children)) {
vNode.children = normalizeChildren(children);
}
if (process.env.NODE_ENV !== "production") {
// This code will be stripped out from production CODE
// It helps users to track errors in their applications.
const verifyKeys = function(vNodes) {
const keyValues = vNodes.map(function(vnode) {
return vnode.key;
});
keyValues.some(function(item, idx) {
const hasDuplicate = keyValues.indexOf(item) !== idx;
if (hasDuplicate) {
warning(
"Inferno normalisation(...): Encountered two children with same key, all keys must be unique within its siblings. Duplicated key is:" +
item
);
}
return hasDuplicate;
});
};
if (vNode.children && Array.isArray(vNode.children)) {
verifyKeys(vNode.children);
}
}
}