How to use debounce-fn - 9 common examples

To help you get started, we’ve selected a few debounce-fn 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 sindresorhus / refined-github / source / features / sticky-discussion-sidebar.tsx View on Github external
import './sticky-discussion-sidebar.css';
import select from 'select-dom';
import debounce from 'debounce-fn';
import onDomReady from 'dom-loaded';
import features from '../libs/features';
import onUpdatableContentUpdate from '../libs/on-updatable-content-update';

const sideBarSelector = '#partial-discussion-sidebar, .discussion-sidebar';

function updateStickiness(): void {
	const sidebar = select(sideBarSelector)!;
	const sidebarHeight = sidebar.offsetHeight + 60; // 60 matches sticky header's height
	sidebar.classList.toggle('rgh-sticky-sidebar', sidebarHeight < window.innerHeight);
}

const handler = debounce(updateStickiness, {wait: 100});

async function init(): Promise {
	await onDomReady;
	updateStickiness();
	window.addEventListener('resize', handler);
	onUpdatableContentUpdate(select(sideBarSelector)!, updateStickiness);
}

function deinit(): void {
	window.removeEventListener('resize', handler);
}

features.add({
	id: __featureName__,
	description: 'Makes the discussion sidebar sticky.',
	screenshot: 'https://user-images.githubusercontent.com/10238474/62276723-5a2eaa80-b44d-11e9-810b-ff598d1c5c6a.gif',
github tdeekens / flopflip / packages / launchdarkly-adapter / modules / adapter / adapter.ts View on Github external
if (!this._didFlagChange(normalizedFlagName, normalizedFlagValue))
            return;

          const updatedFlags: Flags = {
            [normalizedFlagName]: normalizedFlagValue,
          };

          // NOTE: Adapter state needs to be updated outside of debounced-fn
          // so that no flag updates are lost.
          updateFlagsInAdapterState(updatedFlags);

          const updateFlags = () => {
            adapterEventHandlers.onFlagsStateChange(adapterState.flags);
          };

          debounce(updateFlags, {
            wait: flagsUpdateDelayMs,
            immediate: !flagsUpdateDelayMs,
          })();
        });
      }
github npezza93 / archipelago / app / renderer / app / terminal.jsx View on Github external
fit() {
    if (this.props.tabId === this.props.currentTabId) {
      debouncer(this.props.session.fit, {wait: 150})()
    }
  }
github uber / react-vis / www / src / screens / search.js View on Github external
function useDebFn(cb, opts) {
  return React.useCallback(debounceFn(cb, opts), [])
}
github npezza93 / archipelago / app / renderer / sessions / session.js View on Github external
resetBlink() {
    debouncer(() => {
      if (this.currentProfile.get('cursorBlink')) {
        this.xterm.setOption('cursorBlink', false)
        this.xterm.setOption('cursorBlink', true)
      }
    }, {wait: 50})()
  }
github BeeDesignLLC / GlutenProject.com / components / SearchBoss.js View on Github external
import {Configure} from 'react-instantsearch/dom'
import InstantSearch from './InstantSearch'

type Props = {
  children?: React.Node,
  q?: string,
  initialSearchState: Object,
  initialResultsState: Object,
}
type State = {
  searchState: Object,
  production: boolean,
}

const debouncedRouterReplace = debounce(Router.replace, {wait: 700})
const debouncedTrackSearch = debounce(
  query => {
    window.gtag && window.gtag('event', 'search', {search_term: query})
  },
  {wait: 700}
)

class SearchBoss extends React.Component {
  state = {
    searchState: this.props.initialSearchState || {query: this.props.q || ''},
    production: true,
  }

  componentDidMount() {
    if (!isPresent(this.state.searchState.query) && Router.pathname === '/search') {
      const searchInput = window.document.querySelector('#global-product-search')
      if (searchInput) searchInput.focus()
github BeeDesignLLC / GlutenProject.com / components / SearchBoss.js View on Github external
import {urlForQuery} from '../utils/misc'
import {Configure} from 'react-instantsearch/dom'
import InstantSearch from './InstantSearch'

type Props = {
  children?: React.Node,
  q?: string,
  initialSearchState: Object,
  initialResultsState: Object,
}
type State = {
  searchState: Object,
  production: boolean,
}

const debouncedRouterReplace = debounce(Router.replace, {wait: 700})
const debouncedTrackSearch = debounce(
  query => {
    window.gtag && window.gtag('event', 'search', {search_term: query})
  },
  {wait: 700}
)

class SearchBoss extends React.Component {
  state = {
    searchState: this.props.initialSearchState || {query: this.props.q || ''},
    production: true,
  }

  componentDidMount() {
    if (!isPresent(this.state.searchState.query) && Router.pathname === '/search') {
      const searchInput = window.document.querySelector('#global-product-search')
github contentful / extensions / samples / content-tree / src / index.js View on Github external
constructor(props) {
    super(props)
    this.state = {
      allContentTypes: [],
      childReferences: [],
      entryMap: {},
      siblingReferences: []
    }

    this.onViewingEntryUpdated = debounce(this.onViewingEntryUpdated, {
      wait: 250
    })
  }
github learn-anything / learn-anything / src / pages / index.js View on Github external
function useDebFn(cb, opts) {
  return React.useCallback(debounceFn(cb, opts), []);
}

debounce-fn

Debounce a function

MIT
Latest version published 9 months ago

Package Health Score

71 / 100
Full package analysis

Popular debounce-fn functions