当前位置: 首页>>代码示例>>TypeScript>>正文


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

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


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

示例1: directClone

export function directClone(vNodeToClone: VNode): VNode {
  let newVNode;
  const flags = vNodeToClone.flags;

  if (flags & VNodeFlags.Component) {
    let props;
    const propsToClone = vNodeToClone.props;

    if (isNull(propsToClone)) {
      props = EMPTY_OBJ;
    } else {
      props = {};
      for (const key in propsToClone) {
        props[key] = propsToClone[key];
      }
    }
    newVNode = createVNode(
      flags,
      vNodeToClone.type,
      null,
      null,
      props,
      vNodeToClone.key,
      vNodeToClone.ref,
      true
    );
    const newProps = newVNode.props;

    const newChildren = newProps.children;
    // we need to also clone component children that are in props
    // as the children may also have been hoisted
    if (newChildren) {
      if (isArray(newChildren)) {
        const len = newChildren.length;
        if (len > 0) {
          const tmpArray: InfernoChildren = [];

          for (let i = 0; i < len; i++) {
            const child = newChildren[i];

            if (isStringOrNumber(child)) {
              tmpArray.push(child);
            } else if (!isInvalid(child) && isVNode(child)) {
              tmpArray.push(directClone(child));
            }
          }
          newProps.children = tmpArray;
        }
      } else if (isVNode(newChildren)) {
        newProps.children = directClone(newChildren);
      }
    }

    newVNode.children = null;
  } else if (flags & VNodeFlags.Element) {
    const children = vNodeToClone.children;
    let props;
    const propsToClone = vNodeToClone.props;

    if (propsToClone === null) {
      props = EMPTY_OBJ;
    } else {
      props = {};
      for (const key in propsToClone) {
        props[key] = propsToClone[key];
      }
    }
    newVNode = createVNode(
      flags,
      vNodeToClone.type,
      vNodeToClone.className,
      children,
      props,
      vNodeToClone.key,
      vNodeToClone.ref,
      !children
    );
  } else if (flags & VNodeFlags.Text) {
    newVNode = createTextVNode(
      vNodeToClone.children as string,
      vNodeToClone.key
    );
  }

  return newVNode;
}
开发者ID:russelgal,项目名称:inferno,代码行数:86,代码来源:VNodes.ts

示例2: cloneVNode

