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


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

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


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

示例1: recycleElement

export function recycleElement(
  vNode: VNode,
  lifecycle: LifecycleClass,
  context: Object,
  isSVG: boolean
) {
  const tag = vNode.type as string | null;
  const pools: Pools | undefined = elementPools.get(tag);

  if (!isUndefined(pools)) {
    const key = vNode.key;
    const pool = key === null ? pools.nonKeyed : pools.keyed.get(key);

    if (!isUndefined(pool)) {
      const recycledVNode = pool.pop();

      if (!isUndefined(recycledVNode)) {
        patchElement(
          recycledVNode,
          vNode,
          null,
          lifecycle,
          context,
          isSVG,
          true
        );
        return vNode.dom;
      }
    }
  }
  return null;
}
开发者ID:russelgal,项目名称:inferno,代码行数:32,代码来源:recycling.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: updateReactComponent

/**
 * Update (and create if necessary) the ReactDOMComponent|ReactCompositeComponent-like
 * instance for a given Inferno component instance or DOM Node.
 */
function updateReactComponent(vNode, parentDom) {
  if (!vNode) {
    return null;
  }
  const flags = vNode.flags;
  const oldInstance = getInstanceFromVNode(vNode);
  let newInstance;

  if (flags & VNodeFlags.Component) {
    newInstance = createReactCompositeComponent(
      vNode,
      isUndefined(oldInstance)
    );
  } else {
    newInstance = createReactDOMComponent(vNode, parentDom);
  }

  if (oldInstance) {
    for (const key in newInstance) {
      oldInstance[key] = newInstance[key];
    }

    return oldInstance;
  }
  createInstanceFromVNode(vNode, newInstance);
  return newInstance;
}
开发者ID:russelgal,项目名称:inferno,代码行数:31,代码来源:bridge.ts

示例4: recycleComponent

export function recycleComponent(
  vNode: VNode,
  lifecycle: LifecycleClass,
  context: Object,
  isSVG: boolean
) {
  const type = vNode.type as Function;
  const pools: Pools | undefined = componentPools.get(type);

  if (!isUndefined(pools)) {
    const key = vNode.key;
    const pool = key === null ? pools.nonKeyed : pools.keyed.get(key);

    if (!isUndefined(pool)) {
      const recycledVNode = pool.pop();

      if (!isUndefined(recycledVNode)) {
        const flags = vNode.flags;
        const failed = patchComponent(
          recycledVNode,
          vNode,
          null,
          lifecycle,
          context,
          isSVG,
          (flags & VNodeFlags.ComponentClass) > 0,
          true
        );

        if (!failed) {
          return vNode.dom;
        }
      }
    }
  }
  return null;
}
开发者ID:russelgal,项目名称:inferno,代码行数:37,代码来源:recycling.ts

示例5: poolElement

