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

TypeScript utils.Signals类代码示例

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

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



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

示例1: setTimeout

  interactions.signals.on('down', ({ interaction, pointer, event, eventTarget, pointerIndex }) => {
    const timer = interaction.pointers[pointerIndex].hold
    const path = utils.dom.getPath(eventTarget)
    const signalArg = {
      interaction,
      pointer,
      event,
      eventTarget,
      type: 'hold',
      targets: [] as EventTargetList,
      path,
      element: null,
    }

    for (const element of path) {
      signalArg.element = element

      signals.fire('collect-targets', signalArg)
    }

    if (!signalArg.targets.length) { return }

    let minDuration = Infinity

    for (const target of signalArg.targets) {
      const holdDuration = target.eventable.options.holdDuration

      if (holdDuration < minDuration) {
        minDuration = holdDuration
      }
    }

    timer.duration = minDuration
    timer.timeout = setTimeout(() => {
      fire({
        interaction,
        eventTarget,
        pointer,
        event,
        type: 'hold',
      }, scope)
    }, minDuration)
  })
开发者ID:taye,项目名称:interact.js,代码行数:43,代码来源:base.ts


示例2:

function collectEventTargets<T extends string> ({ interaction, pointer, event, eventTarget, type }: {
  interaction: Interaction,
  pointer: Interact.PointerType,
  event: Interact.PointerEventType,
  eventTarget: Interact.EventTarget,
  type: T
}) {
  const pointerIndex = interaction.getPointerIndex(pointer)
  const pointerInfo = interaction.pointers[pointerIndex]

  // do not fire a tap event if the pointer was moved before being lifted
  if (type === 'tap' && (interaction.pointerWasMoved ||
      // or if the pointerup target is different to the pointerdown target
      !(pointerInfo && pointerInfo.downTarget === eventTarget))) {
    return []
  }

  const path = utils.dom.getPath(eventTarget)
  const signalArg = {
    interaction,
    pointer,
    event,
    eventTarget,
    type,
    path,
    targets: [] as EventTargetList,
    element: null,
  }

  for (const element of path) {
    signalArg.element = element

    signals.fire('collect-targets', signalArg)
  }

  if (type === 'hold') {
    signalArg.targets = signalArg.targets.filter((target) =>
      target.eventable.options.holdDuration === interaction.pointers[pointerIndex].hold.duration)
  }

  return signalArg.targets
}
开发者ID:taye,项目名称:interact.js,代码行数:42,代码来源:base.ts


示例3: collectEventTargets

function fire<T extends string> (arg: {
  interaction: Interaction,
  pointer: Interact.PointerType,
  event: Interact.PointerEventType,
  eventTarget: Interact.EventTarget,
  targets?: EventTargetList,
  pointerEvent?: PointerEvent<T>,
  type: T
}, scope: Interact.Scope) {
  const {
    interaction, pointer, event, eventTarget,
    type = (arg as any).pointerEvent.type,
    targets = collectEventTargets(arg),
  } = arg

  const {
    pointerEvent = new PointerEvent(type, pointer, event, eventTarget, interaction, scope.now()),
  } = arg

  const signalArg = {
    interaction,
    pointer,
    event,
    eventTarget,
    targets,
    type,
    pointerEvent,
  }

  for (let i = 0; i < targets.length; i++) {
    const target = targets[i]

    for (const prop in target.props || {}) {
      (pointerEvent as any)[prop] = target.props[prop]
    }

    const origin = utils.getOriginXY(target.eventable, target.element)

    pointerEvent._subtractOrigin(origin)
    pointerEvent.eventable = target.eventable
    pointerEvent.currentTarget = target.element

    target.eventable.fire(pointerEvent)

    pointerEvent._addOrigin(origin)

    if (pointerEvent.immediatePropagationStopped ||
        (pointerEvent.propagationStopped &&
            (i + 1) < targets.length && targets[i + 1].element !== pointerEvent.currentTarget)) {
      break
    }
  }

  signals.fire('fired', signalArg)

  if (type === 'tap') {
    // if pointerEvent should make a double tap, create and fire a doubletap
    // PointerEvent and use that as the prevTap
    const prevTap = pointerEvent.double
      ? fire({
        interaction,
        pointer,
        event,
        eventTarget,
        type: 'doubletap',
      }, scope)
      : pointerEvent

    interaction.prevTap = prevTap
    interaction.tapTime = prevTap.timeStamp
  }

  return pointerEvent
}
开发者ID:taye,项目名称:interact.js,代码行数:74,代码来源:base.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript utils.arr类代码示例发布时间:2022-05-28
下一篇:
TypeScript utils.getOriginXY函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap