Skip to content

Commit

Permalink
Fixes before review
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Szmidt committed Apr 24, 2023
1 parent 5bb01bd commit 65ccac5
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Forte.React.AspNetCore/Configuration/ReactConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ internal class ReactConfiguration
public List<string> ScriptUrls { get; set; } = new();
public bool IsServerSideDisabled { get; set; } = false;
public Version ReactVersion { get; set; } = null!;
public string ObjectToSavePropsName { get; set; } = "__reactProps";
public string NameOfObjectToSaveProps { get; set; } = "__reactProps";
}
4 changes: 0 additions & 4 deletions Forte.React.AspNetCore/Forte.React.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
<None Remove="renderToPipeableStream.js" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Jering.Javascript.NodeJS" Version="7.0.0-beta.4" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Forte.React.AspNetCore/ForteReactAspNetCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void AddReact(this IServiceCollection services,
}

public static void UseReact(this IApplicationBuilder app, IEnumerable<string> scriptUrls, Version reactVersion,
bool disableServerSideRendering = false, string? objectToSavePropsName = null)
bool disableServerSideRendering = false, string? nameOfObjectToSaveProps = null)
{
var config = app.ApplicationServices.GetService<ReactConfiguration>();

Expand All @@ -56,6 +56,6 @@ public static void UseReact(this IApplicationBuilder app, IEnumerable<string> sc
config.IsServerSideDisabled = disableServerSideRendering;
config.ScriptUrls = scriptUrls.ToList();
config.ReactVersion = reactVersion;
config.ObjectToSavePropsName = objectToSavePropsName ?? config.ObjectToSavePropsName;
config.NameOfObjectToSaveProps = nameOfObjectToSaveProps ?? config.NameOfObjectToSaveProps;
}
}
5 changes: 1 addition & 4 deletions Forte.React.AspNetCore/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.IO;
using System.Text.Encodings.Web;
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Forte.React.AspNetCore.React;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
Expand Down
4 changes: 2 additions & 2 deletions Forte.React.AspNetCore/React/ReactService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private ReactService(INodeJSService nodeJsService, ReactConfiguration config)

private async Task<T> ASD<T>(Component component, object props, params object[] args)
{
var allArgs = new List<object>() { component.Name, component.JsonContainerId, props, _config.ScriptUrls, _config.ObjectToSavePropsName };
var allArgs = new List<object>() { component.Name, component.JsonContainerId, props, _config.ScriptUrls, _config.NameOfObjectToSaveProps };
allArgs.AddRange(args);

var type = typeof(T);
Expand Down Expand Up @@ -150,7 +150,7 @@ private static string GetElementById(string containerId)

private string CreateElement(Component component)
=>
$"React.createElement({component.Name}, window.{_config.ObjectToSavePropsName}[\"{component.JsonContainerId}\"])";
$"React.createElement({component.Name}, window.{_config.NameOfObjectToSaveProps}[\"{component.JsonContainerId}\"])";


private string Render(Component component)
Expand Down
9 changes: 2 additions & 7 deletions Forte.React.AspNetCore/renderToPipeableStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = (
jsonContainerId,
props = {},
scriptFiles,
objectToSavePropsName,
nameOfObjectToSaveProps,
options,
) => {
try {
Expand All @@ -38,7 +38,7 @@ module.exports = (
}

let error;
const bootstrapScriptContent = `(window.${objectToSavePropsName} = window.${objectToSavePropsName} || {})['${jsonContainerId}'] = ${JSON.stringify(
const bootstrapScriptContent = `(window.${objectToSavePropsName} = window.${nameOfObjectToSaveProps} || {})['${jsonContainerId}'] = ${JSON.stringify(
props
)};`;

Expand Down Expand Up @@ -72,9 +72,4 @@ module.exports = (
} catch (err) {
callback(err, null);
}
// const componentHtml = `${ReactDOMServer.renderToString(element)}`;
// const jsonHtml = `<script id="${jsonContainerId}" type="json">${JSON.stringify(
// props
// )}</script>`;
// const result = componentHtml + jsonHtml;
};
4 changes: 2 additions & 2 deletions Forte.React.AspNetCore/renderToString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
jsonContainerId,
props = {},
scriptFiles,
objectToSavePropsName
nameOfObjectToSaveProps
) => {
scriptFiles.forEach((scriptFile) => {
require(scriptFile);
Expand All @@ -16,7 +16,7 @@
const element = React.createElement(component, props);

const componentHtml = `${ReactDOMServer.renderToString(element)}`;
const bootstrapScriptContent = `(window.${objectToSavePropsName} = window.${objectToSavePropsName} || {})['${jsonContainerId}'] = ${JSON.stringify(
const bootstrapScriptContent = `(window.${nameOfObjectToSaveProps} = window.${nameOfObjectToSaveProps} || {})['${jsonContainerId}'] = ${JSON.stringify(
props
)};`;
const jsonHtml = `<script>${bootstrapScriptContent}</script>`;
Expand Down

0 comments on commit 65ccac5

Please sign in to comment.