Code Explainers
Code explainers tagged #debounce
go
func (w *Watcher) resetDebounce(d time.Duration) { if !w.timer.Stop() { select { case <-w.timer.C:
Debouncing a stream of events in Go
debounce
timers
channels
Advanced
7 steps
typescript
import { useCallback, useRef, useState } from "react"; type Tag = { id: string; label: string };
A debounced, abortable tag-input hook in React
custom-hooks
debounce
abort-controller
Advanced
10 steps
ruby
class Article < ApplicationRecord belongs_to :author has_many :taggings, dependent: :destroy has_many :tags, through: :taggings
Keeping a search index fresh in Rails
callbacks
background-jobs
debounce
Intermediate
9 steps
typescript
import { Directive, ElementRef, EventEmitter, inject, NgZone, OnDestroy, Output } from '@angular/core'; @Directive({ selector: '[appResizeDebounced]',
A debounced resize directive in Angular
debounce
change-detection
host-bindings
Advanced
7 steps
typescript
import { useState, useEffect, useRef, useCallback } from "react"; interface Suggestion { id: string;
A debounced autocomplete hook in React
debounce
custom-hooks
abortcontroller
Advanced
7 steps
go
package editor import ( "context"
How a debouncer coalesces bursts in Go
debounce
concurrency
timers
Intermediate
8 steps
javascript
const zxcvbn = require('zxcvbn'); const STRENGTH_LABELS = ['Very weak', 'Weak', 'Fair', 'Strong', 'Very strong']; const STRENGTH_COLORS = ['#d64545', '#e0803c', '#d9c94c', '#5aa84f', '#2f8f3a'];
Building a live password strength meter
debounce
closures
dom-events
Intermediate
8 steps
php
<?php namespace App\Models;
Debouncing Eloquent jobs in Laravel
debounce
model-events
queued-jobs
Advanced
7 steps
python
import threading from functools import wraps
A thread-safe debounce decorator in Python
decorators
debounce
threading
Advanced
6 steps
typescript
type ResizeCallback = (size: { width: number; height: number }) => void; export function observeResize(callback: ResizeCallback, delay = 150) { let timeoutId: ReturnType<typeof setTimeout> | undefined;
Debouncing window resize in TypeScript
debounce
closures
event-listeners
Intermediate
6 steps
javascript
import { useState, useRef, useCallback, useLayoutEffect } from "react"; export function useResizeObserver({ debounce = 0 } = {}) { const [size, setSize] = useState({ width: 0, height: 0 });
A resize-observing hook in React
custom-hook
resizeobserver
callback-ref
Advanced
8 steps
php
final class DebouncedSessionStore { private array $pending = []; private array $timers = [];
Debouncing session writes with an event loop
debounce
event-loop
atomic-write
Advanced
9 steps
rust
use std::collections::HashSet; use std::path::PathBuf; use std::time::Duration;
Debouncing filesystem events in async Rust
debounce
async
channels
Advanced
7 steps
java
public final class Debouncer<T> { private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> {
How a debouncer collapses bursts in Java
debounce
concurrency
scheduling
Intermediate
9 steps
typescript
import { Component } from '@angular/core'; import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { HttpClient } from '@angular/common/http'; import { AsyncPipe } from '@angular/common';
Reactive type-ahead search in Angular
rxjs
reactive-forms
debounce
Intermediate
9 steps
javascript
import { useState, useEffect, useCallback, useRef } from "react"; export function usePersistentForm(storageKey, initialValues) { const [values, setValues] = useState(() => {
A React hook that persists form state to localStorage
custom-hooks
localstorage
debounce
Intermediate
9 steps
javascript
import { useState, useEffect, useMemo } from 'react'; function useDebounce(value, delay = 300) { const [debounced, setDebounced] = useState(value);
Debounced search with cancellation in React
custom-hooks
debounce
abortcontroller
Intermediate
9 steps
go
package debounce import ( "sync"
Building a debouncer in Go
concurrency
debounce
timers
Intermediate
6 steps