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

TypeScript hey-listen.invariant函数代码示例

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

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



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

示例1: default

export default (from: Color | string, to: Color | string) => {
  const fromColorType = getColorType(from);
  const toColorType = getColorType(to);

  invariant(!!fromColorType, notAnimatable(from));
  invariant(!!toColorType, notAnimatable(to));
  invariant(
    fromColorType.transform === toColorType.transform,
    'Both colors must be hex/RGBA, OR both must be HSLA.'
  );

  const fromColor = fromColorType.parse(from);
  const toColor = toColorType.parse(to);
  const blended = { ...fromColor };

  // Only use the linear blending function for rgba and hex
  const mixFunc = fromColorType === hsla ? mix : mixLinearColor;

  return (v: number) => {
    for (const key in blended) {
      if (key !== 'alpha') {
        blended[key] = mixFunc(fromColor[key], toColor[key], v);
      }
    }

    blended.alpha = mix(fromColor.alpha, toColor.alpha, v);

    return fromColorType.transform(blended);
  };
};
开发者ID:Popmotion,项目名称:popmotion,代码行数:30,代码来源:mix-color.ts


示例2: invariant

const getAction = (
  v: Value,
  { type = 'tween', ease: definedEase, ...def }: TransitionDefinition,
  { from, to, velocity }: TransitionProps
) => {
  invariant(
    animationLookup[type] !== undefined,
    `Invalid transition type '${type}'. Valid transition types are: tween, spring, decay, physics and keyframes.`
  );

  let ease: Exclude<
    typeof definedEase,
    keyof typeof easingLookup | CubicBezierArgs
  >;

  // Convert ease definition into easing function
  if (type === 'tween') {
    if (typeof definedEase !== 'function') {
      if (typeof definedEase === 'string') {
        invariant(
          easingLookup[definedEase] !== undefined,
          `Invalid easing type '${definedEase}'. popmotion.io/pose/api/config`
        );

        ease = easingLookup[definedEase];
      } else if (Array.isArray(definedEase) && isCubicBezierArgs(definedEase)) {
        invariant(
          definedEase.length === 4,
          `Cubic bezier arrays must contain four numerical values.`
        );
        const [x1, y1, x2, y2] = definedEase;
        ease = easing.cubicBezier(x1, y1, x2, y2);
      }
    }
  }

  ease = ease || (definedEase as typeof ease);

  const baseProps =
    type !== 'keyframes'
      ? {
        from,
        to,
        velocity,
        ease
      }
      : { ease };

  return animationLookup[type]({ ...baseProps, ...def });
};
开发者ID:Popmotion,项目名称:popmotion,代码行数:50,代码来源:pose.ts


示例3: invariant

const getKey = (child: ReactElement<any>): string => {
  invariant(
    child && child.key !== null,
    'Every child of Transition must be given a unique key'
  );

  const childKey =
    typeof child.key === 'number' ? child.key.toString() : child.key;

  return childKey.replace('.$', '');
};
开发者ID:Popmotion,项目名称:popmotion,代码行数:11,代码来源:children.ts


示例4: invariant

const convertEasing = (easing: EasingDefinition = easeOut) => {
  if (typeof easing === 'string') {
    invariant(
      easingLookup[easing] !== undefined,
      `Invalid easing type '${easing}'. popmotion.io/pose/api/config`
    );

    return easingLookup[easing];
  } else if (Array.isArray(easing)) {
    invariant(
      easing.length === 4,
      'Cubic bezier arrays must contain four numerical values.'
    );

    const [x1, y1, x2, y2] = easing;
    return cubicBezier(x1, y1, x2, y2);
  }

  return easing;
};
开发者ID:Popmotion,项目名称:popmotion,代码行数:20,代码来源:convert-transition-definition.ts


示例5: invariant

const getAction = (
  v: Value,
  { type = 'tween', ease, ...def }: AnimationDef,
  { from, to, velocity }: TransitionProps
) => {
  invariant(
    animationLookup[type] !== undefined,
    `Invalid transition type '${type}'. Valid transition types are: tween, spring, decay, physics and keyframes.`
  );

  // Convert ease definition into easing function
  if (type === 'tween') {
    const typeOfEase = typeof ease;
    if (typeOfEase !== 'function') {
      if (typeOfEase === 'string') {
        invariant(
          easingLookup[ease] !== undefined,
          `Invalid easing type '${ease}'. popmotion.io/pose/api/transition`
        );

        ease = easingLookup[ease];
      } else if (Array.isArray(ease)) {
        invariant(
          ease.length === 4,
          `Cubic bezier arrays must contain four numerical values.`
        );

        const [x1, y1, x2, y2] = ease;
        ease = easing.cubicBezier(x1, y1, x2, y2);
      }
    }
  }

  return animationLookup[type]({
    from,
    to,
    velocity,
    ease,
    ...def
  });
};
开发者ID:jamesgeorge007,项目名称:popmotion,代码行数:41,代码来源:pose.ts


