Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
HMR nits detected by the linter
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D3042850

fb-gh-sync-id: 03fd239b0dea2d7d4ef778e2d07d41af84fe310d
shipit-source-id: 03fd239b0dea2d7d4ef778e2d07d41af84fe310d
  • Loading branch information
martinbigio authored and Facebook Github Bot 9 committed Mar 12, 2016
1 parent 83095f9 commit 780a513
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions local-cli/server/util/attachHMRServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ function attachHMRServer({httpServer, path, packagerServer}) {

// map from module name to path
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
// bundle has
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
// has
Expand Down Expand Up @@ -128,8 +132,8 @@ function attachHMRServer({httpServer, path, packagerServer}) {
`[Hot Module Replacement] File change detected (${time()})`
);

const blacklisted = blacklist.find(path =>
filename.indexOf(path) !== -1
const blacklisted = blacklist.find(blacklistedPath =>
filename.indexOf(blacklistedPath) !== -1
);

if (blacklisted) {
Expand Down Expand Up @@ -170,10 +174,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
// dependencies we used to have with the one we now have
return getDependencies(client.platform, client.bundleEntry)
.then(({
dependenciesCache,
dependenciesModulesCache,
shallowDependencies,
inverseDependenciesCache,
depsCache,
depsModulesCache,
shallowDeps,
inverseDepsCache,
resolutionResponse,
}) => {
if (!client) {
Expand All @@ -182,9 +186,9 @@ function attachHMRServer({httpServer, path, packagerServer}) {

// build list of modules for which we'll send HMR updates
const modulesToUpdate = [packagerServer.getModuleForPath(filename)];
Object.keys(dependenciesModulesCache).forEach(module => {
if (!client.dependenciesModulesCache[module]) {
modulesToUpdate.push(dependenciesModulesCache[module]);
Object.keys(depsModulesCache).forEach(module => {
if (!client.depsModulesCache[module]) {
modulesToUpdate.push(depsModulesCache[module]);
}
});

Expand All @@ -199,9 +203,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
modulesToUpdate.reverse();

// invalidate caches
client.dependenciesCache = dependenciesCache;
client.dependenciesModulesCache = dependenciesModulesCache;
client.shallowDependencies = shallowDependencies;
client.dependenciesCache = depsCache;
client.dependenciesModulesCache = depsModulesCache;
client.shallowDependencies = shallowDeps;
client.inverseDependenciesCache = inverseDepsCache;

return resolutionResponse.copy({
dependencies: modulesToUpdate
Expand All @@ -228,13 +233,11 @@ function attachHMRServer({httpServer, path, packagerServer}) {
packagerHost = httpServerAddress.address;
}

let packagerPort = httpServerAddress.port;

return packagerServer.buildBundleForHMR({
entryFile: client.bundleEntry,
platform: client.platform,
resolutionResponse,
}, packagerHost, packagerPort);
}, packagerHost, httpServerAddress.port);
})
.then(bundle => {
if (!client || !bundle || bundle.isEmpty()) {
Expand All @@ -245,7 +248,7 @@ function attachHMRServer({httpServer, path, packagerServer}) {
type: 'update',
body: {
modules: bundle.getModulesNamesAndCode(),
inverseDependencies: inverseDependenciesCache,
inverseDependencies: client.inverseDependenciesCache,
sourceURLs: bundle.getSourceURLs(),
sourceMappingURLs: bundle.getSourceMappingURLs(),
},
Expand Down

0 comments on commit 780a513

Please sign in to comment.