diff --git a/ReactCommon/utils/ContextContainer.h b/ReactCommon/utils/ContextContainer.h index 835b7f0db72..a8d09655660 100644 --- a/ReactCommon/utils/ContextContainer.h +++ b/ReactCommon/utils/ContextContainer.h @@ -62,6 +62,25 @@ class ContextContainer final { #endif } + /* + * Updates the container with values from a given container. + * Values with keys that already exist in the container will be replaced with + * values from the given container. + */ + void update(ContextContainer const &contextContainer) const { + std::unique_lock lock(mutex_); + + for (auto const &pair : contextContainer.instances_) { + instances_.erase(pair.first); + instances_.insert(pair); +#ifndef NDEBUG + typeNames_.erase(pair.first); + typeNames_.insert( + {pair.first, contextContainer.typeNames_.at(pair.first)}); +#endif + } + } + /* * Returns a previously registered instance of the particular type `T` * for `key`.