export function cloneVNode(
  vNodeToClone: VNode,
  props?: Props,
  ..._children: InfernoChildren[]
): VNode {
  let children: any = _children;
  const childrenLen = _children.length;

  if (childrenLen > 0 && !isUndefined(_children[0])) {
    if (!props) {
      props = {};
    }
    if (childrenLen === 1) {
      children = _children[0];
    }

    if (!isUndefined(children)) {
      props.children = children as VNode;
    }
  }

  let newVNode;

  if (isArray(vNodeToClone)) {
    const tmpArray: InfernoChildren = [];
    for (let i = 0, len = (vNodeToClone as any).length; i < len; i++) {
      tmpArray.push(directClone(vNodeToClone[i]));
    }

    newVNode = tmpArray;
  } else {
    const flags = vNodeToClone.flags;
    let className = vNodeToClone.className;
    let key = vNodeToClone.key;
    let ref = vNodeToClone.ref;
    if (props) {
      if (props.hasOwnProperty("className")) {
        className = props.className as string;
      }
      if (props.hasOwnProperty("ref")) {
        ref = props.ref as Ref;
      }

      if (props.hasOwnProperty("key")) {
        key = props.key;
      }
    }

    if (flags & VNodeFlags.Component) {
      newVNode = createVNode(
        flags,
        vNodeToClone.type,
        className,
        null,
        !vNodeToClone.props && !props
          ? EMPTY_OBJ
          : combineFrom(vNodeToClone.props, props),
        key,
        ref,
        true
      );
      const newProps = newVNode.props;

      if (newProps) {
        const newChildren = newProps.children;
        // we need to also clone component children that are in props
        // as the children may also have been hoisted
        if (newChildren) {
          if (isArray(newChildren)) {
            const len = newChildren.length;
            if (len > 0) {
              const tmpArray: InfernoChildren = [];

              for (let i = 0; i < len; i++) {
                const child = newChildren[i];

                if (isStringOrNumber(child)) {
                  tmpArray.push(child);
                } else if (!isInvalid(child) && isVNode(child)) {
                  tmpArray.push(directClone(child));
                }
              }
              newProps.children = tmpArray;
            }
          } else if (isVNode(newChildren)) {
            newProps.children = directClone(newChildren);
          }
        }
      }
      newVNode.children = null;
    } else if (flags & VNodeFlags.Element) {
      children =
        props && !isUndefined(props.children)
          ? props.children
          : vNodeToClone.children;
      newVNode = createVNode(
        flags,
        vNodeToClone.type,
        className,
        children,
//.........这里部分代码省略.........
开发者ID:russelgal,项目名称:inferno,代码行数:101,代码来源:VNodes.ts

示例3: only

    return children.length;
  },
  only(children: Array<InfernoChildren | any>): InfernoChildren | any {
    children = Children.toArray(children);
    if (children.length !== 1) {
      throw new Error("Children.only() expects only one child.");
    }
    return children[0];
  },
  toArray(
    children: Array<InfernoChildren | any>
  ): Array<InfernoChildren | any> {
    if (isNullOrUndef(children)) {
      return [];
    }
    return isArray(children) ? children : ARR.concat(children);
  }
};

(Component.prototype as any).isReactComponent = {};

let currentComponent: any = null;

options.beforeRender = function(component): void {
  currentComponent = component;
};
options.afterRender = function(): void {
  currentComponent = null;
};

const version = "15.4.2";
开发者ID:russelgal,项目名称:inferno,代码行数:31,代码来源:index.ts

示例4: isEmpty

export function isEmpty(children): boolean {
  return (
    !children || !(isArray(children) ? children : Object.keys(children)).length
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:5,代码来源:utils.ts

示例5: mountElement

export function mountElement(
  vNode: VNode,
  parentDom: Element | null,
  lifecycle: LifecycleClass,
  context: Object,
  isSVG: boolean
) {
  let dom;
  if (options.recyclingEnabled) {
    dom = recycleElement(vNode, lifecycle, context, isSVG);

    if (!isNull(dom)) {
      if (!isNull(parentDom)) {
        appendChild(parentDom, dom);
      }
      return dom;
    }
  }
  const flags = vNode.flags;

  isSVG = isSVG || (flags & VNodeFlags.SvgElement) > 0;
  dom = documentCreateElement(vNode.type, isSVG);
  const children = vNode.children;
  const props = vNode.props;
  const className = vNode.className;
  const ref = vNode.ref;

  vNode.dom = dom;

  if (!isInvalid(children)) {
    if (isStringOrNumber(children)) {
      setTextContent(dom, children as string | number);
    } else {
      const childrenIsSVG = isSVG === true && vNode.type !== "foreignObject";
      if (isArray(children)) {
        mountArrayChildren(children, dom, lifecycle, context, childrenIsSVG);
      } else if (isVNode(children as any)) {
        mount(children as VNode, dom, lifecycle, context, childrenIsSVG);
      }
    }
  }
  if (!isNull(props)) {
    let hasControlledValue = false;
    const isFormElement = (flags & VNodeFlags.FormElement) > 0;
    if (isFormElement) {
      hasControlledValue = isControlledFormElement(props);
    }
    for (const prop in props) {
      // do not add a hasOwnProperty check here, it affects performance
      patchProp(prop, null, props[prop], dom, isSVG, hasControlledValue);
    }
    if (isFormElement) {
      processElement(flags, vNode, dom, props, true, hasControlledValue);
    }
  }

  if (className !== null) {
    if (isSVG) {
      dom.setAttribute("class", className);
    } else {
      dom.className = className;
    }
  }

  if (!isNull(ref)) {
    mountRef(dom, ref, lifecycle);
  }
  if (!isNull(parentDom)) {
    appendChild(parentDom, dom);
  }
  return dom;
}
开发者ID:russelgal,项目名称:inferno,代码行数:72,代码来源:mounting.ts

示例6: unmount

export function unmount(
  vNode: VNode,
  parentDom: Element | null,
  lifecycle: LifecycleClass,
  canRecycle: boolean,
  isRecycling: boolean
) {
  const flags = vNode.flags;
  const dom = vNode.dom as Element;

  if (flags & VNodeFlags.Component) {
    const instance = vNode.children as any;
    const isStatefulComponent: boolean =
      (flags & VNodeFlags.ComponentClass) > 0;
    const props = vNode.props || EMPTY_OBJ;
    const ref = vNode.ref as any;

    if (!isRecycling) {
      if (isStatefulComponent) {
        if (!instance._unmounted) {
          if (!isNull(options.beforeUnmount)) {
            options.beforeUnmount(vNode);
          }
          if (!isUndefined(instance.componentWillUnmount)) {
            instance.componentWillUnmount();
          }
          if (ref && !isRecycling) {
            ref(null);
          }
          instance._unmounted = true;
          if (options.findDOMNodeEnabled) {
            componentToDOMNodeMap.delete(instance);
          }

          unmount(
            instance._lastInput,
            null,
            instance._lifecycle,
            false,
            isRecycling
          );
        }
      } else {
        if (!isNullOrUndef(ref)) {
          if (!isNullOrUndef(ref.onComponentWillUnmount)) {
            ref.onComponentWillUnmount(dom, props);
          }
        }

        unmount(instance, null, lifecycle, false, isRecycling);
      }
    }
    if (
      options.recyclingEnabled &&
      !isStatefulComponent &&
      (parentDom || canRecycle)
    ) {
      poolComponent(vNode);
    }
  } else if (flags & VNodeFlags.Element) {
    const ref = vNode.ref as any;
    const props = vNode.props;

    if (!isRecycling && isFunction(ref)) {
      ref(null);
    }

    const children = vNode.children;

    if (!isNullOrUndef(children)) {
      if (isArray(children)) {
        for (
          let i = 0, len = (children as Array<string | number | VNode>).length;
          i < len;
          i++
        ) {
          const child = children[i];

          if (!isInvalid(child) && isObject(child)) {
            unmount(child as VNode, null, lifecycle, false, isRecycling);
          }
        }
      } else if (isObject(children)) {
        unmount(children as VNode, null, lifecycle, false, isRecycling);
      }
    }

    if (!isNull(props)) {
      for (const name in props) {
        // do not add a hasOwnProperty check here, it affects performance
        if (props[name] !== null && isAttrAnEvent(name)) {
          patchEvent(name, props[name], null, dom);
          // We need to set this null, because same props otherwise come back if SCU returns false and we are recyling
          props[name] = null;
        }
      }
    }
    if (options.recyclingEnabled && (parentDom || canRecycle)) {
      poolElement(vNode);
    }
//.........这里部分代码省略.........
开发者ID:russelgal,项目名称:inferno,代码行数:101,代码来源:unmounting.ts

示例7: matchRoutes

/**
 * Go through every route and create a new node
 * with the matched components
 * @param _routes
 * @param currentURL
 * @param parentPath
 * @param redirect
 * @returns {object}
 */
function matchRoutes(
  _routes,
  currentURL = "/",
  parentPath = "/",
  redirect = false
) {
  const routes = isArray(_routes) ? flatten(_routes) : toArray(_routes);
  const [pathToMatch = "/", search = ""] = currentURL.split("?");
  const params = mapSearchParams(search);

  routes.sort(pathRankSort);

  for (let i = 0, len = routes.length; i < len; i++) {
    const route = routes[i];
    const props = route.props || emptyObject;
    const routePath = props.from || props.path || "/";
    const location =
      parentPath + toPartialURL(routePath, parentPath).replace(/\/\//g, "/");
    const isLast = isEmpty(props.children);
    const matchBase = matchPath(isLast, location, pathToMatch);

    if (matchBase) {
      let children = props.children;

      if (props.from) {
        redirect = props.to;
      }
      if (children) {
        const matchChild = matchRoutes(
          children,
          currentURL,
          location,
          redirect
        );
        if (matchChild) {
          if (matchChild.redirect) {
            return {
              location,
              redirect: matchChild.redirect
            };
          }
          children = matchChild.matched;
          const childProps = children.props.params;
          for (const key in childProps) {
            params[key] = childProps[key];
          }
        } else {
          children = null;
        }
      }

      const matched = Inferno.cloneVNode(route, {
        children,
        params: combineFrom(params, matchBase.params)
      });

      return {
        location,
        matched,
        redirect
      };
    }
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:73,代码来源:match.ts


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