Skip to content

Commit e3c842b

Browse files
ebekkergalvesribeiro
authored andcommitted
adding Length property to LocalSession (#5)
adjusting associated test to target the correction storage interface
1 parent df449e3 commit e3c842b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Blazor.Extensions.Storage/Storage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void SetItem<TItem>(string key, TItem item)
3535

3636
public class LocalStorage
3737
{
38+
public int Length => RegisteredFunction.Invoke<int>(MethodNames.LENGTH_METHOD, StorageTypeNames.LOCAL_STORAGE);
3839
public void Clear() => RegisteredFunction.InvokeUnmarshalled<object>(MethodNames.CLEAR_METHOD, StorageTypeNames.LOCAL_STORAGE);
3940

4041
public TItem GetItem<TItem>(string key)

test/Blazor.Extensions.Storage.Test/Pages/Index.cshtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
1515
var key = "forecasts";
1616
SessionStorage.SetItem<WeatherForecast[]>(key, forecasts);
1717
LocalStorage.SetItem<WeatherForecast[]>(key, forecasts);
18+
1819
var fromSession = SessionStorage.GetItem<WeatherForecast[]>(key);
1920
var fromLocal = LocalStorage.GetItem<WeatherForecast[]>(key);
2021

2122
logger.LogInformation("From session storage:");
2223
logger.LogInformation(fromSession);
2324
logger.LogInformation("From local storage:");
2425
logger.LogInformation(fromLocal);
26+
2527
logger.LogInformation($"Total in session: {SessionStorage.Length}");
26-
logger.LogInformation($"Total in local: {SessionStorage.Length}");
28+
logger.LogInformation($"Total in local: {LocalStorage.Length}");
29+
2730
logger.LogInformation("Removing from session storage...");
2831
SessionStorage.RemoveItem(key);
2932
logger.LogInformation("Removing from local storage...");
3033
LocalStorage.RemoveItem(key);
34+
3135
logger.LogInformation($"Total in session: {SessionStorage.Length}");
3236
logger.LogInformation($"Total in local: {SessionStorage.Length}");
3337
}

0 commit comments

Comments
 (0)