Skip to content

Commit d2f7332

Browse files
committed
Switch various methods from private to protected virtual so they can be overridden. References #39
1 parent 02297fa commit d2f7332

File tree

6 files changed

+64
-64
lines changed

6 files changed

+64
-64
lines changed

src/React/FileCacheHash.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class FileCacheHash : IFileCacheHash
2121
/// <summary>
2222
/// Prefix used for hash line in transformed file. Used for caching.
2323
/// </summary>
24-
internal const string HASH_PREFIX = "// @hash v2-";
24+
private const string HASH_PREFIX = "// @hash v2-";
2525

2626
/// <summary>
2727
/// Althorithm for calculating file hashes
@@ -47,7 +47,7 @@ public string CalculateHash(string input)
4747
/// <param name="cacheContents">Contents retrieved from cache</param>
4848
/// <param name="hash">Hash of the input</param>
4949
/// <returns><c>true</c> if the cache is still valid</returns>
50-
public bool ValidateHash(string cacheContents, string hash)
50+
public virtual bool ValidateHash(string cacheContents, string hash)
5151
{
5252
if (string.IsNullOrWhiteSpace(cacheContents))
5353
{
@@ -75,7 +75,7 @@ public bool ValidateHash(string cacheContents, string hash)
7575
/// </summary>
7676
/// <param name="hash">Hash to prepend prefix to</param>
7777
/// <returns>Hash with prefix</returns>
78-
public string AddPrefix(string hash)
78+
public virtual string AddPrefix(string hash)
7979
{
8080
return HASH_PREFIX + hash;
8181
}

src/React/JavaScriptEngineFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public class JavaScriptEngineFactory : IDisposable, IJavaScriptEngineFactory
1717
/// <summary>
1818
/// Function used to create new JavaScript engine instances.
1919
/// </summary>
20-
private readonly Func<IJsEngine> _factory;
20+
protected readonly Func<IJsEngine> _factory;
2121
/// <summary>
2222
/// Contains all current JavaScript engine instances. One per thread, keyed on thread ID.
2323
/// </summary>
24-
private readonly ConcurrentDictionary<int, IJsEngine> _engines
24+
protected readonly ConcurrentDictionary<int, IJsEngine> _engines
2525
= new ConcurrentDictionary<int, IJsEngine>();
2626

2727
/// <summary>
@@ -40,7 +40,7 @@ public JavaScriptEngineFactory(IEnumerable<Registration> availableFactories)
4040
/// Should handle initialisation.
4141
/// </param>
4242
/// <returns>The JavaScript engine</returns>
43-
public IJsEngine GetEngineForCurrentThread(Action<IJsEngine> onNewEngine = null)
43+
public virtual IJsEngine GetEngineForCurrentThread(Action<IJsEngine> onNewEngine = null)
4444
{
4545
return _engines.GetOrAdd(Thread.CurrentThread.ManagedThreadId, id =>
4646
{
@@ -56,7 +56,7 @@ public IJsEngine GetEngineForCurrentThread(Action<IJsEngine> onNewEngine = null)
5656
/// <summary>
5757
/// Disposes the JavaScript engine for the current thread.
5858
/// </summary>
59-
public void DisposeEngineForCurrentThread()
59+
public virtual void DisposeEngineForCurrentThread()
6060
{
6161
IJsEngine engine;
6262
if (_engines.TryRemove(Thread.CurrentThread.ManagedThreadId, out engine))
@@ -112,7 +112,7 @@ private static Func<IJsEngine> GetFactory(IEnumerable<Registration> availableFac
112112
/// <summary>
113113
/// Clean up all engines
114114
/// </summary>
115-
public void Dispose()
115+
public virtual void Dispose()
116116
{
117117
foreach (var engine in _engines)
118118
{

src/React/JsxTransformer.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,40 @@ public class JsxTransformer : IJsxTransformer
2222
/// <summary>
2323
/// Cache key for JSX to JavaScript compilation
2424
/// </summary>
25-
private const string JSX_CACHE_KEY = "JSX_v2_{0}";
25+
protected const string JSX_CACHE_KEY = "JSX_v2_{0}";
2626
/// <summary>
2727
/// Suffix to append to compiled files
2828
/// </summary>
29-
private const string COMPILED_FILE_SUFFIX = ".generated.js";
29+
protected const string COMPILED_FILE_SUFFIX = ".generated.js";
3030
/// <summary>
3131
/// Suffix to append to source map files
3232
/// </summary>
33-
private const string SOURE_MAP_FILE_SUFFIX = ".map";
33+
protected const string SOURE_MAP_FILE_SUFFIX = ".map";
3434
/// <summary>
3535
/// Number of lines in the header prepended to compiled JSX files.
3636
/// </summary>
37-
private const int LINES_IN_HEADER = 5;
37+
protected const int LINES_IN_HEADER = 5;
3838

3939
/// <summary>
4040
/// Environment this JSX Transformer has been created in
4141
/// </summary>
42-
private readonly IReactEnvironment _environment;
42+
protected readonly IReactEnvironment _environment;
4343
/// <summary>
4444
/// Cache used for storing compiled JSX
4545
/// </summary>
46-
private readonly ICache _cache;
46+
protected readonly ICache _cache;
4747
/// <summary>
4848
/// File system wrapper
4949
/// </summary>
50-
private readonly IFileSystem _fileSystem;
50+
protected readonly IFileSystem _fileSystem;
5151
/// <summary>
5252
/// Hash algorithm for file-based cache
5353
/// </summary>
54-
private readonly IFileCacheHash _fileCacheHash;
54+
protected readonly IFileCacheHash _fileCacheHash;
5555
/// <summary>
5656
/// Site-wide configuration
5757
/// </summary>
58-
private readonly IReactSiteConfiguration _config;
58+
protected readonly IReactSiteConfiguration _config;
5959

6060
/// <summary>
6161
/// Initializes a new instance of the <see cref="JsxTransformer"/> class.
@@ -80,7 +80,7 @@ public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem f
8080
/// <param name="filename">Name of the file to load</param>
8181
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
8282
/// <returns>JavaScript</returns>
83-
public string TransformJsxFile(string filename, bool? useHarmony = null)
83+
public virtual string TransformJsxFile(string filename, bool? useHarmony = null)
8484
{
8585
return TransformJsxFileWithSourceMap(filename, false, useHarmony).Code;
8686
}
@@ -96,7 +96,7 @@ public string TransformJsxFile(string filename, bool? useHarmony = null)
9696
/// </param>
9797
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
9898
/// <returns>JavaScript and source map</returns>
99-
public JavaScriptWithSourceMap TransformJsxFileWithSourceMap(string filename, bool forceGenerateSourceMap = false, bool? useHarmony = null)
99+
public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap(string filename, bool forceGenerateSourceMap = false, bool? useHarmony = null)
100100
{
101101
var cacheKey = string.Format(JSX_CACHE_KEY, filename);
102102

@@ -152,7 +152,7 @@ public JavaScriptWithSourceMap TransformJsxFileWithSourceMap(string filename, bo
152152
/// <c>true</c> to re-transform the file if a cached version with no source map is available
153153
/// </param>
154154
/// <returns></returns>
155-
private JavaScriptWithSourceMap LoadJsxFromFileCache(string filename, string hash, bool forceGenerateSourceMap)
155+
protected virtual JavaScriptWithSourceMap LoadJsxFromFileCache(string filename, string hash, bool forceGenerateSourceMap)
156156
{
157157
var cacheFilename = GetJsxOutputPath(filename);
158158
if (!_fileSystem.FileExists(cacheFilename))
@@ -212,7 +212,7 @@ private JavaScriptWithSourceMap LoadJsxFromFileCache(string filename, string has
212212
/// <param name="hash">Hash of the input. If null, it will be calculated</param>
213213
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
214214
/// <returns>JavaScript</returns>
215-
private JavaScriptWithSourceMap TransformJsxWithHeader(string filename, string contents, string hash = null, bool? useHarmony = null)
215+
protected virtual JavaScriptWithSourceMap TransformJsxWithHeader(string filename, string contents, string hash = null, bool? useHarmony = null)
216216
{
217217
if (string.IsNullOrEmpty(hash))
218218
{
@@ -242,7 +242,7 @@ private JavaScriptWithSourceMap TransformJsxWithHeader(string filename, string c
242242
/// <param name="input">JSX</param>
243243
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
244244
/// <returns>JavaScript</returns>
245-
public string TransformJsx(string input, bool? useHarmony = null)
245+
public virtual string TransformJsx(string input, bool? useHarmony = null)
246246
{
247247
EnsureJsxTransformerSupported();
248248
try
@@ -267,7 +267,7 @@ public string TransformJsx(string input, bool? useHarmony = null)
267267
/// <param name="input">JSX</param>
268268
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
269269
/// <returns>JavaScript and source map</returns>
270-
public JavaScriptWithSourceMap TransformJsxWithSourceMap(string input, bool? useHarmony)
270+
public virtual JavaScriptWithSourceMap TransformJsxWithSourceMap(string input, bool? useHarmony)
271271
{
272272
EnsureJsxTransformerSupported();
273273
try
@@ -290,7 +290,7 @@ public JavaScriptWithSourceMap TransformJsxWithSourceMap(string input, bool? use
290290
/// </summary>
291291
/// <param name="hash">Hash of the input</param>
292292
/// <returns>Header for the cache</returns>
293-
private string GetFileHeader(string hash)
293+
protected virtual string GetFileHeader(string hash)
294294
{
295295
return string.Format(
296296
@"{0}
@@ -307,7 +307,7 @@ private string GetFileHeader(string hash)
307307
/// </summary>
308308
/// <param name="path">Path of the JSX file</param>
309309
/// <returns>Output path of the compiled file</returns>
310-
public string GetJsxOutputPath(string path)
310+
public virtual string GetJsxOutputPath(string path)
311311
{
312312
return Path.Combine(
313313
Path.GetDirectoryName(path),
@@ -321,7 +321,7 @@ public string GetJsxOutputPath(string path)
321321
/// </summary>
322322
/// <param name="path">Path of the JSX file</param>
323323
/// <returns>Output path of the source map</returns>
324-
public string GetSourceMapOutputPath(string path)
324+
public virtual string GetSourceMapOutputPath(string path)
325325
{
326326
return GetJsxOutputPath(path) + SOURE_MAP_FILE_SUFFIX;
327327
}
@@ -333,7 +333,7 @@ public string GetSourceMapOutputPath(string path)
333333
/// <param name="filename">Name of the file to load</param>
334334
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
335335
/// <returns>File contents</returns>
336-
public string TransformAndSaveJsxFile(string filename, bool? useHarmony = null)
336+
public virtual string TransformAndSaveJsxFile(string filename, bool? useHarmony = null)
337337
{
338338
var outputPath = GetJsxOutputPath(filename);
339339
var sourceMapPath = GetSourceMapOutputPath(filename);

src/React/ReactComponent.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public class ReactComponent : IReactComponent
3030
/// <summary>
3131
/// Environment this component has been created in
3232
/// </summary>
33-
private readonly IReactEnvironment _environment;
33+
protected readonly IReactEnvironment _environment;
3434

3535
/// <summary>
3636
/// Global site configuration
3737
/// </summary>
38-
private readonly IReactSiteConfiguration _configuration;
38+
protected readonly IReactSiteConfiguration _configuration;
3939

4040
/// <summary>
4141
/// Gets or sets the name of the component
@@ -79,7 +79,7 @@ public ReactComponent(IReactEnvironment environment, IReactSiteConfiguration con
7979
/// return the rendered HTML.
8080
/// </summary>
8181
/// <returns>HTML</returns>
82-
public string RenderHtml()
82+
public virtual string RenderHtml()
8383
{
8484
EnsureComponentExists();
8585
try
@@ -111,7 +111,7 @@ public string RenderHtml()
111111
/// server-rendered HTML.
112112
/// </summary>
113113
/// <returns>JavaScript</returns>
114-
public string RenderJavaScript()
114+
public virtual string RenderJavaScript()
115115
{
116116
return string.Format(
117117
"React.render({0}, document.getElementById({1}))",
@@ -123,7 +123,7 @@ public string RenderJavaScript()
123123
/// <summary>
124124
/// Ensures that this component exists in global scope
125125
/// </summary>
126-
private void EnsureComponentExists()
126+
protected virtual void EnsureComponentExists()
127127
{
128128
// This is safe as componentName was validated via EnsureComponentNameValid()
129129
var componentExists = _environment.Execute<bool>(string.Format(
@@ -144,7 +144,7 @@ private void EnsureComponentExists()
144144
/// Gets the JavaScript code to initialise the component
145145
/// </summary>
146146
/// <returns>JavaScript for component initialisation</returns>
147-
private string GetComponentInitialiser()
147+
protected virtual string GetComponentInitialiser()
148148
{
149149
var encodedProps = JsonConvert.SerializeObject(Props, _configuration.JsonSerializerSettings); // SerializeObject accepts null settings
150150
return string.Format(

0 commit comments

Comments
 (0)