Refactor the socket client API

Summary:
Two changes:

1. `disable` -> `close` to better match what's happening.

2. `enable` is inlined in the constructor because it's always called right after the constructor.

Reviewed By: rickhanlonii

Differential Revision: D16340009

fbshipit-source-id: 38a906b1ab3f5b39a57d2598ba400a2f03903951
This commit is contained in:
Dan Abramov
2019-07-18 11:11:29 -07:00
committed by Facebook Github Bot
parent c13e5d0b43
commit 295affc8ab
+2 -10
View File
@@ -190,12 +190,12 @@ Error: ${e.message}`;
LoadingView.hide();
if (data.type === 'GraphNotFoundError') {
client.disable();
client.close();
setHMRUnavailableReason(
'The Metro server has restarted since the last edit. Fast Refresh will be disabled until you reload the application.',
);
} else if (data.type === 'RevisionNotFoundError') {
client.disable();
client.close();
setHMRUnavailableReason(
'The Metro server and the client are out of sync. Fast Refresh will be disabled until you reload the application.',
);
@@ -218,14 +218,6 @@ Error: ${e.message}`;
);
});
// This sets up the socket. A better name would be open(), or perhaps
// it should just connect in the constructor. We can change this name if we
// cut a major Metro bump right after. This runs even if Fast Refresh is off.
client.enable();
// Don't confuse this with the enable/disable calls below which actually
// enable or disable applying updates. (Yes, this is very confusing.)
// TODO(gaearon): refactor this to reduce the confusion.
if (isEnabled) {
HMRClient.enable();
} else {