Skip to content

Commit 783116e

Browse files
committed
feat(HMR): Enables hot module reloading for ReactWindows
Minor issue with Chakra console polyfill (was missing 'info') and a minor change to the URI path sent to the HMRClient. Fixes microsoft#357 - Add Hot Module Replacement Option
1 parent a7cc5da commit 783116e

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

ReactWindows/ReactNative/Chakra/Executor/ChakraJavaScriptExecutor.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ChakraJavaScriptExecutor : IJavaScriptExecutor
1313
{
1414
private readonly JavaScriptRuntime _runtime;
1515

16+
private JavaScriptNativeFunction _consoleInfo;
1617
private JavaScriptNativeFunction _consoleLog;
1718
private JavaScriptNativeFunction _consoleWarn;
1819
private JavaScriptNativeFunction _consoleError;
@@ -158,10 +159,12 @@ private void InitializeChakra()
158159
var consoleObject = JavaScriptValue.CreateObject();
159160
EnsureGlobalObject().SetProperty(consolePropertyId, consoleObject, true);
160161

162+
_consoleInfo = ConsoleInfo;
161163
_consoleLog = ConsoleLog;
162164
_consoleWarn = ConsoleWarn;
163165
_consoleError = ConsoleError;
164166

167+
DefineHostCallback(consoleObject, "info", _consoleInfo);
165168
DefineHostCallback(consoleObject, "log", _consoleLog);
166169
DefineHostCallback(consoleObject, "warn", _consoleWarn);
167170
DefineHostCallback(consoleObject, "error", _consoleError);
@@ -217,6 +220,16 @@ private static void DefineHostCallback(
217220
obj.SetProperty(propertyId, function, true);
218221
}
219222

223+
private JavaScriptValue ConsoleInfo(
224+
JavaScriptValue callee,
225+
bool isConstructCall,
226+
JavaScriptValue[] arguments,
227+
ushort argumentCount,
228+
IntPtr callbackData)
229+
{
230+
return ConsoleCallback("Info", callee, isConstructCall, arguments, argumentCount, callbackData);
231+
}
232+
220233
private JavaScriptValue ConsoleLog(
221234
JavaScriptValue callee,
222235
bool isConstructCall,
@@ -257,7 +270,7 @@ private JavaScriptValue ConsoleCallback(
257270
{
258271
try
259272
{
260-
Debug.Write("Chakra " + kind + ">");
273+
Debug.Write($"[JS {kind}]");
261274

262275
// First argument is this-context, ignore...
263276
for (var i = 1; i < argumentCount; ++i)

ReactWindows/ReactNative/DevSupport/DevSupportManager.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ public void ShowDevOptionsDialog()
199199
_isUsingJsProxy = !_isUsingJsProxy;
200200
HandleReloadJavaScript();
201201
}),
202+
new DevOptionHandler(
203+
_devSettings.IsHotModuleReplacementEnabled
204+
? "Disable Hot Reloading"
205+
: "Enable Hot Reloading",
206+
() =>
207+
{
208+
_devSettings.IsHotModuleReplacementEnabled = !_devSettings.IsHotModuleReplacementEnabled;
209+
HandleReloadJavaScript();
210+
}),
202211
new DevOptionHandler(
203212
_devSettings.IsReloadOnJavaScriptChangeEnabled
204213
? "Disable Live Reload"
@@ -324,7 +333,7 @@ private void ResetCurrentContext(ReactContext context)
324333
try
325334
{
326335
var uri = new Uri(SourceUrl);
327-
var path = uri.PathAndQuery.Substring(1); // strip initial slash in path
336+
var path = uri.LocalPath.Substring(1); // strip initial slash in path
328337
var host = uri.Host;
329338
var port = uri.Port;
330339
context.GetJavaScriptModule<HMRClient>().enable("windows", path, host, port);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule HMRLoadingView
10+
* @flow
11+
*/
12+
13+
'use strict';
14+
15+
class HMRLoadingView {
16+
static showMessage(message: string) {
17+
//noop
18+
}
19+
20+
static hide() {
21+
// noop
22+
}
23+
}
24+
25+
module.exports = HMRLoadingView;

0 commit comments

Comments
 (0)