From 295affc8ab8005de5b808410131885db0cf5aca1 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 18 Jul 2019 11:05:44 -0700 Subject: [PATCH] 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 --- Libraries/Utilities/HMRClient.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Libraries/Utilities/HMRClient.js b/Libraries/Utilities/HMRClient.js index 24f568ebd2e..d806150aacd 100644 --- a/Libraries/Utilities/HMRClient.js +++ b/Libraries/Utilities/HMRClient.js @@ -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 {