當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript inferno-shared.isObject函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。