UNPKG

@sanity/desk-tool

Version:

Tool for managing all sorts of content in a structured manner

36 lines (34 loc) 794 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.raf = raf; exports.raf2 = raf2; /** * @internal */ function raf(fn) { var frameId = requestAnimationFrame(fn); return () => { cancelAnimationFrame(frameId); }; } /** * This is a function for calling a callback insid a double `requestAnimationFrame` (RAF). * This is useful for reliably triggering animations. * * The reason for using a double RAF is a common "bug" in browsers. * See: https://stackoverflow.com/questions/44145740/how-does-double-requestanimationframe-work * * @internal */ function raf2(fn) { var innerDispose = null; var outerDispose = raf(() => { innerDispose = raf(fn); }); return () => { if (innerDispose) innerDispose(); outerDispose(); }; }