示例6: invariant

  Object.keys(poses).forEach(key => {
    const pose = poses[key];

    invariant(
      typeof pose === 'object',
      `Pose '${key}' is of invalid type. All poses should be objects.`
    );

    poses[key] =
      pose.transition !== undefined
        ? pose
        : applyDefaultTransition<A>(pose, key, defaultTransitions);
  });
开发者ID:jamesgeorge007,项目名称:popmotion,代码行数:13,代码来源:transitions.ts


示例7: invariant

/**
 * Create a function that maps from a numerical input array to a generic output array.
 *
 * Accepts:
 *   - Numbers
 *   - Colors (hex, hsl, hsla, rgb, rgba)
 *   - Complex (combinations of one or more numbers or strings)
 *
 * ```jsx
 * const mixColor = interpolate([0, 1], ['#fff', '#000'])
 *
 * mixColor(0.5) // 'rgba(128, 128, 128, 1)'
 * ```
 *
 * @public
 */
function interpolate<T>(
  input: number[],
  output: T[],
  { clamp = true, ease, mixer }: InterpolateOptions<T> = {}
): Mix<T | string | number> {
  const inputLength = input.length;

  invariant(
    inputLength === output.length,
    'Both input and output ranges must be the same length'
  );

  invariant(
    !ease || !Array.isArray(ease) || ease.length === inputLength - 1,
    'Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values.'
  );

  // If input runs highest -> lowest, reverse both arrays
  if (input[0] > input[inputLength - 1]) {
    input = [].concat(input);
    output = [].concat(output);
    input.reverse();
    output.reverse();
  }

  const mixers = createMixers(output, ease, mixer);

  const interpolator =
    inputLength === 2
      ? fastInterpolate(input, mixers)
      : slowInterpolate(input, mixers);

  return clamp
    ? (pipe(
        makeInputClamp(input[0], input[inputLength - 1]),
        interpolator
      ) as Mix<number | string | T>)
    : interpolator;
}
开发者ID:Popmotion,项目名称:popmotion,代码行数:55,代码来源:interpolate.ts


示例8: invariant

const createComplexAction: CreateVectorAction = (
  action,
  { from, to, ...props }
) => {
  const valueTemplate = complex.createTransformer(from);

  invariant(
    valueTemplate(from) === complex.createTransformer(to)(from),
    `Values '${from}' and '${to}' are of different format, or a value might have changed value type.`
  );

  return action({ ...props, from: 0, to: 1 }).pipe(
    blendArray(complex.parse(from), complex.parse(to)),
    valueTemplate
  );
};
开发者ID:jamesgeorge007,项目名称:popmotion,代码行数:16,代码来源:vector.ts


示例9: mounted

const createPosedComponentFactory: PosedComponentFactoryFactory = el => (
  config = {}
) =>
  Vue.extend({
    props,
    provide,
    inject,
    mounted() {
      invariant(typeof this.$el !== 'undefined', `No DOM element found.`);

      const poserConfig = {
        ...config,
        initialPose: this.getInitialPose(),
        onDragStart: this.$listeners['drag-start']
          ? (e: any) => this.$emit('drag-start', e)
          : undefined,
        onDragEnd: this.$listeners['drag-end']
          ? (e: any) => this.$emit('drag-end', e)
          : undefined,
        onPressStart: this.$listeners['press-start']
          ? (e: any) => this.$emit('press-start', e)
          : undefined,
        onPressEnd: this.$listeners['press-end']
          ? (e: any) => this.$emit('press-end', e)
          : undefined,
        onChange: this.$props.onValueChange,
        props: this.getPoserProps()
      };

      // First posed component in tree
      if (!this.$props.withParent || !this._poseRegisterChild) {
        this.initPoser(poseFactory(this.$el, poserConfig));
      } else {
        this._poseRegisterChild({
          element: this.$el,
          config: poserConfig,
          onRegistered: poser => this.initPoser(poser)
        } as ChildRegistration);
      }
    },
    watch,
    methods,
    destroyed,
    render(createElement) {
      return createElement(el, {}, [this.$slots.default]);
    }
  });
开发者ID:Popmotion,项目名称:popmotion,代码行数:47,代码来源:posed.ts


示例10: default

export default (
  value: Animated.Value,
  { type = 'tween', loop = 0, ...props }: TransitionConfig
) => {
  invariant(
    createTransition[type] !== undefined,
    `Invalid animation type '${type}' defined. Valid types are: 'tween', 'spring'`
  );

  let transition = createTransition[type](value, props);

  if (loop) {
    transition = loopTransition(transition, { iterations: loop });
  }

  return transition;
};
开发者ID:Popmotion,项目名称:popmotion,代码行数:17,代码来源:convert-transition-definition.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript hey-listen.warning函数代码示例发布时间:2022-05-25
下一篇:
TypeScript utils.shouldThrow函数代码示例发布时间: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