HMR nits detected by the linter
Reviewed By: davidaurelio Differential Revision: D3042850 fb-gh-sync-id: 03fd239b0dea2d7d4ef778e2d07d41af84fe310d shipit-source-id: 03fd239b0dea2d7d4ef778e2d07d41af84fe310d
This commit is contained in:
Родитель
83095f95b5
Коммит
780a513b7b
|
@ -62,12 +62,16 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
|
|
||||||
// map from module name to path
|
// map from module name to path
|
||||||
const moduleToFilenameCache = Object.create(null);
|
const moduleToFilenameCache = Object.create(null);
|
||||||
deps.forEach(dep => moduleToFilenameCache[dep.name] = dep.path);
|
deps.forEach(dep => {
|
||||||
|
moduleToFilenameCache[dep.name] = dep.path;
|
||||||
|
});
|
||||||
|
|
||||||
// map that indicates the shallow dependency each file included on the
|
// map that indicates the shallow dependency each file included on the
|
||||||
// bundle has
|
// bundle has
|
||||||
const shallowDependencies = Object.create(null);
|
const shallowDependencies = Object.create(null);
|
||||||
deps.forEach(dep => shallowDependencies[dep.path] = dep.deps);
|
deps.forEach(dep => {
|
||||||
|
shallowDependencies[dep.path] = dep.deps;
|
||||||
|
});
|
||||||
|
|
||||||
// map from module name to the modules' dependencies the bundle entry
|
// map from module name to the modules' dependencies the bundle entry
|
||||||
// has
|
// has
|
||||||
|
@ -128,8 +132,8 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
`[Hot Module Replacement] File change detected (${time()})`
|
`[Hot Module Replacement] File change detected (${time()})`
|
||||||
);
|
);
|
||||||
|
|
||||||
const blacklisted = blacklist.find(path =>
|
const blacklisted = blacklist.find(blacklistedPath =>
|
||||||
filename.indexOf(path) !== -1
|
filename.indexOf(blacklistedPath) !== -1
|
||||||
);
|
);
|
||||||
|
|
||||||
if (blacklisted) {
|
if (blacklisted) {
|
||||||
|
@ -170,10 +174,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
// dependencies we used to have with the one we now have
|
// dependencies we used to have with the one we now have
|
||||||
return getDependencies(client.platform, client.bundleEntry)
|
return getDependencies(client.platform, client.bundleEntry)
|
||||||
.then(({
|
.then(({
|
||||||
dependenciesCache,
|
depsCache,
|
||||||
dependenciesModulesCache,
|
depsModulesCache,
|
||||||
shallowDependencies,
|
shallowDeps,
|
||||||
inverseDependenciesCache,
|
inverseDepsCache,
|
||||||
resolutionResponse,
|
resolutionResponse,
|
||||||
}) => {
|
}) => {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
|
@ -182,9 +186,9 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
|
|
||||||
// build list of modules for which we'll send HMR updates
|
// build list of modules for which we'll send HMR updates
|
||||||
const modulesToUpdate = [packagerServer.getModuleForPath(filename)];
|
const modulesToUpdate = [packagerServer.getModuleForPath(filename)];
|
||||||
Object.keys(dependenciesModulesCache).forEach(module => {
|
Object.keys(depsModulesCache).forEach(module => {
|
||||||
if (!client.dependenciesModulesCache[module]) {
|
if (!client.depsModulesCache[module]) {
|
||||||
modulesToUpdate.push(dependenciesModulesCache[module]);
|
modulesToUpdate.push(depsModulesCache[module]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -199,9 +203,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
modulesToUpdate.reverse();
|
modulesToUpdate.reverse();
|
||||||
|
|
||||||
// invalidate caches
|
// invalidate caches
|
||||||
client.dependenciesCache = dependenciesCache;
|
client.dependenciesCache = depsCache;
|
||||||
client.dependenciesModulesCache = dependenciesModulesCache;
|
client.dependenciesModulesCache = depsModulesCache;
|
||||||
client.shallowDependencies = shallowDependencies;
|
client.shallowDependencies = shallowDeps;
|
||||||
|
client.inverseDependenciesCache = inverseDepsCache;
|
||||||
|
|
||||||
return resolutionResponse.copy({
|
return resolutionResponse.copy({
|
||||||
dependencies: modulesToUpdate
|
dependencies: modulesToUpdate
|
||||||
|
@ -228,13 +233,11 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
packagerHost = httpServerAddress.address;
|
packagerHost = httpServerAddress.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
let packagerPort = httpServerAddress.port;
|
|
||||||
|
|
||||||
return packagerServer.buildBundleForHMR({
|
return packagerServer.buildBundleForHMR({
|
||||||
entryFile: client.bundleEntry,
|
entryFile: client.bundleEntry,
|
||||||
platform: client.platform,
|
platform: client.platform,
|
||||||
resolutionResponse,
|
resolutionResponse,
|
||||||
}, packagerHost, packagerPort);
|
}, packagerHost, httpServerAddress.port);
|
||||||
})
|
})
|
||||||
.then(bundle => {
|
.then(bundle => {
|
||||||
if (!client || !bundle || bundle.isEmpty()) {
|
if (!client || !bundle || bundle.isEmpty()) {
|
||||||
|
@ -245,7 +248,7 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
type: 'update',
|
type: 'update',
|
||||||
body: {
|
body: {
|
||||||
modules: bundle.getModulesNamesAndCode(),
|
modules: bundle.getModulesNamesAndCode(),
|
||||||
inverseDependencies: inverseDependenciesCache,
|
inverseDependencies: client.inverseDependenciesCache,
|
||||||
sourceURLs: bundle.getSourceURLs(),
|
sourceURLs: bundle.getSourceURLs(),
|
||||||
sourceMappingURLs: bundle.getSourceMappingURLs(),
|
sourceMappingURLs: bundle.getSourceMappingURLs(),
|
||||||
},
|
},
|
||||||
|
|
Загрузка…
Ссылка в новой задаче