UNPKG

@figliolia/react-hooks

Version:

A small collection of simple React Hooks you're probably rewriting on a regular basis

30 lines (29 loc) 686 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AnimationFrame = void 0; class AnimationFrame { constructor() { this.IDs = new Set(); } execute(callback) { const ID = requestAnimationFrame(() => { callback(); }); return () => { this.cancel(ID); }; } abortAll() { for (const ID of this.IDs) { cancelAnimationFrame(ID); } this.IDs.clear(); } cancel(ID) { if (ID && this.IDs.has(ID)) { cancelAnimationFrame(ID); this.IDs.delete(ID); } } } exports.AnimationFrame = AnimationFrame;