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


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

本文整理匯總了TypeScript中inferno-shared.isNull函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isNull函數的具體用法?TypeScript isNull怎麽用?TypeScript isNull使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isNull函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: poolComponent

export function poolComponent(vNode: VNode) {
  const hooks = vNode.ref as Refs;
  const nonRecycleHooks =
    hooks &&
    (hooks.onComponentWillMount ||
      hooks.onComponentWillUnmount ||
      hooks.onComponentDidMount ||
      hooks.onComponentWillUpdate ||
      hooks.onComponentDidUpdate);
  if (nonRecycleHooks) {
    return;
  }
  const type = vNode.type;
  const key = vNode.key;
  let pools: Pools | undefined = componentPools.get(type as Function);

  if (isUndefined(pools)) {
    pools = {
      keyed: new Map<string | number, VNode[]>(),
      nonKeyed: []
    };
    componentPools.set(type as Function, pools);
  }
  if (isNull(key)) {
    pools.nonKeyed.push(vNode);
  } else {
    let pool = pools.keyed.get(key);

    if (isUndefined(pool)) {
      pool = [];
      pools.keyed.set(key, pool);
    }
    pool.push(vNode);
  }
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:35,代碼來源:recycling.ts

示例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);
      }
    }
  }
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:30,代碼來源:normalization.ts

示例4: applyKeyIfMissing

function applyKeyIfMissing(key: string | number, vNode: VNode): VNode {
  if (isNumber(key)) {
    key = `.${key}`;
  }
  if (isNull(vNode.key) || vNode.key[0] === ".") {
    return applyKey(key as string, vNode);
  }
  return vNode;
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:9,代碼來源:normalization.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: mountVoid

export function mountVoid(vNode: VNode, parentDom: Element | null) {
  const dom = document.createTextNode("");

  vNode.dom = dom as any;
  if (!isNull(parentDom)) {
    appendChild(parentDom, dom);
  }
  return dom;
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:9,代碼來源:mounting.ts

示例7: updateTextContent

export function updateTextContent(dom, text: string | number) {
  const textNode = dom.firstChild;

  // Guard against external change on DOM node.
  if (isNull(textNode)) {
    setTextContent(dom, text);
  } else {
    textNode.nodeValue = text;
  }
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:10,代碼來源:utils.ts

示例8: mountText

export function mountText(vNode: VNode, parentDom: Element | null): any {
  const dom = document.createTextNode(vNode.children as string);

  vNode.dom = dom as any;
  if (!isNull(parentDom)) {
    appendChild(parentDom, dom);
  }

  return dom;
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:10,代碼來源:mounting.ts

示例9: renderToSnapshot

export function renderToSnapshot(input: VNode) {
  const wrapper = renderIntoDocument(input);
  const vnode = wrapper.props.children;

  if (!isNull(wrapper.props)) {
    const snapshot = vNodeToSnapshot(vnode.children as VNode);
    delete snapshot.props.children;
    return snapshot;
  }

  return undefined;
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:12,代碼來源:jest.ts

示例10: hydrateRoot

export function hydrateRoot(
  input,
  parentDom: Element | null,
  lifecycle: LifecycleClass
) {
  if (!isNull(parentDom)) {
    let dom = parentDom.firstChild as Element;

    if (!isNull(dom)) {
      hydrate(input, dom, lifecycle, EMPTY_OBJ, false);
      dom = parentDom.firstChild as Element;
      // clear any other DOM nodes, there should be only a single entry for the root
      while ((dom = dom.nextSibling as Element)) {
        parentDom.removeChild(dom);
      }
      return true;
    }
  }

  return false;
}
開發者ID:russelgal,項目名稱:inferno,代碼行數:21,代碼來源:hydration.ts


注:本文中的inferno-shared.isNull函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。