本文整理汇总了TypeScript中inferno-shared.isObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isObject函数的具体用法?TypeScript isObject怎么用?TypeScript isObject使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isObject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: isDOMElement
export function isDOMElement(instance: any): boolean {
return (
Boolean(instance) &&
isObject(instance) &&
(instance as any).nodeType === 1 &&
isString((instance as any).tagName)
);
}
示例2: isVNode
export function isVNode(instance: any): instance is VNode {
return (
Boolean(instance) &&
isObject(instance) &&
isNumber((instance as any).flags) &&
(instance as any).flags > 0
);
}
示例3: 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;
}
}
示例4: isRenderedClassComponent
export function isRenderedClassComponent(instance: any): boolean {
return (
Boolean(instance) &&
isObject(instance) &&
isVNode((instance as any)._vNode) &&
isFunction((instance as any).render) &&
isFunction((instance as any).setState)
);
}
示例5: isValidElement
export default function isValidElement(obj: VNode): boolean {
const isNotANullObject = isObject(obj) && isNull(obj) === false;
if (isNotANullObject === false) {
return false;
}
const flags = obj.flags;
return (flags & (VNodeFlags.Component | VNodeFlags.Element)) > 0;
}
示例6: vNodeToSnapshot
export function vNodeToSnapshot(node: VNode) {
let object;
const children: any[] = [];
if (isDOMVNode(node)) {
const props = { className: node.className || undefined, ...node.props };
// Remove undefined props
Object.keys(props).forEach(propKey => {
if (props[propKey] === undefined) {
delete props[propKey];
}
});
// Create the actual object that Jest will interpret as the snapshot for this VNode
object = createSnapshotObject({
props,
type: getTagNameOfVNode(node)
});
}
if (isArray(node.children)) {
node.children.forEach(child => {
const asJSON = vNodeToSnapshot(child as VNode);
if (asJSON) {
children.push(asJSON);
}
});
} else if (isString(node.children)) {
children.push(node.children);
} else if (isObject(node.children) && !isNull(node.children)) {
const asJSON = vNodeToSnapshot(node.children);
if (asJSON) {
children.push(asJSON);
}
}
if (object) {
object.children = children.length ? children : null;
return object;
}
if (children.length > 1) {
return children;
} else if (children.length === 1) {
return children[0];
}
return object;
}
示例7: 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;
});
}
}
示例8: findVNodeFromDom
function findVNodeFromDom(vNode, dom) {
if (!vNode) {
const roots = options.roots;
for (let i = 0, len = roots.length; i < len; i++) {
const root = roots[i];
const result = findVNodeFromDom(root.input, dom);
if (result) {
return result;
}
}
} else {
if (vNode.dom === dom) {
return vNode;
}
const flags = vNode.flags;
let children = vNode.children;
if (flags & VNodeFlags.Component) {
children = children._lastInput || children;
}
if (children) {
if (isArray(children)) {
for (let i = 0, len = children.length; i < len; i++) {
const child = children[i];
if (child) {
const result = findVNodeFromDom(child, dom);
if (result) {
return result;
}
}
}
} else if (isObject(children)) {
const result = findVNodeFromDom(children, dom);
if (result) {
return result;
}
}
}
}
}
示例9: patchComponent
//.........这里部分代码省略.........
);
// 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."
);
}
throwError();
} else if (isObject(nextInput)) {
if (!isNull((nextInput as VNode).dom)) {
nextInput = directClone(nextInput as VNode);
}
}
if (nextInput.flags & VNodeFlags.Component) {
nextInput.parentVNode = nextVNode;
} else if (lastInput.flags & VNodeFlags.Component) {
lastInput.parentVNode = nextVNode;
}
instance._lastInput = nextInput;
instance._vNode = nextVNode;
if (didUpdate) {
patch(
lastInput,
nextInput,
parentDom,
lifecycle,
childContext,
isSVG,
isRecycling
);
if (hasComponentDidUpdate && instance.componentDidUpdate) {
instance.componentDidUpdate(lastProps, lastState);
}
if (!isNull(options.afterUpdate)) {
options.afterUpdate(nextVNode);
}
if (options.findDOMNodeEnabled) {
componentToDOMNodeMap.set(instance, nextInput.dom);
}
}
nextVNode.dom = nextInput.dom;
示例10: Error
/**
* Creates virtual node
* @param {string|Function|Component<any, any>} type Type of node
* @param {object=} props Optional props for virtual node
* @param {...{object}=} _children Optional children for virtual node
* @returns {VNode} new virtual ndoe
*/
export default function createElement<T>(
type: string | Function | Component<any, any>,
props?: T & Props | null,
..._children: Array<InfernoChildren | any>
): VNode {
if (isInvalid(type) || isObject(type)) {
throw new Error(
"Inferno Error: createElement() name parameter cannot be undefined, null, false or true, It must be a string, class or function."
);
}
let children: any = _children;
let ref: any = null;
let key = null;
let className = null;
let flags = 0;
let newProps;
if (_children) {
if (_children.length === 1) {
children = _children[0];
} else if (_children.length === 0) {
children = void 0;
}
}
if (isString(type)) {
flags = getFlagsForElementVnode(type as string);
if (!isNullOrUndef(props)) {
newProps = {} as T & Props;
for (const prop in props) {
if (prop === "className" || prop === "class") {
className = props[prop];
} else if (prop === "key") {
key = props.key;
} else if (prop === "children" && isUndefined(children)) {
children = props.children; // always favour children args, default to props
} else if (prop === "ref") {
ref = props.ref;
} else {
newProps[prop] = props[prop];
}
}
}
} else {
flags = VNodeFlags.ComponentUnknown;
if (!isUndefined(children)) {
if (!props) {
props = {} as T;
}
props.children = children;
children = null;
}
if (!isNullOrUndef(props)) {
newProps = {} as T & Props;
for (const prop in props) {
if (componentHooks.has(prop)) {
if (!ref) {
ref = {};
}
ref[prop] = props[prop];
} else if (prop === "key") {
key = props.key;
} else {
newProps[prop] = props[prop];
}
}
}
}
return createVNode(
flags,
type as string | Function,
className,
children,
newProps,
key,
ref
);
}