From 6494fc38d4be850c1604b47a4480eb830d4ea5e0 Mon Sep 17 00:00:00 2001 From: Worthen Date: Wed, 19 Jun 2019 12:25:38 -0700 Subject: [PATCH] feat: Update to .Net Core preview6 --- BlazorRealm.sln | 16 ++--- src/BlazorRealm/BlazorRealm.csproj | 23 +++--- .../IServiceCollectionExtensions.cs | 6 +- src/BlazorRealm/RealmComponent.cs | 4 +- ...ainer.cshtml => RealmStateContainer.razor} | 4 +- src/BlazorRealm/Store.cs | 3 +- src/BlazorRealm/_ViewImports.cshtml | 1 - src/BlazorRealmAsync/BlazorRealmAsync.csproj | 23 +++--- src/BlazorRealmAsync/_ViewImports.cshtml | 1 - .../BlazorRealmReduxDevTools.csproj | 21 +++--- .../IServiceCollectionExtensions.cs | 13 ++++ .../HandleReduxDevTools.cs | 72 +++++++++++++++---- .../MessageEventArgs.cs | 17 ++--- .../ReduxDevToolsInterop.cs | 46 +++++++----- .../_ViewImports.cshtml | 1 - .../content/RealmReduxDevTools.js | 7 +- 16 files changed, 158 insertions(+), 100 deletions(-) rename src/BlazorRealm/{RealmStateContainer.cshtml => RealmStateContainer.razor} (94%) delete mode 100644 src/BlazorRealm/_ViewImports.cshtml delete mode 100644 src/BlazorRealmAsync/_ViewImports.cshtml create mode 100644 src/BlazorRealmReduxDevTools/Extensions/IServiceCollectionExtensions.cs delete mode 100644 src/BlazorRealmReduxDevTools/_ViewImports.cshtml diff --git a/BlazorRealm.sln b/BlazorRealm.sln index dfe6dcc..3416b07 100644 --- a/BlazorRealm.sln +++ b/BlazorRealm.sln @@ -1,16 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2026 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28917.182 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorRealm", "src\BlazorRealm\BlazorRealm.csproj", "{E3C73603-90EF-472B-9076-043650A367E9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorStandAlone", "examples\BlazorStandAlone\BlazorStandAlone.csproj", "{B822325A-ED72-44FE-8721-3268C96C8B88}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorRealmAsync", "src\BlazorRealmAsync\BlazorRealmAsync.csproj", "{1BD0F7C1-0DD8-4600-9218-7728D6CE8D7F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorRealmReduxDevTools", "src\BlazorRealmReduxDevTools\BlazorRealmReduxDevTools.csproj", "{978D2FCB-A530-485D-A733-4C42E30FF38F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorClientApp", "examples\BlazorClientApp\BlazorClientApp.csproj", "{03D3D602-4271-42D0-9DEF-FC54F392E894}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,10 +21,6 @@ Global {E3C73603-90EF-472B-9076-043650A367E9}.Debug|Any CPU.Build.0 = Debug|Any CPU {E3C73603-90EF-472B-9076-043650A367E9}.Release|Any CPU.ActiveCfg = Release|Any CPU {E3C73603-90EF-472B-9076-043650A367E9}.Release|Any CPU.Build.0 = Release|Any CPU - {B822325A-ED72-44FE-8721-3268C96C8B88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B822325A-ED72-44FE-8721-3268C96C8B88}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B822325A-ED72-44FE-8721-3268C96C8B88}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B822325A-ED72-44FE-8721-3268C96C8B88}.Release|Any CPU.Build.0 = Release|Any CPU {1BD0F7C1-0DD8-4600-9218-7728D6CE8D7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1BD0F7C1-0DD8-4600-9218-7728D6CE8D7F}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BD0F7C1-0DD8-4600-9218-7728D6CE8D7F}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -33,6 +29,10 @@ Global {978D2FCB-A530-485D-A733-4C42E30FF38F}.Debug|Any CPU.Build.0 = Debug|Any CPU {978D2FCB-A530-485D-A733-4C42E30FF38F}.Release|Any CPU.ActiveCfg = Release|Any CPU {978D2FCB-A530-485D-A733-4C42E30FF38F}.Release|Any CPU.Build.0 = Release|Any CPU + {03D3D602-4271-42D0-9DEF-FC54F392E894}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03D3D602-4271-42D0-9DEF-FC54F392E894}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03D3D602-4271-42D0-9DEF-FC54F392E894}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03D3D602-4271-42D0-9DEF-FC54F392E894}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/BlazorRealm/BlazorRealm.csproj b/src/BlazorRealm/BlazorRealm.csproj index 7535217..d1e52b6 100644 --- a/src/BlazorRealm/BlazorRealm.csproj +++ b/src/BlazorRealm/BlazorRealm.csproj @@ -20,27 +20,22 @@ https://github.com/dworthen/BlazorRealm Git Blazor;Redux;State Management;Realm + + https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; + https://dotnet.myget.org/F/blazor-dev/api/v3/index.json; + + 3.0 + true - - - - - - + + + - - - - - - - - diff --git a/src/BlazorRealm/Extensions/IServiceCollectionExtensions.cs b/src/BlazorRealm/Extensions/IServiceCollectionExtensions.cs index 5314868..3eecad6 100644 --- a/src/BlazorRealm/Extensions/IServiceCollectionExtensions.cs +++ b/src/BlazorRealm/Extensions/IServiceCollectionExtensions.cs @@ -9,9 +9,9 @@ public static Store AddRealmStore(this IServiceCollection servic { Store store = new Store(initialState, rootReducer); services.AddSingleton>(store); - IServiceProvider serviceProvider = services.BuildServiceProvider(); - IStoreBuilder builder = new StoreBuilder(serviceProvider); - services.AddSingleton>(builder); + //IServiceProvider serviceProvider = services.BuildServiceProvider(); + //IStoreBuilder builder = new StoreBuilder(serviceProvider); + services.AddSingleton, StoreBuilder>(/*builder*/); return store; } } diff --git a/src/BlazorRealm/RealmComponent.cs b/src/BlazorRealm/RealmComponent.cs index cc9c26d..74fd55b 100644 --- a/src/BlazorRealm/RealmComponent.cs +++ b/src/BlazorRealm/RealmComponent.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNetCore.Blazor.Components; +using Microsoft.AspNetCore.Components; using System; namespace Blazor.Realm { - public class RealmComponent : BlazorComponent, IDisposable + public class RealmComponent : ComponentBase, IDisposable { [Inject] public Store Store { get; private set; } diff --git a/src/BlazorRealm/RealmStateContainer.cshtml b/src/BlazorRealm/RealmStateContainer.razor similarity index 94% rename from src/BlazorRealm/RealmStateContainer.cshtml rename to src/BlazorRealm/RealmStateContainer.razor index 9b51782..d6d9083 100644 --- a/src/BlazorRealm/RealmStateContainer.cshtml +++ b/src/BlazorRealm/RealmStateContainer.razor @@ -5,7 +5,7 @@ @ComponentTemplate(Store) -@functions { +@code { [Inject] private Store Store { get; set; } @@ -29,7 +29,7 @@ protected virtual void OnChangeHandler(object sender, EventArgs e) { State = Store.GetState(); - StateHasChanged(); + this.StateHasChanged(); } } \ No newline at end of file diff --git a/src/BlazorRealm/Store.cs b/src/BlazorRealm/Store.cs index d10a763..20ac3b0 100644 --- a/src/BlazorRealm/Store.cs +++ b/src/BlazorRealm/Store.cs @@ -1,5 +1,6 @@ using Microsoft.JSInterop; using System; +using System.Text.Json.Serialization; namespace Blazor.Realm { @@ -29,7 +30,7 @@ public TState GetState() { try { - return Json.Deserialize(Json.Serialize(State)); + return JsonSerializer.Parse(JsonSerializer.ToString(State)); } catch (Exception e) { return State; diff --git a/src/BlazorRealm/_ViewImports.cshtml b/src/BlazorRealm/_ViewImports.cshtml deleted file mode 100644 index 4a8ec84..0000000 --- a/src/BlazorRealm/_ViewImports.cshtml +++ /dev/null @@ -1 +0,0 @@ -@addTagHelper *, Blazor.Realm \ No newline at end of file diff --git a/src/BlazorRealmAsync/BlazorRealmAsync.csproj b/src/BlazorRealmAsync/BlazorRealmAsync.csproj index 0dfa581..93b28ff 100644 --- a/src/BlazorRealmAsync/BlazorRealmAsync.csproj +++ b/src/BlazorRealmAsync/BlazorRealmAsync.csproj @@ -19,23 +19,18 @@ Blazor;Redux;State Management;Realm;Middleware;Async https://github.com/dworthen/BlazorRealm true + + https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; + https://dotnet.myget.org/F/blazor-dev/api/v3/index.json; + + 3.0 + true - - - - - - - - - - - - - - + + + diff --git a/src/BlazorRealmAsync/_ViewImports.cshtml b/src/BlazorRealmAsync/_ViewImports.cshtml deleted file mode 100644 index f13af37..0000000 --- a/src/BlazorRealmAsync/_ViewImports.cshtml +++ /dev/null @@ -1 +0,0 @@ -@addTagHelper *, Blazor.Realm.Async \ No newline at end of file diff --git a/src/BlazorRealmReduxDevTools/BlazorRealmReduxDevTools.csproj b/src/BlazorRealmReduxDevTools/BlazorRealmReduxDevTools.csproj index 99dea0e..6a7168c 100644 --- a/src/BlazorRealmReduxDevTools/BlazorRealmReduxDevTools.csproj +++ b/src/BlazorRealmReduxDevTools/BlazorRealmReduxDevTools.csproj @@ -17,6 +17,12 @@ Git Blazor;Redux;State Management;Realm;Middleware;Dev Tools; true + + https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; + https://dotnet.myget.org/F/blazor-dev/api/v3/index.json; + + 3.0 + true @@ -27,16 +33,11 @@ - - - - - - - - - - + + + + + diff --git a/src/BlazorRealmReduxDevTools/Extensions/IServiceCollectionExtensions.cs b/src/BlazorRealmReduxDevTools/Extensions/IServiceCollectionExtensions.cs new file mode 100644 index 0000000..caa69ab --- /dev/null +++ b/src/BlazorRealmReduxDevTools/Extensions/IServiceCollectionExtensions.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Blazor.Realm.ReduxDevTools.Extensions +{ + public static class IServiceCollectionExtensions + { + public static IServiceCollection AddRealmReduxDevToolServices(this IServiceCollection services) + { + services.AddSingleton(); + return services; + } + } +} diff --git a/src/BlazorRealmReduxDevTools/HandleReduxDevTools.cs b/src/BlazorRealmReduxDevTools/HandleReduxDevTools.cs index 0568eea..c17a7dc 100644 --- a/src/BlazorRealmReduxDevTools/HandleReduxDevTools.cs +++ b/src/BlazorRealmReduxDevTools/HandleReduxDevTools.cs @@ -1,7 +1,14 @@ -using Microsoft.AspNetCore.Blazor.Services; +using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System; using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Extensions.Primitives; +using Microsoft.AspNetCore.Http.Extensions; +using System.Linq; +using Microsoft.AspNetCore.Components.Routing; +using System.Text.Json.Serialization; namespace Blazor.Realm.ReduxDevTools { @@ -13,6 +20,7 @@ public class HandleReduxDevTools private readonly Type[] ActionsToIgnore; private readonly Store Store; private readonly Dispatcher Next; + private readonly ReduxDevToolsInterop reduxDevToolsInterop; public HandleReduxDevTools(Store store, Dispatcher next, IServiceProvider serviceProvider) : this(store, next, serviceProvider, new Type[] { }) { @@ -26,27 +34,57 @@ public HandleReduxDevTools(Store store, Dispatcher next, IServic ServiceProvider = serviceProvider; ActionsToIgnore = actionsToIgnore ?? new Type[] { }; UriHelper = ServiceProvider.GetService(typeof(IUriHelper)) as IUriHelper; + //IJSRuntime JSRuntime = ServiceProvider.GetService(); + reduxDevToolsInterop = ServiceProvider.GetService(); + //reduxDevToolsInterop = new ReduxDevToolsInterop(JSRuntime); TState state = store.GetState(); - History.Add(new Tuple(UriHelper.GetAbsoluteUri(), Json.Serialize(state))); + History.Add(new Tuple(UriHelper.GetAbsoluteUri(), JsonSerializer.ToString(state))); - ReduxDevToolsInterop.Connect(); - ReduxDevToolsInterop.Init(state); - ReduxDevToolsInterop.MessageReceived += (object sender, MessageEventArgs eventArgs) => + reduxDevToolsInterop.Connect(); + reduxDevToolsInterop.Init(state); + + UriHelper.OnLocationChanged += (object s, LocationChangedEventArgs uri) => + { + Dictionary queryParams = QueryHelpers.ParseQuery(new Uri(UriHelper.GetAbsoluteUri()).Query); + if(!queryParams.ContainsKey("RealmReduxDevToolsNavigation")) + { + TState State = store.GetState(); + History.Add(new Tuple(UriHelper.GetAbsoluteUri(), JsonSerializer.ToString(state))); + reduxDevToolsInterop.Send(new RealmReduxDevToolsUriChanged(), State); + } + }; + + ReduxDevToolsInterop.MessageReceived += (object sender, Message eventArgs) => { - if(eventArgs.Message.Payload?.Type == "JUMP_TO_STATE" || eventArgs.Message.Payload?.Type == "JUMP_TO_ACTION") + if (eventArgs.Payload?.Type == "JUMP_TO_STATE" || eventArgs.Payload?.Type == "JUMP_TO_ACTION") { - int index = eventArgs.Message.Payload.Type == "JUMP_TO_STATE" - ? eventArgs.Message.Payload.Index - : eventArgs.Message.Payload.ActionId; + int index = eventArgs.Payload.Type == "JUMP_TO_STATE" + ? eventArgs.Payload.Index + : eventArgs.Payload.ActionId; Tuple desiredState = History[index]; - store.Dispatch(new RealmReduxDevToolsAppState(Json.Deserialize(desiredState.Item2))); - if(desiredState.Item1 != UriHelper.GetAbsoluteUri()) + store.Dispatch(new RealmReduxDevToolsAppState(JsonSerializer.Parse(desiredState.Item2))); + if (desiredState.Item1 != UriHelper.GetAbsoluteUri()) { - UriHelper.NavigateTo(desiredState.Item1); + UriBuilder uri = new UriBuilder(desiredState.Item1); + //Dictionary query = QueryHelpers.ParseNullableQuery(uri.Query); + //query.Add("RealmReduxDevToolsNavigation", "true"); + //uri.Query = QueryHelpers. + List> query = QueryHelpers + .ParseQuery(uri.Query) + .SelectMany(x => x.Value, (col, value) => new KeyValuePair(col.Key, value)) + .ToList(); + QueryBuilder qb = new QueryBuilder(query); + qb.Add("RealmReduxDevToolsNavigation", "true"); + + //string newUri = QueryHelpers.AddQueryString(desiredState.Item1, "RealmReduxDevToolsNavigation", "true"); + uri.Query = qb.ToQueryString().Value; + string newUri = uri.ToString(); + + UriHelper.NavigateTo(newUri); } } }; - ReduxDevToolsInterop.Subscribe(); + reduxDevToolsInterop.Subscribe(); } public TState Invoke(IRealmAction action) @@ -59,8 +97,8 @@ public TState Invoke(IRealmAction action) TState nextState = Next(action); if (nextState != null && Array.IndexOf(ActionsToIgnore, action.GetType()) == -1) { - History.Add(new Tuple(UriHelper.GetAbsoluteUri(), Json.Serialize(nextState))); - ReduxDevToolsInterop.Send(action, nextState); + History.Add(new Tuple(UriHelper.GetAbsoluteUri(), JsonSerializer.ToString(nextState))); + reduxDevToolsInterop.Send(action, nextState); } return nextState; } @@ -77,4 +115,8 @@ public RealmReduxDevToolsAppState(TState state) State = state; } } + + class RealmReduxDevToolsUriChanged : IRealmAction + { + } } diff --git a/src/BlazorRealmReduxDevTools/MessageEventArgs.cs b/src/BlazorRealmReduxDevTools/MessageEventArgs.cs index 472f5d8..0262612 100644 --- a/src/BlazorRealmReduxDevTools/MessageEventArgs.cs +++ b/src/BlazorRealmReduxDevTools/MessageEventArgs.cs @@ -1,18 +1,19 @@ using Microsoft.JSInterop; using System; +using System.Text.Json.Serialization; namespace Blazor.Realm.ReduxDevTools { - public class MessageEventArgs: EventArgs - { - public Message Message { get; set; } + //public class MessageEventArgs: EventArgs + //{ + // public Message Message { get; set; } - public MessageEventArgs(string message) - { - Message = Json.Deserialize(message); - } + // public MessageEventArgs(string message) + // { + // Message = JsonSerializer.Parse(message); + // } - } + //} public class Message { diff --git a/src/BlazorRealmReduxDevTools/ReduxDevToolsInterop.cs b/src/BlazorRealmReduxDevTools/ReduxDevToolsInterop.cs index 9a5114d..8acbeac 100644 --- a/src/BlazorRealmReduxDevTools/ReduxDevToolsInterop.cs +++ b/src/BlazorRealmReduxDevTools/ReduxDevToolsInterop.cs @@ -1,43 +1,53 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace Blazor.Realm.ReduxDevTools { - public static class ReduxDevToolsInterop + public class ReduxDevToolsInterop { - private static readonly string JSNameSpace = "BlazorRealmReduxDevTools"; - public static event EventHandler MessageReceived; + protected readonly string JSNameSpace = "BlazorRealmReduxDevTools"; + protected readonly IJSRuntime JSRuntime; + protected readonly IUriHelper UriHelper; + public static event EventHandler MessageReceived; + + public ReduxDevToolsInterop(IJSRuntime jsRuntime, IUriHelper uriHelper) + { + JSRuntime = jsRuntime; + UriHelper = uriHelper; + } + [JSInvokable] - public static void OnMessageReceived(string message) => MessageReceived?.Invoke(null, new MessageEventArgs(message)); - public static async Task IsAvailableAsync() + public static void OnMessageReceived(Message message) => MessageReceived?.Invoke(null, message); + public async Task IsAvailableAsync() { - bool result = await JSRuntime.Current.InvokeAsync($"{JSNameSpace}.IsAvailable"); + bool result = await JSRuntime.InvokeAsync($"{JSNameSpace}.IsAvailable"); return result; } - public static void Connect() + public void Connect() { - JSRuntime.Current.InvokeAsync($"{JSNameSpace}.Connect"); + JSRuntime.InvokeAsync($"{JSNameSpace}.Connect"); } - public static void Init(object state) + public void Init(object state) { - JSRuntime.Current.InvokeAsync($"{JSNameSpace}.Init", state); + JSRuntime.InvokeAsync($"{JSNameSpace}.Init", state); } - public static void Subscribe() + public void Subscribe() { - JSRuntime.Current.InvokeAsync($"{JSNameSpace}.Subscribe"); + JSRuntime.InvokeAsync($"{JSNameSpace}.Subscribe"); } - public static void Send(object action, object state) + public void Send(object action, object state) { - JSRuntime.Current.InvokeAsync($"{JSNameSpace}.Send", new { type = action.GetType().Name }, state); + JSRuntime.InvokeAsync($"{JSNameSpace}.Send", new { type = action.GetType().FullName }, state); } - public static void UnSubscribe() + public void UnSubscribe() { - JSRuntime.Current.InvokeAsync($"{JSNameSpace}.UnSubscribe"); + JSRuntime.InvokeAsync($"{JSNameSpace}.UnSubscribe"); } - public static void Disconnect() + public void Disconnect() { - JSRuntime.Current.InvokeAsync($"{JSNameSpace}.Disconnect"); + JSRuntime.InvokeAsync($"{JSNameSpace}.Disconnect"); } } } diff --git a/src/BlazorRealmReduxDevTools/_ViewImports.cshtml b/src/BlazorRealmReduxDevTools/_ViewImports.cshtml deleted file mode 100644 index b813073..0000000 --- a/src/BlazorRealmReduxDevTools/_ViewImports.cshtml +++ /dev/null @@ -1 +0,0 @@ -@addTagHelper *, Blazor.Realm.ReduxDevTools \ No newline at end of file diff --git a/src/BlazorRealmReduxDevTools/content/RealmReduxDevTools.js b/src/BlazorRealmReduxDevTools/content/RealmReduxDevTools.js index e8629a2..8b70c3d 100644 --- a/src/BlazorRealmReduxDevTools/content/RealmReduxDevTools.js +++ b/src/BlazorRealmReduxDevTools/content/RealmReduxDevTools.js @@ -10,6 +10,9 @@ }, Connect: function () { + devTools({ + latency: 0 + }); devTools = devTools.connect(); }, @@ -23,8 +26,8 @@ Subscribe: function () { devTools.subscribe((message) => { - var json = JSON.stringify(message); - DotNet.invokeMethod(assemblyName, "OnMessageReceived", json); + //var json = JSON.stringify(message); + DotNet.invokeMethod(assemblyName, "OnMessageReceived", message); }); },