当前位置: 首页>>代码示例>>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;未经允许,请勿转载。