How to use throttleit - 10 common examples

To help you get started, we’ve selected a few throttleit 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 larsenwork / sketch-easing-gradient / resources / components / mixins / mouse.js View on Github external
this.move(event)
    })
    document.addEventListener('mouseup', this.up)
  },
  methods: {
    up() {
      this.$store.commit('mouseUp')
    },
    down(event, element) {
      this.$store.commit(
        'parentBounding',
        event.target.parentElement.getBoundingClientRect(),
      )
      this.$store.commit('mouseDown', element)
    },
    move: throttle(function(event) { // eslint-disable-line
      const element = this.$store.state.mouseElement
      if (element) {
        const cursorX =
          typeof event.clientX === 'number'
            ? event.clientX
            : event.touches[0].clientX
        const cursorY =
          typeof event.clientY === 'number'
            ? event.clientY
            : event.touches[0].clientY
        const squareLeft = this.$store.state.parentBounding.left
        const squareRight = this.$store.state.parentBounding.right
        const squareTop = this.$store.state.parentBounding.top
        const squareBottom = this.$store.state.parentBounding.bottom
        /* eslint-disable no-nested-ternary */
        const xPosition =
github buildkite / frontend / app / components / organization / AgentsCount.js View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import Relay from 'react-relay/classic';
import throttle from 'throttleit';
import { seconds } from 'metrick/duration';

import PusherStore from 'app/stores/PusherStore';

import { formatNumber } from 'app/lib/number';

// We need a `requestUpdate` queue above the React component level so
// AgentsCount components will only perform one `forceFetch` in any
// given time window. I wish this was cleaner, kid, I really do.
const requestUpdate = throttle((callback) => callback(), 3::seconds);

class AgentsCount extends React.PureComponent {
  static propTypes = {
    organization: PropTypes.shape({
      agents: PropTypes.shape({
        count: PropTypes.number.isRequired
      })
    }),
    relay: PropTypes.object.isRequired
  };

  state = {
    agentCount: this.props.organization.agents ? this.props.organization.agents.count : 0
  };

  componentDidMount() {
github conveyal / taui / src / components / geocoder / index.js View on Github external
constructor (props) {
    super(props)
    this.loadOptions = throttle(this.loadOptions, 500)
  }
github wdfe / weweb / src / service / bridge / command.js View on Github external
export function enableCompass() {
  let id = Compass.watch(throttle(head => {
    toAppService({
      msg: {
        eventName: 'onCompassChange',
        data: {
          direction: head
        }
      }
    })
  }, 200))
  router.currentView().on('destroy', () => {
    Compass.unwatch(id)
  })
}
github wdfe / weweb / src / service / bridge / command.js View on Github external
export function enableAccelerometer () {
  if (window.DeviceMotionEvent) {
    let handler = throttle(event => {
      let { x, y, z } = {
        x: event.accelerationIncludingGravity.x,
        y: event.accelerationIncludingGravity.y,
        z: event.accelerationIncludingGravity.z
      }
      if (x == null || y == null || z == null) return
      toAppService({
        msg: {
          eventName: 'onAccelerometerChange',
          data: { x, y, z }
        }
      })
    }, 200)
    window.addEventListener('devicemotion', handler, false)
    router.currentView().on('destroy', () => {
      window.removeEventListener('devicemotion', handler, false)
github xiaody / react-navigate / src / Navigation.js View on Github external
constructor (props) {
    super(props)
    const view0 = props.viewsMap[props.defaultViewName]
    if (!view0) {
      throw new Error('Invalid defaultViewName')
    }
    this.state = {
      prev: null,
      current: view0,
      direction: 'init'
    }
    this.history = [view0]
    this.goto = throttle(this.goto.bind(this), TRANSITION_DURATION)
    this.back = throttle(this.back.bind(this), TRANSITION_DURATION)
    this.onWillNav = this.onWillNav.bind(this)
    this.updateHeight = this.updateHeight.bind(this)
  }
github wdfe / weweb / src / service / bridge / command.js View on Github external
export function enableAccelerometer() {
  if(window.DeviceMotionEvent){
    let handler = throttle(event => {
      let {x, y, z} = {
        x: event.accelerationIncludingGravity.x,
        y: event.accelerationIncludingGravity.y,
        z: event.accelerationIncludingGravity.z
      }
      if (x == null || y == null || z == null) return
      toAppService({
        msg: {
          eventName: 'onAccelerometerChange',
          data: {x, y, z}
        }
      })
    }, 200)
    window.addEventListener("devicemotion", handler, false);
    router.currentView().on('destroy', () => {
      window.removeEventListener("devicemotion", handler, false);
github chemzqm / wept / src / command.js View on Github external
export function enableAccelerometer() {
  if(window.DeviceMotionEvent){
    let handler = throttle(event => {
      let {x, y, z} = {
        x: event.accelerationIncludingGravity.x,
        y: event.accelerationIncludingGravity.y,
        z: event.accelerationIncludingGravity.z
      }
      if (x == null || y == null || z == null) return
      toAppService({
        msg: {
          eventName: 'onAccelerometerChange',
          type: 'ON_APPLIFECYCLE_EVENT',
          data: {x, y, z}
        }
      })
    }, 200)
    window.addEventListener("devicemotion", handler, false);
    viewManage.currentView().on('destroy', () => {
github wdfe / weweb / src / service / bridge / command.js View on Github external
export function enableCompass () {
  let id = Compass.watch(
    throttle(head => {
      toAppService({
        msg: {
          eventName: 'onCompassChange',
          data: {
            direction: head
          }
        }
      })
    }, 200)
  )
  router.currentView().on('destroy', () => {
    Compass.unwatch(id)
  })
}
github chemzqm / wept / src / command.js View on Github external
export function enableCompass() {
  let id = Compass.watch(throttle(head => {
    toAppService({
      msg: {
        eventName: 'onCompassChange',
        type: 'ON_APPLIFECYCLE_EVENT',
        data: {
          direction: head
        }
      }
    })
  }, 200))
  viewManage.currentView().on('destroy', () => {
    Compass.unwatch(id)
  })
}

throttleit

Throttle a function to limit its execution rate

MIT
Latest version published 6 months ago

Package Health Score

76 / 100
Full package analysis

Popular throttleit functions