From e6a807a8b7741b99c23bc5ca9d92f29fac3e2435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Mon, 28 Dec 2015 16:43:08 -0800 Subject: [PATCH] Introduce Packager and App HMR WebSocket connection Summary: public This diff adds infra to both the Packager and the running app to have a WebSocket based connection between them. This connection is toggled by a new dev menu item, namely `Enable/Disable Hot Loading`. Reviewed By: vjeux Differential Revision: D2787621 fb-gh-sync-id: d1dee769348e4830c28782e7b650d025f2b3a786 --- react-packager/src/Server/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index c1bc5ce1..c2acd305 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -134,6 +134,7 @@ class Server { this._projectRoots = opts.projectRoots; this._bundles = Object.create(null); this._changeWatchers = []; + this._fileChangeListeners = []; const assetGlobs = opts.assetExts.map(ext => '**/*.' + ext); @@ -175,6 +176,7 @@ class Server { this._fileWatcher.on('all', this._onFileChange.bind(this)); this._debouncedFileChangeHandler = _.debounce(filePath => { + this._fileChangeListeners.forEach(listener => listener(filePath)); this._rebuildBundles(filePath); this._informChangeWatchers(); }, 50); @@ -187,6 +189,10 @@ class Server { ]); } + addFileChangeListener(listener) { + this._fileChangeListeners.push(listener); + } + buildBundle(options) { return Promise.resolve().then(() => { if (!options.platform) {