Skip to content

Commit c0a41a5

Browse files
Add initial NodeJs engine support
This is very WIP
1 parent 7a9935b commit c0a41a5

File tree

11 files changed

+581
-2
lines changed

11 files changed

+581
-2
lines changed

src/React.Core/AssemblyRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Register(TinyIoCContainer container)
3737
container.Register<IJavaScriptEngineFactory, JavaScriptEngineFactory>().AsSingleton();
3838
container.Register<IReactIdGenerator, ReactIdGenerator>().AsSingleton();
3939

40-
container.Register<IReactEnvironment, ReactEnvironment>().AsPerRequestSingleton();
40+
container.Register<IReactEnvironment, ReactWithNodeEnvironment>().AsPerRequestSingleton();
4141
}
4242
}
4343
}

src/React.Core/INodeJsEngine.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Reflection;
3+
4+
namespace React
5+
{
6+
/// <summary>
7+
/// The wrapper for the Node engine
8+
/// </summary>
9+
public interface INodeJsEngine
10+
{
11+
string Name { get; }
12+
string Version { get; }
13+
14+
bool HasVariable(string uSER_SCRIPTS_LOADED_KEY);
15+
void Execute(string contents, string file);
16+
void SetVariableValue(string uSER_SCRIPTS_LOADED_KEY, bool v);
17+
void Execute(string code);
18+
T Evaluate<T>(string code);
19+
20+
T CallFunctionReturningJson<T>(string function, object[] args);
21+
22+
void ExecuteResource(string resourceName, Assembly assembly);
23+
}
24+
}

src/React.Core/IReactSiteConfiguration.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,18 @@ public interface IReactSiteConfiguration
216216
/// <param name="provider"></param>
217217
/// <returns></returns>
218218
IReactSiteConfiguration SetScriptNonceProvider(Func<string> provider);
219+
220+
/// <summary>
221+
///
222+
/// </summary>
223+
Func<INodeJsEngine> NodeJsEngine { get; set; }
224+
225+
/// <summary>
226+
///
227+
/// </summary>
228+
/// <param name="nodeJsEngine"></param>
229+
/// <returns></returns>
230+
IReactSiteConfiguration SetNodeJsEngine(Func<INodeJsEngine> nodeJsEngine);
231+
219232
}
220233
}

src/React.Core/NodeJsException.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
using System;
9+
10+
namespace React
11+
{
12+
public class NodeJsException : Exception
13+
{
14+
}
15+
}

src/React.Core/ReactSiteConfiguration.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,21 @@ public IReactSiteConfiguration SetScriptNonceProvider(Func<string> provider)
359359
ScriptNonceProvider = provider;
360360
return this;
361361
}
362+
363+
/// <summary>
364+
/// The Node engine instance
365+
/// </summary>
366+
public Func<INodeJsEngine> NodeJsEngine { get; set; }
367+
368+
/// <summary>
369+
/// Sets the Node engine instance
370+
/// </summary>
371+
/// <param name="nodeJsEngine"></param>
372+
/// <returns></returns>
373+
public IReactSiteConfiguration SetNodeJsEngine(Func<INodeJsEngine> nodeJsEngine)
374+
{
375+
NodeJsEngine = nodeJsEngine;
376+
return this;
377+
}
362378
}
363379
}

0 commit comments

Comments
 (0)