react-native/ReactCommon/cxxreact/JSDeltaBundleClient.h
David Aurelio 4d931d529e Add native delta client for Metro
Summary:
Adds C++ delta client that keeps modules in memory, and can be used as a RAM bundle.

For now, this client expects a `folly::dynamic` object as payload for patches, i.e. the JSON response retrieved from Metro needs to be parsed with `folly::parseJson` by the caller.

In the future, we will replace JSON with a streaming friendly binary format.

Reviewed By: fromcelticpark

Differential Revision: D7845136

fbshipit-source-id: f003f98a2607c8354c427a7e60e01e19e20295b1
2018-05-03 08:47:47 -07:00

43 lines
1010 B
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>
#include <cxxreact/JSBigString.h>
#include <cxxreact/JSModulesUnbundle.h>
#include <folly/dynamic.h>
namespace facebook {
namespace react {
class JSDeltaBundleClient {
public:
void patch(const folly::dynamic& delta);
JSModulesUnbundle::Module getModule(uint32_t moduleId) const;
std::unique_ptr<const JSBigString> getStartupCode() const;
void clear();
private:
std::unordered_map<uint32_t, std::string> modules_;
std::string startupCode_;
};
class JSDeltaBundleClientRAMBundle : public JSModulesUnbundle {
public:
JSDeltaBundleClientRAMBundle(
std::shared_ptr<const JSDeltaBundleClient> client) : client_(client) {}
Module getModule(uint32_t moduleId) const override {
return client_->getModule(moduleId);
}
private:
const std::shared_ptr<const JSDeltaBundleClient> client_;
};
} // namespace react
} // namespace facebook