Make the chrome debugger handle dynamic delta ids

Differential Revision: D7112419

fbshipit-source-id: 1d80c0c13144dd19bbcd5535383befc6567cacf7
This commit is contained in:
Rafael Oleza 2018-03-02 02:47:42 -08:00 коммит произвёл Facebook Github Bot
Родитель 7216079a79
Коммит 7be3d1cbaf
2 изменённых файлов: 20 добавлений и 12 удалений

Просмотреть файл

@ -30,6 +30,7 @@
pre: new Map(),
post: new Map(),
modules: new Map(),
id: undefined,
};
this._initialized = false;
this._lastNumModifiedFiles = 0;
@ -66,6 +67,7 @@
pre: new Map(),
post: new Map(),
modules: new Map(),
id: undefined,
};
}
@ -80,9 +82,15 @@
this._patchMap(this._lastBundle.post, deltaBundle.post);
this._patchMap(this._lastBundle.modules, deltaBundle.delta);
this._lastBundle.id = deltaBundle.id;
return this;
}
getLastBundleId() {
return this._lastBundle.id;
}
/**
* Returns the number of modified files in the last received Delta. This is
* currently used to populate the `X-Metro-Files-Changed-Count` HTTP header

Просмотреть файл

@ -20,31 +20,34 @@
* whole JS bundle Blob.
*/
async function deltaUrlToBlobUrl(deltaUrl) {
let cachedBundle = cachedBundleUrls.get(deltaUrl);
const client = global.DeltaPatcher.get(deltaUrl);
const deltaBundleId = cachedBundle
? `&deltaBundleId=${cachedBundle.id}`
const deltaBundleId = client.getLastBundleId()
? `&deltaBundleId=${client.getLastBundleId()}`
: '';
const data = await fetch(deltaUrl + deltaBundleId);
const bundle = await data.json();
const deltaPatcher = global.DeltaPatcher.get(bundle.id).applyDelta({
const deltaPatcher = client.applyDelta({
id: bundle.id,
pre: new Map(bundle.pre),
post: new Map(bundle.post),
delta: new Map(bundle.delta),
reset: bundle.reset,
});
let cachedBundle = cachedBundleUrls.get(deltaUrl);
// If nothing changed, avoid recreating a bundle blob by reusing the
// previous one.
if (deltaPatcher.getLastNumModifiedFiles() === 0 && cachedBundle) {
return cachedBundle.url;
return cachedBundle;
}
// Clean up the previous bundle URL to not leak memory.
if (cachedBundle) {
URL.revokeObjectURL(cachedBundle.url);
URL.revokeObjectURL(cachedBundle);
}
// To make Source Maps work correctly, we need to add a newline between
@ -58,13 +61,10 @@
type: 'application/javascript',
});
const bundleUrl = URL.createObjectURL(blob);
cachedBundleUrls.set(deltaUrl, {
id: bundle.id,
url: bundleUrl,
});
const bundleContents = URL.createObjectURL(blob);
cachedBundleUrls.set(deltaUrl, bundleContents);
return bundleUrl;
return bundleContents;
}
global.deltaUrlToBlobUrl = deltaUrlToBlobUrl;