From 2869aa72c54ef963254b2700b289413eaf8a8837 Mon Sep 17 00:00:00 2001 From: adrian smyda Date: Thu, 8 Aug 2024 10:09:22 +0200 Subject: [PATCH] ref pr#1 --- .../Configuration/ReactConfiguration.cs | 6 ++--- Forte.Web.React/ForteWebReactExtensions.cs | 4 ++-- Forte.Web.React/HtmlHelperExtensions.cs | 24 +++++++++---------- Forte.Web.React/React/ReactService.cs | 12 +++++----- Forte.Web.React/Scripts/renderToString.js | 6 ++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Forte.Web.React/Configuration/ReactConfiguration.cs b/Forte.Web.React/Configuration/ReactConfiguration.cs index c961d71..e926592 100644 --- a/Forte.Web.React/Configuration/ReactConfiguration.cs +++ b/Forte.Web.React/Configuration/ReactConfiguration.cs @@ -27,10 +27,10 @@ public class ReactConfiguration public string NameOfObjectToSaveProps { get; set; } = "__reactProps"; /// - /// Name of the object used to save global context. Default value is "__globalContext". - /// NameOfGlobalContextToSave is supported by method. + /// Name of the object used to save global data object. Default value is "__globalData". + /// NameOfGlobalDataToSave is supported by method. /// - public string NameOfGlobalContextToSave { get; set; } = "__globalContext"; + public string NameOfGlobalDataToSave { get; set; } = "__globalData"; /// /// Indicates whether caching is used. Default value is "true". diff --git a/Forte.Web.React/ForteWebReactExtensions.cs b/Forte.Web.React/ForteWebReactExtensions.cs index c840b3a..2d4b0b8 100644 --- a/Forte.Web.React/ForteWebReactExtensions.cs +++ b/Forte.Web.React/ForteWebReactExtensions.cs @@ -49,7 +49,7 @@ public static void AddReact(this IServiceCollection services, public static void UseReact(this IApplicationBuilder app, IEnumerable scriptUrls, Version reactVersion, bool disableServerSideRendering = false, string? nameOfObjectToSaveProps = null, - string? nameOfGlobalContextToSave = null, bool? useCache = null, bool? strictMode = null) + string? nameOfGlobalDataToSave = null, bool? useCache = null, bool? strictMode = null) { var config = app.ApplicationServices.GetService(); @@ -62,7 +62,7 @@ public static void UseReact(this IApplicationBuilder app, IEnumerable sc config.ScriptUrls = scriptUrls.ToList(); config.ReactVersion = reactVersion; config.NameOfObjectToSaveProps = nameOfObjectToSaveProps ?? config.NameOfObjectToSaveProps; - config.NameOfGlobalContextToSave = nameOfGlobalContextToSave ?? config.NameOfGlobalContextToSave; + config.NameOfGlobalDataToSave = nameOfGlobalDataToSave ?? config.NameOfGlobalDataToSave; config.UseCache = useCache ?? true; config.StrictMode = strictMode ?? false; } diff --git a/Forte.Web.React/HtmlHelperExtensions.cs b/Forte.Web.React/HtmlHelperExtensions.cs index 5f4c9b6..c78bca7 100644 --- a/Forte.Web.React/HtmlHelperExtensions.cs +++ b/Forte.Web.React/HtmlHelperExtensions.cs @@ -17,33 +17,33 @@ namespace Forte.Web.React; public static class HtmlHelperExtensions { #if NET48 - public static IHtmlString React(this HtmlHelper _, string componentName, T props, object? globalContext = null) + public static IHtmlString React(this HtmlHelper _, string componentName, T props, object? globalData = null) { var reactService = DependencyResolver.Current.GetService(); - var renderedComponent = reactService.RenderToStringAsync(componentName, props, globalContext: globalContext) + var renderedComponent = reactService.RenderToStringAsync(componentName, props, globalData: globalData) .GetAwaiter().GetResult(); return new HtmlString(renderedComponent); } - public static IHtmlString React(this HtmlHelper _, TComponent component, object? globalContext = null) + public static IHtmlString React(this HtmlHelper _, TComponent component, object? globalData = null) where TComponent : IReactComponent { var reactService = DependencyResolver.Current.GetService(); var renderedComponent = reactService - .RenderToStringAsync(component.Path, null, component.RenderingMode, globalContext) + .RenderToStringAsync(component.Path, null, component.RenderingMode, globalData) .GetAwaiter().GetResult(); return new HtmlString(renderedComponent); } public static IHtmlString React(this HtmlHelper _, TComponent component, - object? globalContext = null) + object? globalData = null) where TComponent : IReactComponent where TProps : IReactComponentProps { var reactService = DependencyResolver.Current.GetService(); var renderedComponent = reactService - .RenderToStringAsync(component.Path, component.Props, component.RenderingMode, globalContext).GetAwaiter() + .RenderToStringAsync(component.Path, component.Props, component.RenderingMode, globalData).GetAwaiter() .GetResult(); return new HtmlString(renderedComponent); @@ -60,33 +60,33 @@ public static IHtmlString InitJavascript(this HtmlHelper _) #if NET6_0_OR_GREATER public static async Task ReactAsync(this IHtmlHelper htmlHelper, string componentName, T props, - object? globalContext = null) + object? globalData = null) { var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService(); return new HtmlString( - await reactService.RenderToStringAsync(componentName, props, globalContext: globalContext)); + await reactService.RenderToStringAsync(componentName, props, globalData: globalData)); } public static async Task ReactAsync(this IHtmlHelper htmlHelper, TComponent component, - object? globalContext = null) + object? globalData = null) where TComponent : IReactComponent { var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService(); return new HtmlString( - await reactService.RenderToStringAsync(component.Path, null, component.RenderingMode, globalContext)); + await reactService.RenderToStringAsync(component.Path, null, component.RenderingMode, globalData)); } public static async Task ReactAsync(this IHtmlHelper htmlHelper, - TComponent component, object? globalContext = + TComponent component, object? globalData = null) where TComponent : IReactComponent where TProps : IReactComponentProps { var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService(); return new HtmlString( await reactService.RenderToStringAsync(component.Path, component.Props, component.RenderingMode, - globalContext)); + globalData)); } public static IHtmlContent InitJavascript(this IHtmlHelper htmlHelper) diff --git a/Forte.Web.React/React/ReactService.cs b/Forte.Web.React/React/ReactService.cs index ffe5598..608a1fa 100644 --- a/Forte.Web.React/React/ReactService.cs +++ b/Forte.Web.React/React/ReactService.cs @@ -18,7 +18,7 @@ public interface IReactService Task RenderAsync(TextWriter writer, string componentName, object? props = null, RenderOptions? options = null); Task RenderToStringAsync(string componentName, object? props = null, - RenderingMode renderingMode = RenderingMode.ClientAndServer, object? globalContext = null); + RenderingMode renderingMode = RenderingMode.ClientAndServer, object? globalData = null); } public class ReactService : IReactService @@ -67,7 +67,7 @@ public ReactService(INodeJSService nodeJsService, IJsonSerializationService json } #endif - private async Task InvokeRenderTo(Component component, object? props = null, object? globalContext = null, params object[] args) + private async Task InvokeRenderTo(Component component, object? props = null, object? globalData = null, params object[] args) { var allArgs = new List() { @@ -76,8 +76,8 @@ private async Task InvokeRenderTo(Component component, object? props = nul props, _config.ScriptUrls, _config.NameOfObjectToSaveProps, - _config.NameOfGlobalContextToSave, - globalContext + _config.NameOfGlobalDataToSave, + globalData }; allArgs.AddRange(args); @@ -108,7 +108,7 @@ private async Task InvokeRenderTo(Component component, object? props = nul public async Task RenderToStringAsync(string componentName, object? props = null, - RenderingMode renderingMode = RenderingMode.ClientAndServer, object? globalContext = null) + RenderingMode renderingMode = RenderingMode.ClientAndServer, object? globalData = null) { var component = new Component(componentName, props, renderingMode); Components.Add(component); @@ -118,7 +118,7 @@ public async Task RenderToStringAsync(string componentName, object? prop return WrapRenderedStringComponent(string.Empty, component); } - var result = await InvokeRenderTo(component, props, globalContext).ConfigureAwait(false); + var result = await InvokeRenderTo(component, props, globalData).ConfigureAwait(false); return WrapRenderedStringComponent(result, component); } diff --git a/Forte.Web.React/Scripts/renderToString.js b/Forte.Web.React/Scripts/renderToString.js index eac7c88..f7086ce 100644 --- a/Forte.Web.React/Scripts/renderToString.js +++ b/Forte.Web.React/Scripts/renderToString.js @@ -5,8 +5,8 @@ props = {}, scriptFiles, nameOfObjectToSaveProps, - nameOfGlobalContextToSave, - context = {} + nameOfGlobalDataToSave, + globalData = {} ) => { scriptFiles.forEach((scriptFile) => { require(scriptFile); @@ -15,7 +15,7 @@ const ReactDOMServer = global["ReactDOMServer"]; const React = global["React"]; const componentRepository = global["__react"] || {}; - global[nameOfGlobalContextToSave] = context; + global[nameOfGlobalDataToSave] = globalData; const path = componentName.split("."); let component = componentRepository[path[0]];