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


TypeScript _helpers.mockSignals函数代码示例

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


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

示例1: test

test('pointerEvents.collectEventTargets', (t) => {
  const type = 'TEST'
  const TEST_PROP = ['TEST_PROP']
  const target = {
    TEST_PROP,
    eventable: new Eventable(pointerEvents.defaults),
  }
  let collectedTargets

  function onCollect ({ targets }) {
    targets.push(target)

    collectedTargets = targets
  }

  pointerEvents.signals.on('collect-targets', onCollect)
  pointerEvents.collectEventTargets({
    interaction: new Interaction({ signals: helpers.mockSignals() } as any),
    pointer: {},
    event: {},
    eventTarget: {},
    type,
  } as any)

  t.deepEqual(collectedTargets, [target])

  pointerEvents.signals.off('collect-targets', onCollect)

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:30,代码来源:base.spec.ts

示例2: test

test('restrictSize', (t) => {
  const edges = { left: true, top: true }
  const rect = { left: 0, top: 0, right: 200, bottom: 300 }
  const interaction = new Interaction({ signals: mockSignals() } as any)

  interaction.prepared = { name: null }
  interaction.prepared.edges = edges
  interaction.resizeRects = {} as any
  interaction.resizeRects.inverted = rectUtils.xywhToTlbr(rect)
  interaction.modifiers = {} as any
  interaction._interacting = true

  const options = {
    min: { width:  60, height:  50 },
    max: { width: 300, height: 350 },
  }
  const startCoords = Object.freeze({ x: 0, y: 0 })
  const offset = { top: 0, bottom: 0, left: 0, right: 0 }
  const state = {
    options,
    offset,
    methods: restrictSize,
  }
  const arg = {
    interaction,
    states: [state],
    coords: startCoords,
    pageCoords: startCoords,
    options,
    state: null,
  }

  interaction.modifiers.startOffset = base.getRectOffset(rect, startCoords)
  base.startAll(arg)
  arg.state = state

  const move1 = Object.freeze({ x: -50, y: -40 })
  arg.coords = { ...move1 }
  restrictSize.set(arg)

  t.deepEqual(arg.coords, move1, 'within both min and max')

  const move2 = Object.freeze({ x: -200, y: -300 })
  arg.coords = { ...move2 }
  restrictSize.set(arg)

  t.deepEqual(arg.coords, { x: -100, y: -50 }, 'outside max')

  const move3 = Object.freeze({ x: 250, y: 320 })
  arg.coords = { ...move3 }
  restrictSize.set(arg)

  t.deepEqual(arg.coords, { x: 140, y: 250 }, 'outside min')

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:56,代码来源:size.spec.ts

示例3: test

test('restrictEdges', (t) => {
  const interaction = new Interaction({ signals: mockSignals() } as any)
  interaction.prepared = {} as any
  interaction.prepared.edges = { top: true, bottom: true, left: true, right: true }
  interaction.resizeRects = {} as any
  interaction.resizeRects.inverted = { x: 10, y: 20, width: 300, height: 200 } as any
  interaction._interacting = true

  const options: any = { enabled: true }
  const coords = { x: 40, y: 40 }
  const offset = { top: 0, left: 0, bottom: 0, right: 0 }
  const state = { options, offset }
  const arg = { interaction, state } as any

  arg.coords = { ...coords }

  // outer restriction
  options.outer = { top: 100, left: 100, bottom: 200, right: 200 }
  restrictEdges.set(arg)

  t.deepEqual(
    arg.coords,
    { x: coords.y + 60, y: coords.y + 60 },
    'outer restriction is applied correctly'
  )

  arg.coords = { ...coords }

  // inner restriction
  options.outer = null
  options.inner = { top: 0, left: 0, bottom: 10, right: 10 }
  restrictEdges.set(arg)

  t.deepEqual(
    arg.coords,
    { x: coords.x - 40, y: coords.y - 40 },
    'inner restriction is applied correctly'
  )

  // offset
  Object.assign(offset, {
    top: 100,
    left: 100,
    bottom: 200,
    right: 200,
  })
  arg.coords = { ...coords }

  options.outer = { top: 100, left: 100, bottom: 200, right: 200 }
  options.inner = null
  restrictEdges.set(arg)

  t.deepEqual(
    arg.coords,
    { x: coords.x + 160, y: coords.x + 160 },
    'outer restriction is applied correctly with offset'
  )

  // start
  interaction.modifiers = {} as any
  interaction.modifiers.startOffset = { top: 5, left: 10, bottom: -8, right: -16 }
  interaction.interactable = {
    getRect () {
      return { top: 500, left: 900 }
    },
  } as any

  options.offset = 'self'
  restrictEdges.start(arg)

  t.deepEqual(
    arg.state.offset,
    { top: 505, left: 910, bottom: 508, right: 916 },
    'start gets x/y from selector string'
  )

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:78,代码来源:edges.spec.ts


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