How to use @instructure/debounce - 6 common examples

To help you get started, we’ve selected a few @instructure/debounce 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 instructure / instructure-ui / packages / ui-layout / src / addElementQueryMatchListener.js View on Github external
.filter(key => matchingQueries[key])
      .map(key => key)

    // we only call back if the matches have changed
    if (matches.length !== newMatches.length) {
      matches = newMatches
      cb(matches)
    }

    if (matches.filter(match => newMatches.indexOf(match) === -1).length > 0) {
      matches = newMatches
      cb(matches)
    }
  }

  const debounced = debounce(updateElementMatches, 100, { leading: false, trailing: true })
  const elementResizeListener = addResizeListener(node, debounced)
  const { width, height } = getBoundingClientRect(node)

  updateElementMatches({ width, height })

  return {
    remove () {
      if (elementResizeListener) {
        elementResizeListener.remove()
      }

      if (debounced) {
        debounced.cancel()
      }
    }
  }
github instructure / instructure-ui / packages / ui-layout / src / DrawerLayout / DrawerContent / index.js View on Github external
componentDidMount () {
    const rect = getBoundingClientRect(this._content)
    // set initial size
    this.props.onSizeChange({width: rect.width, height: rect.height})
    // listen for changes to size
    this._debounced = debounce(this.props.onSizeChange, 100, {leading: false, trailing: true})
    this._resizeListener = addResizeListener(this._content, this._debounced)
  }
github instructure / instructure-ui / packages / ui-test-utils / src / utils / waitForQueryResult.js View on Github external
return new Promise((resolve, reject) => {
    const debouncedQuery = debounce(runQuery, 10, { leading: false, trailing: true })

    let lastError, observer, timer, lastResult

    lastResult = {}

    function runQuery () {
      if (typeof queryFn !== 'function') {
        lastResult = {
          results: [],
          selector: JSON.stringify(queryFn)
        }
        onDone(new Error([
          '[ui-test-utils] Invalid element query function.',
          lastResult.selector
        ].join('\n')), lastResult)
        return
github instructure / instructure-ui / packages / ui-navigation / src / AppNav / index.js View on Github external
componentDidMount () {
    this._debounced = debounce(this.handleResize, this.props.debounce, { leading: true, trailing: true })
    this._resizeListener = addResizeListener(this._list, this._debounced)

    this.handleResize()
  }
github instructure / instructure-ui / packages / ui-position / src / Position / index.js View on Github external
constructor (props) {
    super(props)

    this.state = {
      positioned: false,
      ...this.calculatePosition(props)
    }

    this.position = debounce(this.position, 0, { leading: false, trailing: true })
    this._id = this.props.id || uid('Position')
  }
github instructure / instructure-ui / packages / ui-elements / src / TruncateText / index.js View on Github external
componentDidMount () {
    const { children } = this.props

    if (children) {
      this.checkChildren()
      this._text = ensureSingleChild(children)

      this.truncate()

      if (this.props.debounce === 0) {
        this._resizeListener = addResizeListener(this._ref, this.update)
      } else {
        this._debounced = debounce(this.update, this.props.debounce, { leading: true, trailing: true })
        this._resizeListener = addResizeListener(this._ref, this._debounced)
      }
    }
  }

@instructure/debounce

A debounce util made by Instructure Inc.

MIT
Latest version published 16 days ago

Package Health Score

87 / 100
Full package analysis

Popular @instructure/debounce functions

Similar packages