/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/ReactCommon/react/renderer/animated/MergedValueDispatcher.h
56 строк
2 KB
Samuel Susla
Move C++ Animated to ReactCommon (#53278)
18 авг 2025, 14:13
18 авг 2025, 14:13
3a3e3b8
Код
Авторство
О чём код?
/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include <folly/dynamic.h> #include <react/renderer/core/ReactPrimitives.h> #include <functional> #include <mutex> namespace facebook::react { /** * A thread-safe dispatcher that ensures only the latest value is dispatched * to avoid overloading the target thread. Multiple rapid calls are coalesced * into a single dispatch operation merging the values. */ class MergedValueDispatcher { public: using DispatchFunction = std::function<void(std::function<void()>&&)>; using MergedValueFunction = std::function<void(std::unordered_map<Tag, folly::dynamic>&& tagToProps)>; /** * Creates a MergedValueDispatcher with the given dispatch function. * * @param dispatchFunction - function that dispatches to the target * thread. * @param latestValueFunction - function that will be called on the target * thread with all values merged. */ explicit MergedValueDispatcher( DispatchFunction dispatchFunction, MergedValueFunction mergedValueFunction); /** * Dispatches the given value. If a dispatch is already pending, this will * merge with the pending value instead of creating a new dispatch. * * @param value - value to be dispatched. */ void dispatch(const std::unordered_map<Tag, folly::dynamic>& value); private: DispatchFunction dispatchFunction_; MergedValueFunction mergedValueFunction_; std::mutex mutex_; bool hasPendingDispatch_{false}; std::unordered_map<Tag, folly::dynamic> accumulatedValues_; }; } // namespace facebook::react