SharedProxyCxxModule.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) Facebook, Inc. and its 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. #include <memory>
  8. #include <cxxreact/CxxModule.h>
  9. namespace facebook {
  10. namespace xplat {
  11. namespace module {
  12. // Allows a Cxx-module to be shared or reused across multiple React instances
  13. // Caveat: the setInstance call is not forwarded, so usages of getInstance
  14. // inside your module (e.g. dispatching events) will always be nullptr.
  15. class SharedProxyCxxModule : public CxxModule {
  16. public:
  17. explicit SharedProxyCxxModule(std::shared_ptr<CxxModule> shared)
  18. : shared_(shared) {}
  19. std::string getName() override {
  20. return shared_->getName();
  21. }
  22. auto getConstants() -> std::map<std::string, folly::dynamic> override {
  23. return shared_->getConstants();
  24. }
  25. auto getMethods() -> std::vector<Method> override {
  26. return shared_->getMethods();
  27. }
  28. private:
  29. std::shared_ptr<CxxModule> shared_;
  30. };
  31. } // namespace module
  32. } // namespace xplat
  33. } // namespace facebook