• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript inferno-shared.isObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:8,代码来源:index.ts


示例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
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:8,代码来源:index.ts


示例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;
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:58,代码来源:hydration.ts


示例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)
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:9,代码来源:index.ts


示例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;
}
开发者ID:russelgal,项目名称:inferno,代码行数:9,代码来源:isValidElement.ts


示例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;
}
开发者ID:russelgal,项目名称:inferno,代码行数:49,代码来源:jest.ts


示例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;
    });
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:46,代码来源:mounting.ts


示例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;
        }
      }
    }
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:45,代码来源:bridge.ts


示例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;
开发者ID:russelgal,项目名称:inferno,代码行数:67,代码来源:patching.ts


示例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
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:88,代码来源:index.ts



注:本文中的inferno-shared.isObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript inferno-shared.isString函数代码示例发布时间:2022-05-25
下一篇:
TypeScript inferno-shared.isNumber函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap