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

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

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

本文整理汇总了TypeScript中inferno-shared.isStringOrNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isStringOrNumber函数的具体用法?TypeScript isStringOrNumber怎么用?TypeScript isStringOrNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isStringOrNumber函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: createReactDOMComponent

/**
 * Create a ReactDOMComponent-compatible object for a given DOM node rendered
 * by Inferno.
 *
 * This implements the subset of the ReactDOMComponent interface that
 * React DevTools requires in order to display DOM nodes in the inspector with
 * the correct type and properties.
 */
function createReactDOMComponent(vNode, parentDom) {
  const flags = vNode.flags;

  if (flags & VNodeFlags.Void) {
    return null;
  }
  const type = vNode.type;
  const children =
    vNode.children === 0 ? vNode.children.toString() : vNode.children;
  const props = vNode.props;
  const dom = vNode.dom;
  const isText = flags & VNodeFlags.Text || isStringOrNumber(vNode);

  return {
    _currentElement: isText
      ? children || vNode
      : {
          props,
          type
        },
    _inDevTools: false,
    _renderedChildren: !isText && normalizeChildren(children, dom),
    _stringText: isText ? (children || vNode).toString() : null,
    node: dom || parentDom,
    vNode
  };
}
开发者ID:russelgal,项目名称:inferno,代码行数:35,代码来源:bridge.ts


示例2: validateNodeTree

export function validateNodeTree(node: any): boolean {
  if (!node) {
    return true;
  }
  if (isStringOrNumber(node)) {
    return true;
  }
  if (!node.dom) {
    return false;
  }
  const children = node.children;
  const flags = node.flags;

  if ((flags & VNodeFlags.Element) > 0) {
    if (!isNullOrUndef(children)) {
      if (isArray(children)) {
        for (const child of children) {
          const val = validateNodeTree(child);

          if (!val) {
            return false;
          }
        }
      } else {
        const val = validateNodeTree(children);

        if (!val) {
          return false;
        }
      }
    }
  }
  return true;
}
开发者ID:russelgal,项目名称:inferno,代码行数:34,代码来源:index.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: createFunctionalComponentInput

export function createFunctionalComponentInput(
  vNode: VNode,
  component,
  props: Props,
  context: Object
) {
  let input = component(props, context);

  if (isArray(input)) {
    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 (isInvalid(input)) {
    input = createVoidVNode();
  } else if (isStringOrNumber(input)) {
    input = createTextVNode(input, null);
  } else {
    if (input.dom) {
      input = directClone(input);
    }
    if (input.flags & VNodeFlags.Component) {
      // if we have an input that is also a component, we run into a tricky situation
      // where the root vNode needs to always have the correct DOM entry
      // so we break monomorphism on our input and supply it our vNode as parentVNode
      // we can optimise this in the future, but this gets us out of a lot of issues
      input.parentVNode = vNode;
    }
  }
  return input;
}
开发者ID:russelgal,项目名称:inferno,代码行数:33,代码来源:utils.ts


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


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


示例7: normalizeVNodes

export function normalizeVNodes(nodes: any[]): VNode[] {
  let newNodes;

  // we assign $ which basically means we've flagged this array for future note
  // if it comes back again, we need to clone it, as people are using it
  // in an immutable way
  // tslint:disable
  if (nodes["$"] === true) {
    nodes = nodes.slice();
  } else {
    nodes["$"] = true;
  }
  // tslint:enable
  for (let i = 0, len = nodes.length; i < len; i++) {
    const n = nodes[i];

    if (isInvalid(n) || isArray(n)) {
      const result = (newNodes || nodes).slice(0, i) as VNode[];

      _normalizeVNodes(nodes, result, i, ``);
      return result;
    } else if (isStringOrNumber(n)) {
      if (!newNodes) {
        newNodes = nodes.slice(0, i) as VNode[];
      }
      newNodes.push(applyKeyIfMissing(i, createTextVNode(n, null)));
    } else if (
      (isVNode(n) && n.dom !== null) ||
      (isNull(n.key) && (n.flags & VNodeFlags.HasNonKeyedChildren) === 0)
    ) {
      if (!newNodes) {
        newNodes = nodes.slice(0, i) as VNode[];
      }
      newNodes.push(applyKeyIfMissing(i, directClone(n)));
    } else if (newNodes) {
      newNodes.push(applyKeyIfMissing(i, directClone(n)));
    }
  }

  return newNodes || (nodes as VNode[]);
}
开发者ID:russelgal,项目名称:inferno,代码行数:41,代码来源:normalization.ts


示例8: patchComponent

export function patchComponent(
  lastVNode,
  nextVNode,
  parentDom,
  lifecycle: LifecycleClass,
  context,
  isSVG: boolean,
  isClass: boolean,
  isRecycling: boolean
) {
  const lastType = lastVNode.type;
  const nextType = nextVNode.type;
  const lastKey = lastVNode.key;
  const nextKey = nextVNode.key;

  if (lastType !== nextType || lastKey !== nextKey) {
    replaceWithNewNode(
      lastVNode,
      nextVNode,
      parentDom,
      lifecycle,
      context,
      isSVG,
      isRecycling
    );
    return false;
  } else {
    const nextProps = nextVNode.props || EMPTY_OBJ;

    if (isClass) {
      const instance = lastVNode.children;
      instance._updating = true;

      if (instance._unmounted) {
        if (isNull(parentDom)) {
          return true;
        }
        replaceChild(
          parentDom,
          mountComponent(
            nextVNode,
            null,
            lifecycle,
            context,
            isSVG,
            (nextVNode.flags & VNodeFlags.ComponentClass) > 0
          ),
          lastVNode.dom
        );
      } else {
        const hasComponentDidUpdate = !isUndefined(instance.componentDidUpdate);
        const nextState = instance.state;
        // When component has componentDidUpdate hook, we need to clone lastState or will be modified by reference during update
        const lastState = hasComponentDidUpdate
          ? combineFrom(nextState, null)
          : nextState;
        const lastProps = instance.props;
        nextVNode.children = instance;
        instance._isSVG = isSVG;
        const lastInput = instance._lastInput;
        let nextInput = instance._updateComponent(
          lastState,
          nextState,
          lastProps,
          nextProps,
          context,
          false,
          false
        );
        // 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."
            );
          }
//.........这里部分代码省略.........
开发者ID:russelgal,项目名称:inferno,代码行数:101,代码来源:patching.ts


示例9: patchChildren

function patchChildren(
  lastFlags: VNodeFlags,
  nextFlags: VNodeFlags,
  lastChildren,
  nextChildren,
  dom: Element,
  lifecycle: LifecycleClass,
  context: Object,
  isSVG: boolean,
  isRecycling: boolean
) {
  let patchArray = false;
  let patchKeyed = false;

  if (nextFlags & VNodeFlags.HasNonKeyedChildren) {
    patchArray = true;
  } else if (
    (lastFlags & VNodeFlags.HasKeyedChildren) > 0 &&
    (nextFlags & VNodeFlags.HasKeyedChildren) > 0
  ) {
    patchKeyed = true;
    patchArray = true;
  } else if (isInvalid(nextChildren)) {
    unmountChildren(lastChildren, dom, lifecycle, isRecycling);
  } else if (isInvalid(lastChildren)) {
    if (isStringOrNumber(nextChildren)) {
      setTextContent(dom, nextChildren);
    } else {
      if (isArray(nextChildren)) {
        mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
      } else {
        mount(nextChildren, dom, lifecycle, context, isSVG);
      }
    }
  } else if (isStringOrNumber(nextChildren)) {
    if (isStringOrNumber(lastChildren)) {
      updateTextContent(dom, nextChildren);
    } else {
      unmountChildren(lastChildren, dom, lifecycle, isRecycling);
      setTextContent(dom, nextChildren);
    }
  } else if (isArray(nextChildren)) {
    if (isArray(lastChildren)) {
      patchArray = true;
      if (isKeyed(lastChildren, nextChildren)) {
        patchKeyed = true;
      }
    } else {
      unmountChildren(lastChildren, dom, lifecycle, isRecycling);
      mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
    }
  } else if (isArray(lastChildren)) {
    removeAllChildren(dom, lastChildren, lifecycle, isRecycling);
    mount(nextChildren, dom, lifecycle, context, isSVG);
  } else if (isVNode(nextChildren)) {
    if (isVNode(lastChildren)) {
      patch(
        lastChildren,
        nextChildren,
        dom,
        lifecycle,
        context,
        isSVG,
        isRecycling
      );
    } else {
      unmountChildren(lastChildren, dom, lifecycle, isRecycling);
      mount(nextChildren, dom, lifecycle, context, isSVG);
    }
  }
  if (patchArray) {
    const lastLength = lastChildren.length;
    const nextLength = nextChildren.length;

    // Fast path's for both algorithms
    if (lastLength === 0) {
      if (nextLength > 0) {
        mountArrayChildren(nextChildren, dom, lifecycle, context, isSVG);
      }
    } else if (nextLength === 0) {
      removeAllChildren(dom, lastChildren, lifecycle, isRecycling);
    } else if (patchKeyed) {
      patchKeyedChildren(
        lastChildren,
        nextChildren,
        dom,
        lifecycle,
        context,
        isSVG,
        isRecycling,
        lastLength,
        nextLength
      );
    } else {
      patchNonKeyedChildren(
        lastChildren,
        nextChildren,
        dom,
        lifecycle,
        context,
//.........这里部分代码省略.........
开发者ID:russelgal,项目名称:inferno,代码行数:101,代码来源:patching.ts


示例10: createClassComponentInstance

export function createClassComponentInstance(
  vNode: VNode,
  Component,
  props: Props,
  context: Object,
  isSVG: boolean,
  lifecycle: LifecycleClass
) {
  if (isUndefined(context)) {
    context = EMPTY_OBJ; // Context should not be mutable
  }
  const instance = new Component(props, context);
  vNode.children = instance;
  instance._blockSetState = false;
  instance.context = context;
  if (instance.props === EMPTY_OBJ) {
    instance.props = props;
  }
  // setState callbacks must fire after render is done when called from componentWillReceiveProps or componentWillMount
  instance._lifecycle = lifecycle;

  instance._unmounted = false;
  instance._isSVG = isSVG;
  if (!isNullOrUndef(instance.componentWillMount)) {
    instance._blockRender = true;
    instance.componentWillMount();

    if (instance._pendingSetState) {
      const state = instance.state;
      const pending = instance._pendingState;

      if (state === null) {
        instance.state = pending;
      } else {
        for (const key in pending) {
          state[key] = pending[key];
        }
      }
      instance._pendingSetState = false;
      instance._pendingState = null;
    }

    instance._blockRender = false;
  }

  let childContext;
  if (!isNullOrUndef(instance.getChildContext)) {
    childContext = instance.getChildContext();
  }

  if (isNullOrUndef(childContext)) {
    instance._childContext = context;
  } else {
    instance._childContext = combineFrom(context, childContext);
  }

  if (!isNull(options.beforeRender)) {
    options.beforeRender(instance);
  }

  let input = instance.render(props, instance.state, context);

  if (!isNull(options.afterRender)) {
    options.afterRender(instance);
  }
  if (isArray(input)) {
    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 (isInvalid(input)) {
    input = createVoidVNode();
  } else if (isStringOrNumber(input)) {
    input = createTextVNode(input, null);
  } else {
    if (input.dom) {
      input = directClone(input);
    }
    if (input.flags & VNodeFlags.Component) {
      // if we have an input that is also a component, we run into a tricky situation
      // where the root vNode needs to always have the correct DOM entry
      // so we break monomorphism on our input and supply it our vNode as parentVNode
      // we can optimise this in the future, but this gets us out of a lot of issues
      input.parentVNode = vNode;
    }
  }
  instance._lastInput = input;
  return instance;
}
开发者ID:russelgal,项目名称:inferno,代码行数:91,代码来源:utils.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript inferno-shared.isUndefined函数代码示例发布时间:2022-05-25
下一篇:
TypeScript inferno-shared.isString函数代码示例发布时间: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