guardia-messenger/node_modules/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp
DESKTOP-TKLFCPRython f29f525c77 refactor: 101.79.17.164 → zioinfo.co.kr 전체 도메인 변환 + Manager UI 배포
- 37개 파일 IP → zioinfo.co.kr 치환 (소스/매뉴얼/설정/하네스)
- Manager DrConsole/NetworkConsole/CsapConsole 빌드 + /var/www/manager/ 배포
- 테스트: Manager HTTP 200, ITSM 신규 API 7개 전체 200

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 10:09:17 +09:00

143 lines
3.9 KiB
C++

/*
* 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.
*/
#include "MutationObserverManager.h"
#include <react/renderer/debug/SystraceSection.h>
#include <utility>
#include "MutationObserver.h"
namespace facebook::react {
MutationObserverManager::MutationObserverManager() = default;
void MutationObserverManager::observe(
MutationObserverId mutationObserverId,
ShadowNode::Shared shadowNode,
bool observeSubtree,
const UIManager& uiManager) {
SystraceSection s("MutationObserverManager::observe");
auto surfaceId = shadowNode->getSurfaceId();
auto& observers = observersBySurfaceId_[surfaceId];
auto observerIt = observers.find(mutationObserverId);
if (observerIt == observers.end()) {
auto observer = MutationObserver{mutationObserverId};
observer.observe(shadowNode, observeSubtree);
observers.insert({mutationObserverId, std::move(observer)});
} else {
auto observer = observerIt->second;
observer.observe(shadowNode, observeSubtree);
}
}
void MutationObserverManager::unobserve(
MutationObserverId mutationObserverId,
const ShadowNode& shadowNode) {
SystraceSection s("MutationObserverManager::unobserve");
auto surfaceId = shadowNode.getSurfaceId();
auto observersIt = observersBySurfaceId_.find(surfaceId);
if (observersIt == observersBySurfaceId_.end()) {
return;
}
auto& observers = observersIt->second;
auto observerIt = observers.find(mutationObserverId);
if (observerIt == observers.end()) {
return;
}
auto& observer = observerIt->second;
observer.unobserve(shadowNode);
if (!observer.isObserving()) {
observers.erase(mutationObserverId);
}
if (observers.empty()) {
observersBySurfaceId_.erase(surfaceId);
}
}
void MutationObserverManager::connect(
UIManager& uiManager,
std::function<void(std::vector<MutationRecord>&)> onMutations) {
SystraceSection s("MutationObserverManager::connect");
// Fail-safe in case the caller doesn't guarantee consistency.
if (commitHookRegistered_) {
return;
}
onMutations_ = onMutations;
uiManager.registerCommitHook(*this);
commitHookRegistered_ = true;
}
void MutationObserverManager::disconnect(UIManager& uiManager) {
SystraceSection s("MutationObserverManager::disconnect");
// Fail-safe in case the caller doesn't guarantee consistency.
if (!commitHookRegistered_) {
return;
}
uiManager.unregisterCommitHook(*this);
onMutations_ = nullptr;
commitHookRegistered_ = false;
}
void MutationObserverManager::commitHookWasRegistered(
const UIManager& uiManager) noexcept {}
void MutationObserverManager::commitHookWasUnregistered(
const UIManager& uiManager) noexcept {}
RootShadowNode::Unshared MutationObserverManager::shadowTreeWillCommit(
const ShadowTree& shadowTree,
const RootShadowNode::Shared& oldRootShadowNode,
const RootShadowNode::Unshared& newRootShadowNode) noexcept {
runMutationObservations(shadowTree, *oldRootShadowNode, *newRootShadowNode);
return newRootShadowNode;
}
void MutationObserverManager::runMutationObservations(
const ShadowTree& shadowTree,
const RootShadowNode& oldRootShadowNode,
const RootShadowNode& newRootShadowNode) {
SystraceSection s("MutationObserverManager::runMutationObservations");
auto surfaceId = shadowTree.getSurfaceId();
auto observersIt = observersBySurfaceId_.find(surfaceId);
if (observersIt == observersBySurfaceId_.end()) {
return;
}
std::vector<MutationRecord> mutationRecords;
auto& observers = observersIt->second;
for (const auto& [mutationObserverId, observer] : observers) {
observer.recordMutations(
oldRootShadowNode, newRootShadowNode, mutationRecords);
}
if (!mutationRecords.empty()) {
onMutations_(mutationRecords);
}
return;
}
} // namespace facebook::react