-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes and update to blazor sample
- Loading branch information
Showing
10 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletions
19
src/Shiny.Mediator.Blazor/Infrastructure/StorageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
using System.Text.Json; | ||
using Microsoft.JSInterop; | ||
using Shiny.Mediator.Infrastructure; | ||
|
||
namespace Shiny.Mediator.Blazor.Infrastructure; | ||
|
||
|
||
public class StorageService(IJSRuntime jsruntime) : IStorageService | ||
public class StorageService(IJSRuntime jsruntime, ISerializerService serializer) : IStorageService | ||
{ | ||
public Task Set<T>(string key, T value) | ||
{ | ||
var json = JsonSerializer.Serialize(value); | ||
((IJSInProcessRuntime)jsruntime).Invoke<string?>("localStorage.setItem", key, json); | ||
var json = serializer.Serialize(value); | ||
((IJSInProcessRuntime)jsruntime).Invoke<string?>("MediatorServices.setStore", key, json); | ||
|
||
return Task.FromResult(key); | ||
} | ||
|
||
|
||
public Task<T> Get<T>(string key) | ||
public Task<T?> Get<T>(string key) | ||
{ | ||
var stringValue = ((IJSInProcessRuntime)jsruntime).Invoke<string?>("localStorage.getItem", key); | ||
var stringValue = ((IJSInProcessRuntime)jsruntime).Invoke<string?>("MediatorServices.getStore", key); | ||
if (String.IsNullOrWhiteSpace(stringValue)) | ||
return null!; | ||
return Task.FromResult<T?>(default); | ||
|
||
var final = JsonSerializer.Deserialize<T>(stringValue); | ||
return Task.FromResult(final); | ||
var final = serializer.Deserialize<T>(stringValue); | ||
return Task.FromResult<T?>(final); | ||
} | ||
|
||
|
||
public Task Remove(string key) | ||
{ | ||
var inproc = (IJSInProcessRuntime)jsruntime; | ||
inproc.InvokeVoid("localStorage.removeItem", key); | ||
inproc.InvokeVoid("MediatorServices.removeStore", key); | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters