Skip to content

Commit 252041d

Browse files
Implement on-the-fly React / Babel JSX compilation
1 parent b6f1652 commit 252041d

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/React.NodeServices/NodeJsEngine.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static INodeJsEngine CreateEngine(INodeJSService nodeJSService)
3838

3939
public T CallFunctionReturningJson<T>(string function, object[] args)
4040
{
41-
return _nodeJSService.InvokeFromStringAsync<T>(WrapAsModule(function), args: args).ConfigureAwait(false).GetAwaiter().GetResult();
41+
return _nodeJSService.InvokeFromStringAsync<T>(WrapAsModule($"{function}(...{JsonConvert.SerializeObject(args ?? new object[0])})")).ConfigureAwait(false).GetAwaiter().GetResult();
4242
}
4343

4444
public void Dispose()
@@ -51,10 +51,7 @@ public T Evaluate<T>(string code)
5151
return _nodeJSService.InvokeFromStringAsync<T>(WrapAsModule(code)).ConfigureAwait(false).GetAwaiter().GetResult();
5252
}
5353

54-
public void Execute(string contents, string file)
55-
{
56-
throw new NotImplementedException();
57-
}
54+
public void Execute(string contents, string file) => Execute(contents);
5855

5956
public void Execute(string code)
6057
{

src/React.NodeServices/ReactWithNodeEnvironment.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ IReactIdGenerator reactIdGenerator
136136

137137
var nodeInstance = _config.CreateNodeJsInstance();
138138

139+
if (_config.LoadReact)
140+
{
141+
nodeInstance.ExecuteResource(_config.UseDebugReact
142+
? "React.Core.Resources.react.generated.js"
143+
: "React.Core.Resources.react.generated.min.js",
144+
typeof(ReactEnvironment).Assembly);
145+
}
146+
139147
LoadUserScripts(nodeInstance);
140148

141149
return nodeInstance;

src/React.Sample.Mvc4/Content/Sample.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ function CommentsBox(props: CommentsBoxProps) {
6666
return <em>Loading...</em>;
6767
} else if (state.hasMore) {
6868
return (
69-
<Reactstrap.Button onClick={loadMoreClicked}>
69+
<button onClick={loadMoreClicked}>
7070
Load More
71-
</Reactstrap.Button>
71+
</button>
7272
);
7373
} else {
7474
return <em>No more comments</em>;

0 commit comments

Comments
 (0)