/* * 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 #include #include #include namespace facebook::react { using MutationObserverId = int32_t; struct MutationRecord { MutationObserverId mutationObserverId; ShadowNode::Shared targetShadowNode; std::vector addedShadowNodes; std::vector removedShadowNodes; }; class MutationObserver { public: MutationObserver(MutationObserverId intersectionObserverId); void observe(ShadowNode::Shared targetShadowNode, bool observeSubtree); void unobserve(const ShadowNode& targetShadowNode); bool isObserving() const; void recordMutations( const RootShadowNode& oldRootShadowNode, const RootShadowNode& newRootShadowNode, std::vector& recordedMutations) const; private: MutationObserverId mutationObserverId_; std::vector deeplyObservedShadowNodes_; std::vector shallowlyObservedShadowNodes_; using SetOfShadowNodePointers = std::unordered_set; void recordMutationsInTarget( ShadowNode::Shared targetShadowNode, const RootShadowNode& oldRootShadowNode, const RootShadowNode& newRootShadowNode, bool observeSubtree, std::vector& recordedMutations, SetOfShadowNodePointers& processedNodes) const; void recordMutationsInSubtrees( ShadowNode::Shared targetShadowNode, const ShadowNode& oldNode, const ShadowNode& newNode, bool observeSubtree, std::vector& recordedMutations, SetOfShadowNodePointers processedNodes) const; }; } // namespace facebook::react