Skip to content

Commit 7d4bc84

Browse files
committed
Removed JS and sorted README
1 parent 81044b2 commit 7d4bc84

5 files changed

Lines changed: 27 additions & 54 deletions

File tree

‎README.md‎

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,43 @@ Or via the Visual Studio package manger.
1515

1616
### Setup
1717

18-
You need to add a reference to the Blazored SessionStorage javascript file in your `index.html` (Blazor WebAssembly) `_Host.cshtml` (Blazor Server).
19-
20-
```html
21-
<script src="_content/Blazored.SessionStorage/blazored-sessionstorage.js"></script>
22-
```
23-
24-
You will then need to register the local storage services with the service collection in your _startup.cs_ file.
18+
You will need to register the session storage services with the service collection in your _startup.cs_ file.
2519

2620
```c#
2721
public void ConfigureServices(IServiceCollection services)
2822
{
29-
services.AddBlazoredLocalStorage();
23+
services.AddBlazoredSessionStorage();
3024
}
3125
```
3226

3327
### Usage (Blazor WebAssembly)
34-
To use Blazored.SessionStorage in Blazor WebAssembly, inject the `ILocalStorageService` per the example below.
28+
To use Blazored.SessionStorage in Blazor WebAssembly, inject the `ISessionStorageService` per the example below.
3529

3630
```c#
37-
@inject Blazored.SessionStorage.ILocalStorageService localStorage
31+
@inject Blazored.SessionStorage.ISessionStorageService sessionStorage
3832

3933
@code {
4034

4135
protected override async Task OnInitializedAsync()
4236
{
43-
await localStorage.SetItemAsync("name", "John Smith");
44-
var name = await localStorage.GetItemAsync<string>("name");
37+
await sessionStorage.SetItemAsync("name", "John Smith");
38+
var name = await sessionStorage.GetItemAsync<string>("name");
4539
}
4640

4741
}
4842
```
4943

50-
With Blazor WebAssembly you also have the option of a synchronous API, if your use case requires it. You can swap the `ILocalStorageService` for `ISyncStorageService` which allows you to avoid use of `async`/`await`. For either interface, the method names are the same.
44+
With Blazor WebAssembly you also have the option of a synchronous API, if your use case requires it. You can swap the `ISessionStorageService` for `ISyncStorageService` which allows you to avoid use of `async`/`await`. For either interface, the method names are the same.
5145

5246
```c#
53-
@inject Blazored.SessionStorage.ISyncStorageService localStorage
47+
@inject Blazored.SessionStorage.ISyncStorageService sessionStorage
5448

5549
@code {
5650

5751
protected override void OnInitialized()
5852
{
59-
localStorage.SetItem("name", "John Smith");
60-
var name = localStorage.GetItem<string>("name");
53+
sessionStorage.SetItem("name", "John Smith");
54+
var name = sessionStorage.GetItem<string>("name");
6155
}
6256

6357
}
@@ -68,22 +62,22 @@ With Blazor WebAssembly you also have the option of a synchronous API, if your u
6862
**NOTE:** Due to pre-rendering in Blazor Server you can't perform any JS interop until the `OnAfterRender` lifecycle method.
6963

7064
```c#
71-
@inject Blazored.SessionStorage.ILocalStorageService localStorage
65+
@inject Blazored.SessionStorage.ISessionStorageService sessionStorage
7266

