JSDeltaBundleClient.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #pragma once
  8. #include <cstdint>
  9. #include <memory>
  10. #include <string>
  11. #include <unordered_map>
  12. #include <cxxreact/JSBigString.h>
  13. #include <cxxreact/JSModulesUnbundle.h>
  14. #include <folly/dynamic.h>
  15. namespace facebook {
  16. namespace react {
  17. class JSDeltaBundleClient {
  18. public:
  19. void patch(const folly::dynamic &delta);
  20. JSModulesUnbundle::Module getModule(uint32_t moduleId) const;
  21. std::unique_ptr<const JSBigString> getStartupCode() const;
  22. void clear();
  23. private:
  24. std::unordered_map<uint32_t, std::string> modules_;
  25. std::string startupCode_;
  26. void patchModules(const folly::dynamic *delta);
  27. };
  28. class JSDeltaBundleClientRAMBundle : public JSModulesUnbundle {
  29. public:
  30. JSDeltaBundleClientRAMBundle(
  31. std::shared_ptr<const JSDeltaBundleClient> client)
  32. : client_(client) {}
  33. Module getModule(uint32_t moduleId) const override {
  34. return client_->getModule(moduleId);
  35. }
  36. private:
  37. const std::shared_ptr<const JSDeltaBundleClient> client_;
  38. };
  39. } // namespace react
  40. } // namespace facebook