From 65ccac5ac85b8938e177fd4c8c454c2b8f616813 Mon Sep 17 00:00:00 2001 From: Wojciech Szmidt Date: Mon, 24 Apr 2023 15:48:04 +0200 Subject: [PATCH] Fixes before review --- .../Configuration/ReactConfiguration.cs | 2 +- Forte.React.AspNetCore/Forte.React.AspNetCore.csproj | 4 ---- Forte.React.AspNetCore/ForteReactAspNetCoreExtensions.cs | 4 ++-- Forte.React.AspNetCore/HtmlHelperExtensions.cs | 5 +---- Forte.React.AspNetCore/React/ReactService.cs | 4 ++-- Forte.React.AspNetCore/renderToPipeableStream.js | 9 ++------- Forte.React.AspNetCore/renderToString.js | 4 ++-- 7 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Forte.React.AspNetCore/Configuration/ReactConfiguration.cs b/Forte.React.AspNetCore/Configuration/ReactConfiguration.cs index 215802c..5787cd7 100644 --- a/Forte.React.AspNetCore/Configuration/ReactConfiguration.cs +++ b/Forte.React.AspNetCore/Configuration/ReactConfiguration.cs @@ -8,5 +8,5 @@ internal class ReactConfiguration public List 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"; } diff --git a/Forte.React.AspNetCore/Forte.React.AspNetCore.csproj b/Forte.React.AspNetCore/Forte.React.AspNetCore.csproj index 1244024..95a4776 100644 --- a/Forte.React.AspNetCore/Forte.React.AspNetCore.csproj +++ b/Forte.React.AspNetCore/Forte.React.AspNetCore.csproj @@ -20,10 +20,6 @@ false - - - - diff --git a/Forte.React.AspNetCore/ForteReactAspNetCoreExtensions.cs b/Forte.React.AspNetCore/ForteReactAspNetCoreExtensions.cs index 529743c..cef80a8 100644 --- a/Forte.React.AspNetCore/ForteReactAspNetCoreExtensions.cs +++ b/Forte.React.AspNetCore/ForteReactAspNetCoreExtensions.cs @@ -44,7 +44,7 @@ public static void AddReact(this IServiceCollection services, } public static void UseReact(this IApplicationBuilder app, IEnumerable scriptUrls, Version reactVersion, - bool disableServerSideRendering = false, string? objectToSavePropsName = null) + bool disableServerSideRendering = false, string? nameOfObjectToSaveProps = null) { var config = app.ApplicationServices.GetService(); @@ -56,6 +56,6 @@ public static void UseReact(this IApplicationBuilder app, IEnumerable sc config.IsServerSideDisabled = disableServerSideRendering; config.ScriptUrls = scriptUrls.ToList(); config.ReactVersion = reactVersion; - config.ObjectToSavePropsName = objectToSavePropsName ?? config.ObjectToSavePropsName; + config.NameOfObjectToSaveProps = nameOfObjectToSaveProps ?? config.NameOfObjectToSaveProps; } } diff --git a/Forte.React.AspNetCore/HtmlHelperExtensions.cs b/Forte.React.AspNetCore/HtmlHelperExtensions.cs index 6704928..44e9707 100644 --- a/Forte.React.AspNetCore/HtmlHelperExtensions.cs +++ b/Forte.React.AspNetCore/HtmlHelperExtensions.cs @@ -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; diff --git a/Forte.React.AspNetCore/React/ReactService.cs b/Forte.React.AspNetCore/React/ReactService.cs index 50920fd..2b5c741 100644 --- a/Forte.React.AspNetCore/React/ReactService.cs +++ b/Forte.React.AspNetCore/React/ReactService.cs @@ -51,7 +51,7 @@ private ReactService(INodeJSService nodeJsService, ReactConfiguration config) private async Task ASD(Component component, object props, params object[] args) { - var allArgs = new List() { component.Name, component.JsonContainerId, props, _config.ScriptUrls, _config.ObjectToSavePropsName }; + var allArgs = new List() { component.Name, component.JsonContainerId, props, _config.ScriptUrls, _config.NameOfObjectToSaveProps }; allArgs.AddRange(args); var type = typeof(T); @@ -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) diff --git a/Forte.React.AspNetCore/renderToPipeableStream.js b/Forte.React.AspNetCore/renderToPipeableStream.js index 7c2139a..af46590 100644 --- a/Forte.React.AspNetCore/renderToPipeableStream.js +++ b/Forte.React.AspNetCore/renderToPipeableStream.js @@ -12,7 +12,7 @@ module.exports = ( jsonContainerId, props = {}, scriptFiles, - objectToSavePropsName, + nameOfObjectToSaveProps, options, ) => { try { @@ -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 )};`; @@ -72,9 +72,4 @@ module.exports = ( } catch (err) { callback(err, null); } - // const componentHtml = `${ReactDOMServer.renderToString(element)}`; - // const jsonHtml = ``; - // const result = componentHtml + jsonHtml; }; diff --git a/Forte.React.AspNetCore/renderToString.js b/Forte.React.AspNetCore/renderToString.js index 8596841..7e8739d 100644 --- a/Forte.React.AspNetCore/renderToString.js +++ b/Forte.React.AspNetCore/renderToString.js @@ -4,7 +4,7 @@ jsonContainerId, props = {}, scriptFiles, - objectToSavePropsName + nameOfObjectToSaveProps ) => { scriptFiles.forEach((scriptFile) => { require(scriptFile); @@ -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 = ``;