How to use the @better-scroll/shared-utils.EventEmitter function in @better-scroll/shared-utils

To help you get started, we’ve selected a few @better-scroll/shared-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ustbhuangyi / better-scroll / packages / core / src / __mocks__ / index.ts View on Github external
'refresh',
    'enable',
    'disable',
    'destroy',
    // scroller
    'beforeScrollStart',
    'scrollStart',
    'scroll',
    'scrollEnd',
    'touchEnd',
    'flick'
  ])
  const res = {
    wrapper: wrapper,
    options: options,
    hooks: new EventEmitter([
      'init',
      'refresh',
      'enable',
      'disable',
      'destroy'
    ]),
    scroller: new Scroller(wrapper, options),
    // own methods
    proxy: jest.fn(),
    refresh: jest.fn(),
    // proxy methods
    scrollTo: jest.fn(),
    resetPosition: jest.fn(),
    registerType: jest.fn().mockImplementation((names: string[]) => {
      names.forEach(name => {
        const eventTypes = eventEmitter.eventTypes
github ustbhuangyi / better-scroll / packages / core / src / utils / __tests__ / bubbling.spec.ts View on Github external
it('bubbling', () => {
    const parentHooks = new EventEmitter(['test'])
    const childHooks = new EventEmitter(['test'])
    bubbling(childHooks, parentHooks, ['test'])
    const handler = jest.fn(() => {})
    parentHooks.on('test', handler)
    childHooks.trigger('test', 'dummy test')
    expect(handler).toBeCalledWith('dummy test')
  })
})
github ustbhuangyi / better-scroll / packages / core / src / utils / __tests__ / bubbling.spec.ts View on Github external
it('bubbling', () => {
    const parentHooks = new EventEmitter(['test'])
    const childHooks = new EventEmitter(['test'])
    bubbling(childHooks, parentHooks, ['test'])
    const handler = jest.fn(() => {})
    parentHooks.on('test', handler)
    childHooks.trigger('test', 'dummy test')
    expect(handler).toBeCalledWith('dummy test')
  })
})
github ustbhuangyi / better-scroll / packages / slide / src / __tests__ / Slide.spec.ts View on Github external
beforeAll(() => {
    hooks = new EventEmitter([
      'beforeStart',
      'scroll',
      'refresh',
      'momentum',
      'scrollEnd',
      'forceStop',
      'flick',
      'destroy'
    ])
  })
github ustbhuangyi / better-scroll / packages / zoom / src / __tests__ / Zoom.spec.ts View on Github external
beforeAll(() => {
    hooks = new EventEmitter([
      'start',
      'beforeMove',
      'beforeEnd',
      'beforeTranslate',
      'destroy',
      'zoomStart',
      'zoomEnd',
      'ignoreDisMoveForSamePos'
    ])
  })
github ustbhuangyi / better-scroll / packages / core / src / base / __mocks__ / ActionsHandler.ts View on Github external
.mockImplementation((wrapper, bscrollOptions) => {
    return {
      wrapper,
      options: bscrollOptions,
      initiated: 1,
      pointX: 0,
      pointY: 0,
      startClickRegister: new EventRegister(wrapper, []),
      moveEndRegister: new EventRegister(wrapper, []),
      hooks: new EventEmitter(['beforeStart', 'start', 'move', 'end', 'click']),
      destroy: jest.fn()
    }
  })
github ustbhuangyi / better-scroll / packages / core / src / scroller / __mocks__ / Scroller.ts View on Github external
const actions = new Actions(
    scrollBehaviorX,
    scrollBehaviorY,
    actionsHandler,
    animater,
    bscrollOptions
  )
  return {
    wrapper,
    content,
    options: bscrollOptions,
    translater,
    animater,
    actionsHandler,
    actions,
    hooks: new EventEmitter([
      'beforeStart',
      'beforeMove',
      'beforeScrollStart',
      'scrollStart',
      'scroll',
      'beforeEnd',
      'scrollEnd',
      'refresh',
      'touchEnd',
      'end',
      'flick',
      'scrollCancel',
      'momentum',
      'scrollTo',
      'scrollToElement',
      'transitionEnd',
github ustbhuangyi / better-scroll / packages / core / src / scroller / __mocks__ / Behavior.ts View on Github external
const Behavior = jest.fn().mockImplementation((content, bscrollOptions) => {
  return {
    content,
    options: bscrollOptions,
    startPos: 0,
    absStartPos: 0,
    dist: 0,
    minScrollPos: 0,
    maxScrollPos: 0,
    hasScroll: true,
    direction: 0,
    movingDirection: 0,
    relativeOffset: 0,
    wrapperSize: 0,
    contentSize: 0,
    hooks: new EventEmitter(['momentum', 'end']),
    start: jest.fn(),
    move: jest.fn(),
    end: jest.fn(),
    updateDirection: jest.fn(),
    refresh: jest.fn(),
    updatePosition: jest.fn(),
    getCurrentPos: jest.fn(),
    checkInBoundary: jest.fn(),
    adjustPosition: jest.fn(),
    updateStartPos: jest.fn(),
    updateAbsStartPos: jest.fn(),
    resetStartPos: jest.fn(),
    getAbsDist: jest.fn(),
    destroy: jest.fn()
  }
})
github ustbhuangyi / better-scroll / packages / scroll-bar / src / event-handler.ts View on Github external
) {
    this.bscroll = indicator.bscroll
    this.startEventRegister = new EventRegister(this.indicator.el, [
      {
        name: options.disableMouse ? 'touchstart' : 'mousedown',
        handler: this._start.bind(this)
      }
    ])

    this.endEventRegister = new EventRegister(window, [
      {
        name: options.disableMouse ? 'touchend' : 'mouseup',
        handler: this._end.bind(this)
      }
    ])
    this.hooks = new EventEmitter(['touchStart', 'touchMove', 'touchEnd'])
  }
github ustbhuangyi / better-scroll / packages / scroll-bar / src / __mocks__ / event-handler.ts View on Github external
const EventHandler = jest.fn().mockImplementation(() => {
  return {
    hooks: new EventEmitter(['touchStart', 'touchMove', 'touchEnd'])
  }
})