7367
@functions {
7468

7569
protected override async Task OnAfterRenderAsync()
7670
{
77-
await localStorage.SetItemAsync("name", "John Smith");
78-
var name = await localStorage.GetItemAsync<string>("name");
71+
await sessionStorage.SetItemAsync("name", "John Smith");
72+
var name = await sessionStorage.GetItemAsync<string>("name");
7973
}
8074

8175
}
8276
```
8377

8478
The APIs available are:
8579

86-
- asynchronous via `ILocalStorageService`:
80+
- asynchronous via `ISessionStorageService`:
8781
- SetItemAsync()
8882
- GetItemAsync()
8983
- RemoveItemAsync()

‎src/Blazored.SessionStorage/Blazored.SessionStorage.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<TypeScriptToolsVersion>3.2</TypeScriptToolsVersion>
88

99
<PackageId>Blazored.SessionStorage</PackageId>
10-
<Version>1.0.7</Version>
10+
<Version>1.0.8</Version>
1111
<Authors>Chris Sainty</Authors>
1212
<Description>A library to provide access to session storage in Blazor applications</Description>
1313
<Copyright>Copyright 2018 (c) Chris Sainty. All rights reserved.</Copyright>

‎src/Blazored.SessionStorage/SessionStorageService.cs‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task SetItemAsync(string key, object data)
2626
if (e.Cancel)
2727
return;
2828

29-
await _jSRuntime.InvokeAsync<object>("blazoredSessionStorage.setItem", key, JsonSerializer.Serialize(data));
29+
await _jSRuntime.InvokeAsync<object>("sessionStorage.setItem", key, JsonSerializer.Serialize(data));
3030

3131
RaiseOnChanged(key, e.OldValue, data);
3232
}
@@ -36,7 +36,7 @@ public async Task<T> GetItemAsync<T>(string key)
3636
if (string.IsNullOrEmpty(key))
3737
throw new ArgumentNullException(nameof(key));
3838

39-
var serialisedData = await _jSRuntime.InvokeAsync<string>("blazoredSessionStorage.getItem", key);
39+
var serialisedData = await _jSRuntime.InvokeAsync<string>("sessionStorage.getItem", key);
4040

4141
if (serialisedData == null)
4242
return default(T);
@@ -49,14 +49,14 @@ public async Task RemoveItemAsync(string key)
4949
if (string.IsNullOrEmpty(key))
5050
throw new ArgumentNullException(nameof(key));
5151

52-
await _jSRuntime.InvokeAsync<object>("blazoredSessionStorage.removeItem", key);
52+
await _jSRuntime.InvokeAsync<object>("sessionStorage.removeItem", key);
5353
}
5454

55-
public async Task ClearAsync() => await _jSRuntime.InvokeAsync<object>("blazoredSessionStorage.clear");
55+
public async Task ClearAsync() => await _jSRuntime.InvokeAsync<object>("sessionStorage.clear");
5656

57-
public async Task<int> LengthAsync() => await _jSRuntime.InvokeAsync<int>("blazoredSessionStorage.length");
57+
public async Task<int> LengthAsync() => await _jSRuntime.InvokeAsync<int>("eval", "sessionStorage.length");
5858

59-
public async Task<string> KeyAsync(int index) => await _jSRuntime.InvokeAsync<string>("blazoredSessionStorage.key", index);
59+
public async Task<string> KeyAsync(int index) => await _jSRuntime.InvokeAsync<string>("sessionStorage.key", index);
6060

6161
public void SetItem(string key, object data)
6262
{
@@ -71,7 +71,7 @@ public void SetItem(string key, object data)
7171
if (e.Cancel)
7272
return;
7373

74-
_jSInProcessRuntime.Invoke<object>("blazoredSessionStorage.setItem", key, JsonSerializer.Serialize(data));
74+
_jSInProcessRuntime.Invoke<object>("sessionStorage.setItem", key, JsonSerializer.Serialize(data));
7575

7676
RaiseOnChanged(key, e.OldValue, data);
7777
}
@@ -84,7 +84,7 @@ public T GetItem<T>(string key)
8484
if (_jSInProcessRuntime == null)
8585
throw new InvalidOperationException("IJSInProcessRuntime not available");
8686

87-
var serialisedData = _jSInProcessRuntime.Invoke<string>("blazoredSessionStorage.getItem", key);
87+
var serialisedData = _jSInProcessRuntime.Invoke<string>("sessionStorage.getItem", key);
8888

8989
if (serialisedData == null)
9090
return default(T);
@@ -100,31 +100,31 @@ public void RemoveItem(string key)
100100
if (_jSInProcessRuntime == null)
101101
throw new InvalidOperationException("IJSInProcessRuntime not available");
102102

103-
_jSInProcessRuntime.Invoke<object>("blazoredSessionStorage.removeItem", key);
103+
_jSInProcessRuntime.Invoke<object>("sessionStorage.removeItem", key);
104104
}
105105

106106
public void Clear()
107107
{
108108
if (_jSInProcessRuntime == null)
109109
throw new InvalidOperationException("IJSInProcessRuntime not available");
110110

111-
_jSInProcessRuntime.Invoke<object>("blazoredSessionStorage.clear");
111+
_jSInProcessRuntime.Invoke<object>("sessionStorage.clear");
112112
}
113113

114114
public int Length()
115115
{
116116
if (_jSInProcessRuntime == null)
117117
throw new InvalidOperationException("IJSInProcessRuntime not available");
118118

119-
return _jSInProcessRuntime.Invoke<int>("blazoredSessionStorage.length");
119+
return _jSInProcessRuntime.Invoke<int>("eval", "sessionStorage.length");
120120
}
121121

122122
public string Key(int index)
123123
{
124124
if (_jSInProcessRuntime == null)
125125
throw new InvalidOperationException("IJSInProcessRuntime not available");
126126

127-
return _jSInProcessRuntime.Invoke<string>("blazoredSessionStorage.key", index);
127+
return _jSInProcessRuntime.Invoke<string>("sessionStorage.key", index);
128128
}
129129

130130
public event EventHandler<ChangingEventArgs> Changing;

‎src/Blazored.SessionStorage/wwwroot/blazored-sessionstorage.js‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎src/Blazored.SessionStorage/wwwroot/blazored-sessionstorage.js.map‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)