Update the Delta/HMR format

Summary:
Makes the delta bundle data structures more consistent.

The changes are as follows:
* There are now two types of JSON bundles that can be downloaded from the delta endpoint. Base bundles (`Bundle` type), and Delta bundles (`DeltaBundle` type).
* The `reset` boolean is renamed to `base`.
* `pre` and `post` properties are now strings.
* Only `Bundle` can define `pre` and `post` properties.
* The `delta` property is renamed to `modules`.
* Deleted modules are now listed inside of the `deleted` property, which is only defined by `DeltaBundle`.

Reviewed By: mjesun

Differential Revision: D10446831

fbshipit-source-id: 40e229a2811d48950f0bad8dd341ece189089e9b
This commit is contained in:
Alexandre Kirszenberg
2018-10-29 08:58:30 -07:00
committed by Facebook Github Bot
parent bb93abf5ca
commit 1eedf05651
4 changed files with 88 additions and 81 deletions
+15 -15
View File
@@ -13,9 +13,7 @@ namespace {
for (auto section : {pre, post}) {
if (section != nullptr) {
for (folly::dynamic pair : *section) {
startupCode << pair[1].getString() << '\n';
}
startupCode << section->getString() << '\n';
}
}
@@ -24,28 +22,30 @@ namespace {
} // namespace
void JSDeltaBundleClient::patch(const folly::dynamic& delta) {
auto const reset = delta.get_ptr("reset");
if (reset != nullptr && reset->asBool()) {
auto const base = delta.get_ptr("base");
if (base != nullptr && base->asBool()) {
clear();
}
auto const pre = delta.get_ptr("pre");
auto const post = delta.get_ptr("post");
auto const pre = delta.get_ptr("pre");
auto const post = delta.get_ptr("post");
if ((pre != nullptr && pre->size() > 0) || (post != nullptr && post->size() > 0)) {
startupCode_ = startupCode(pre, post);
} else {
const folly::dynamic *deleted = delta.get_ptr("deleted");
if (deleted != nullptr) {
for (const folly::dynamic id : *deleted) {
modules_.erase(id.getInt());
}
}
}
const folly::dynamic *modules = delta.get_ptr("delta");
const folly::dynamic *modules = delta.get_ptr("modules");
if (modules != nullptr) {
for (const folly::dynamic pair : *modules) {
auto id = pair[0].getInt();
auto module = pair[1];
if (module.isNull()) {
modules_.erase(id);
} else {
modules_.emplace(id, module.getString());
}
modules_.emplace(id, module.getString());
}
}
}