| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | import {requestPostPaintCallback} from './ReactFiberConfig'; |
| 10 | |
| 11 | let postPaintCallbackScheduled = false; |
| 12 | let callbacks: Array<any | ((endTime: number) => void)> = []; |
| 13 | |
| 14 | export function schedulePostPaintCallback(callback: (endTime: number) => void) { |
| 15 | callbacks.push(callback); |
| 16 | if (!postPaintCallbackScheduled) { |
| 17 | postPaintCallbackScheduled = true; |
| 18 | requestPostPaintCallback(endTime => { |
| 19 | for (let i = 0; i < callbacks.length; i++) { |
| 20 | callbacks[i](endTime); |
| 21 | } |
| 22 | postPaintCallbackScheduled = false; |
| 23 | callbacks = []; |
| 24 | }); |
| 25 | } |
| 26 | } |