Repository navigation
Expand file tree
/
Copy pathSync.razor
More file actions
101 lines (81 loc) · 2.53 KB
/
Copy pathSync.razor
File metadata and controls
101 lines (81 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
@page "/sync"
@inject ISyncSessionStorageService sessionStorage
<h1>Non Async Session Storage</h1>
<div class="row mb-5">
<div class="col-md-4">
<h5>Add Item to session storage</h5>
<div class="input-group">
<input class="form-control" type="text" placeholder="Enter a value" @bind="Name" />
<div class="input-group-append">
<button class="btn btn-primary" @onclick="SaveName">Save</button>
</div>
</div>
</div>
<div class="col-md-4">
<h5>Remove item from session storage</h5>
<button class="btn btn-primary" @onclick="RemoveName">Remove Item</button>
</div>
<div class="col-md-4">
<h5>Clear session storage</h5>
<button class="btn btn-primary" @onclick="ClearSessionStorage">Clear All</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<h5>Value Read from session storage</h5>
@NameFromSessionStorage
</div>
<div class="col-md-4">
<h5>Items in session storage</h5>
@ItemsInSessionStorage
</div>
</div>
@code {
string NameFromSessionStorage { get; set; }
int ItemsInSessionStorage { get; set; }
string Name { get; set; }
protected override void OnInitialized()
{
GetNameFromSessionStorage();
GetSessionStorageLength();
sessionStorage.Changed += (sender, e) =>
{
Console.WriteLine($"Value for key {e.Key} changed from {e.OldValue} to {e.NewValue}");
};
}
void SaveName()
{
sessionStorage.SetItem("name", Name);
GetNameFromSessionStorage();
GetSessionStorageLength();
Name = "";
}
void GetNameFromSessionStorage()
{
NameFromSessionStorage = sessionStorage.GetItem<string>("name");
if (string.IsNullOrEmpty(NameFromSessionStorage))
{
NameFromSessionStorage = "Nothing Saved";
}
}
void RemoveName()
{
sessionStorage.RemoveItem("name");
GetNameFromSessionStorage();
GetSessionStorageLength();
}
void ClearSessionStorage()
{
Console.WriteLine("Calling Clear...");
sessionStorage.Clear();
Console.WriteLine("Getting name from session storage...");
GetNameFromSessionStorage();
Console.WriteLine("Calling Get Length...");
GetSessionStorageLength();
}
void GetSessionStorageLength()
{
Console.WriteLine(sessionStorage.Length());
ItemsInSessionStorage = sessionStorage.Length();
}
}