Skip to content

Commit 8ea2205

Browse files
committed
Addressing code review comments.
1 parent 947abd4 commit 8ea2205

7 files changed

+68
-25
lines changed

ReactWindows/ReactNative/Bridge/JavaScriptBundleLoader.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public static JavaScriptBundleLoader CreateFileLoader(string fileName)
4545
/// <see cref="DevSupport.IDevSupportManager"/>.
4646
/// </summary>
4747
/// <param name="sourceUrl">The source URL.</param>
48-
/// <param name="cachedBundle">The cached bundle.</param>
48+
/// <param name="cachedFileLocation">The cached bundle.</param>
4949
/// <returns>The JavaScript bundle loader.</returns>
50-
public static JavaScriptBundleLoader CreateCachedBundleFromNetworkLoader(string sourceUrl, string cachedBundle)
50+
public static JavaScriptBundleLoader CreateCachedBundleFromNetworkLoader(string sourceUrl, string cachedFileLocation)
5151
{
52-
return new CachedJavaScriptBundleLoader(sourceUrl, cachedBundle);
52+
return new CachedJavaScriptBundleLoader(sourceUrl, cachedFileLocation);
5353
}
5454

5555
class FileJavaScriptBundleLoader : JavaScriptBundleLoader
@@ -100,24 +100,38 @@ public override void LoadScript(IReactBridge bridge)
100100

101101
class CachedJavaScriptBundleLoader : JavaScriptBundleLoader
102102
{
103-
private readonly string _cachedBundle;
103+
private readonly string _cachedFileLocation;
104+
private string _script;
104105

105-
public CachedJavaScriptBundleLoader(string sourceUrl, string cachedBundle)
106+
public CachedJavaScriptBundleLoader(string sourceUrl, string cachedFileLocation)
106107
{
107108
SourceUrl = sourceUrl;
108-
_cachedBundle = cachedBundle;
109+
_cachedFileLocation = cachedFileLocation;
109110
}
110111

111112
public override string SourceUrl { get; }
112113

113-
public override Task InitializeAsync()
114+
public override async Task InitializeAsync()
114115
{
115-
return Task.FromResult(true);
116+
try
117+
{
118+
var storageFile = await StorageFile.GetFileFromPathAsync(_cachedFileLocation);
119+
using (var stream = await storageFile.OpenStreamForReadAsync())
120+
using (var reader = new StreamReader(stream))
121+
{
122+
_script = await reader.ReadToEndAsync();
123+
}
124+
}
125+
catch (Exception ex)
126+
{
127+
var exceptionMessage = String.Format("File read exception for asset {0}", SourceUrl);
128+
throw new InvalidOperationException(exceptionMessage, ex);
129+
}
116130
}
117131

118132
public override void LoadScript(IReactBridge executor)
119133
{
120-
executor.RunScript(_cachedBundle);
134+
executor.RunScript(_script);
121135
}
122136
}
123137
}

ReactWindows/ReactNative/DevSupport/DevSupportManager.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ public DevSupportManager(
4141

4242
public string SourceUrl
4343
{
44-
get;
45-
set;
44+
get
45+
{
46+
if (_jsAppBundleName == null)
47+
{
48+
return "";
49+
}
50+
51+
// TODO: use dev server helpers
52+
throw new NotImplementedException();
53+
}
4654
}
4755

4856
public string SourceMapUrl
@@ -59,10 +67,13 @@ public string SourceMapUrl
5967
}
6068
}
6169

62-
public string CachedJavaScriptBundle
70+
public string CachedJavaScriptBundleFile
6371
{
64-
get;
65-
private set;
72+
get
73+
{
74+
// TODO: choose local file for caching
75+
throw new NotImplementedException();
76+
}
6677
}
6778

6879
public void HandleException(Exception exception)
@@ -221,7 +232,6 @@ private void RegisterDevOptionsMenuTriggers()
221232
}
222233
}
223234

224-
225235
class DevOptionHandler
226236
{
227237
private readonly Action _onSelect;

ReactWindows/ReactNative/DevSupport/DisabledDevSupportManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public string SourceMapUrl
2727
}
2828
}
2929

30-
public string CachedJavaScriptBundle
30+
public string CachedJavaScriptBundleFile
3131
{
3232
get
3333
{

ReactWindows/ReactNative/DevSupport/IDevSupportManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IDevSupportManager
2828
/// <summary>
2929
/// The cached JavaScript bundle.
3030
/// </summary>
31-
string CachedJavaScriptBundle { get; }
31+
string CachedJavaScriptBundleFile { get; }
3232

3333
/// <summary>
3434
/// Handle a native exception.
@@ -41,7 +41,6 @@ public interface IDevSupportManager
4141
/// </summary>
4242
void HandleReloadJavaScript();
4343

44-
4544
/// <summary>
4645
/// Show the developer options dialog.
4746
/// </summary>

ReactWindows/ReactNative/DevSupport/ProgressDialog.xaml.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
using System.Threading;
22
using Windows.UI.Xaml.Controls;
33

4-
// The Content Dialog item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
5-
64
namespace ReactNative.DevSupport
75
{
6+
/// <summary>
7+
/// Content dialog for when the app is waiting.
8+
/// </summary>
9+
/// <remarks>
10+
/// This is used when awaiting the regeneration of the JavaScript bundle.
11+
/// </remarks>
812
public sealed partial class ProgressDialog : ContentDialog
913
{
1014
private readonly CancellationTokenSource _cancellationTokenSource;
1115

16+
/// <summary>
17+
/// Instantiates the <see cref="ProgressDialog"/>.
18+
/// </summary>
19+
/// <param name="title">The title.</param>
20+
/// <param name="message">The message.</param>
1221
public ProgressDialog(string title, string message)
1322
{
1423
this.InitializeComponent();
@@ -19,10 +28,19 @@ public ProgressDialog(string title, string message)
1928
_cancellationTokenSource = new CancellationTokenSource();
2029
}
2130

31+
/// <summary>
32+
/// The title of the dialog.
33+
/// </summary>
2234
public string Heading { get; }
2335

36+
/// <summary>
37+
/// The message displayed in the dialog.
38+
/// </summary>
2439
public string Message { get; }
2540

41+
/// <summary>
42+
/// The cancellation token cancelled upon dialog dismissal.
43+
/// </summary>
2644
public CancellationToken Token
2745
{
2846
get

ReactWindows/ReactNative/ReactInstanceManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ private void OnJavaScriptBundleLoadedFromServer()
384384
() => new ChakraJavaScriptExecutor(),
385385
JavaScriptBundleLoader.CreateCachedBundleFromNetworkLoader(
386386
_devSupportManager.SourceUrl,
387-
_devSupportManager.CachedJavaScriptBundle));
387+
_devSupportManager.CachedJavaScriptBundleFile));
388388
}
389389

390390
private void RecreateReactContextInBackground(
@@ -417,9 +417,9 @@ private async Task InitializeReactContextAsync(
417417
var reactContext = await CreateReactContextAsync(jsExecutorFactory, jsBundleLoader);
418418
SetupReactContext(reactContext);
419419
}
420-
catch (Exception ex)
420+
catch
421421
{
422-
_devSupportManager.HandleException(ex);
422+
// TODO: add exception handler through dev support manager.
423423
}
424424
finally
425425
{

ReactWindows/ReactNative/ReactPage.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using ReactNative.Modules.Core;
22
using System;
33
using System.Collections.Generic;
4+
using Windows.System;
45
using Windows.UI.Xaml;
56
using Windows.UI.Xaml.Controls;
6-
using Windows.UI.Xaml.Media;
77
using Windows.UI.Xaml.Input;
8-
using Windows.System;
8+
using Windows.UI.Xaml.Media;
99

1010
namespace ReactNative
1111
{
@@ -143,7 +143,9 @@ private IReactInstanceManager CreateReactInstanceManager(string jsBundleFile, IR
143143
{
144144
var builder = new ReactInstanceManager.Builder
145145
{
146+
#if DEBUG
146147
UseDeveloperSupport = true,
148+
#endif
147149
InitialLifecycleState = LifecycleState.Resumed,
148150
JavaScriptBundleFile = jsBundleFile,
149151
};

0 commit comments

Comments
 (0)