export function poolElement(vNode: VNode) {
  const tag = vNode.type as string | null;
  const key = vNode.key;
  let pools: Pools | undefined = elementPools.get(tag);

  if (isUndefined(pools)) {
    pools = {
      keyed: new Map<string | number, VNode[]>(),
      nonKeyed: []
    };
    elementPools.set(tag, 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,代码行数:24,代码来源:recycling.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: parseTag

function parseTag(tag: string | null, props: any): string {
  if (!tag) {
    return "div";
  }
  const noId = props && isUndefined(props.id);
  const tagParts = tag.split(classIdSplit);
  let tagName: null | string = null;

  if (notClassId.test(tagParts[1])) {
    tagName = "div";
  }
  let classes;

  for (let i = 0, len = tagParts.length; i < len; i++) {
    const part = tagParts[i];

    if (!part) {
      continue;
    }
    const type = part.charAt(0);

    if (!tagName) {
      tagName = part;
    } else if (type === ".") {
      if (classes === void 0) {
        classes = [];
      }
      classes.push(part.substring(1, part.length));
    } else if (type === "#" && noId) {
      props.id = part.substring(1, part.length);
    }
  }
  if (classes) {
    if (props.className) {
      classes.push(props.className);
    }
    props.className = classes.join(" ");
  }
  return tagName || "div";
}
开发者ID:russelgal,项目名称:inferno,代码行数:40,代码来源:index.ts

示例8: patchKeyedChildren


//.........这里部分代码省略.........
              sources[j - bStart] = i;

              if (pos > j) {
                moved = true;
              } else {
                pos = j;
              }
              if (bNode.dom) {
                b[j] = bNode = directClone(bNode);
              }
              patch(aNode, bNode, dom, lifecycle, context, isSVG, isRecycling);
              patched++;
              a[i] = null as any;
              break;
            }
          }
        }
      }
    } else {
      const keyIndex = new Map();

      // Map keys by their index in array
      for (i = bStart; i <= bEnd; i++) {
        keyIndex.set(b[i].key, i);
      }

      // Try to patch same keys
      for (i = aStart; i <= aEnd; i++) {
        aNode = a[i];

        if (patched < bLeft) {
          j = keyIndex.get(aNode.key);

          if (!isUndefined(j)) {
            bNode = b[j];
            sources[j - bStart] = i;
            if (pos > j) {
              moved = true;
            } else {
              pos = j;
            }
            if (bNode.dom) {
              b[j] = bNode = directClone(bNode);
            }
            patch(aNode, bNode, dom, lifecycle, context, isSVG, isRecycling);
            patched++;
            a[i] = null as any;
          }
        }
      }
    }
    // fast-path: if nothing patched remove all old and add all new
    if (aLeft === aLength && patched === 0) {
      removeAllChildren(dom, a, lifecycle, isRecycling);
      while (bStart < bLeft) {
        node = b[bStart];
        if (node.dom) {
          b[bStart] = node = directClone(node);
        }
        bStart++;
        insertOrAppend(dom, mount(node, null, lifecycle, context, isSVG), null);
      }
    } else {
      i = aLeft - patched;
      while (i > 0) {
        aNode = a[aStart++];
开发者ID:russelgal,项目名称:inferno,代码行数:67,代码来源:patching.ts

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

示例10: normalize

export function normalize(vNode: VNode): void {
  let props = vNode.props;
  let children = vNode.children;

  // convert a wrongly created type back to element
  // Primitive node doesn't have defaultProps, only Component
  if (vNode.flags & VNodeFlags.Component) {
    // set default props
    const type = vNode.type;
    const defaultProps = (type as any).defaultProps;

    if (!isNullOrUndef(defaultProps)) {
      if (!props) {
        props = vNode.props = defaultProps; // Create new object if only defaultProps given
      } else {
        for (const prop in defaultProps) {
          if (isUndefined(props[prop])) {
            props[prop] = defaultProps[prop];
          }
        }
      }
    }

    if (isString(type)) {
      vNode.flags = getFlagsForElementVnode(type as string);
      if (props && props.children) {
        vNode.children = props.children;
        children = props.children;
      }
    }
  }

  if (props) {
    normalizeProps(vNode, props, children);
    if (!isInvalid(props.children)) {
      props.children = normalizeChildren(props.children);
    }
  }
  if (!isInvalid(children)) {
    vNode.children = normalizeChildren(children);
  }

  if (process.env.NODE_ENV !== "production") {
    // This code will be stripped out from production CODE
    // It helps users to track errors in their applications.

    const verifyKeys = function(vNodes) {
      const keyValues = vNodes.map(function(vnode) {
        return vnode.key;
      });
      keyValues.some(function(item, idx) {
        const hasDuplicate = keyValues.indexOf(item) !== idx;

        if (hasDuplicate) {
          warning(
            "Inferno normalisation(...): Encountered two children with same key, all keys must be unique within its siblings. Duplicated key is:" +
              item
          );
        }

        return hasDuplicate;
      });
    };

    if (vNode.children && Array.isArray(vNode.children)) {
      verifyKeys(vNode.children);
    }
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:69,代码来源:normalization.ts


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