Comments (2)
Hey @scottsauber great idea!
But i see some potential issues with it, the expectation from the signature is that it should return null in this case.
Also one could really want to know if it is null or an empty collection.
But how about another overload, that allows to specify a default value that should be returned in case of a null or empty value?
Something like this
Storage.GetItem("Key", new List<ToDoItem>())
or
Storage.GetItem("Key", () => new List<ToDoItem>())
Would that be something of interest to you?
Another idea for your scenario might be to create an extension with exactly your logic in it.
public static T GetItemOrNew<T>(this Storage storage, string key)
where T : new()
{
var json= storage.GetItem(key);
if (string.IsNullOrEmpty(json))
{
return new T();
}
return Json.Deserialize<T>(json);
}
Thanks for the support, let me know how it went! And if there is video coverage i would be interested to see it!
from blazorstorage.
True, I guess you may treat no key exists in local storage differently than "the key exists, but nothing is in here."
Sounds good, I'll let you know on the video. It was recorded, so I assume it'll be up at some point.
Basically demo'd using it with ToDoMVC and this repo: https://github.com/scottsauber/BlazorToDoMVC
from blazorstorage.
Related Issues (18)
- Not working with blazor version 3.0.0-preview5-19227-01 HOT 3
- Does not work with server-side Blazor in 3.0.0-preview7 HOT 4
- .AddStorage() extension should return IServiceCollection to enable fluent code HOT 2
- Incompatibility with Blazor Preview 9 HOT 3
- upgrade to rc1 from preview9 HOT 2
- Not compatible with 0.5 version HOT 2
- Null Reference Exception .net core 3.0.10 Server side blazor HOT 4
- [Dotnet Core 3.0.100] Could not find 'Cloudcrate_AspNetCore_Blazor_Browser_Storage_LocalStorage' in 'window' error HOT 2
- Cannot read property 'toJavaScriptString' of undefined HOT 10
- Security / data obfuscation HOT 2
- JSInterop.JSException after only adding the script and .AddStorage()
- StorageEventArgs in reverse order
- TypeError: key is not a function HOT 1
- Cookie storage fallback HOT 3
- Blazor 0.5.1 , Error HOT 10
- Error with Blazor 0.8.0 HOT 7
- Add StorageEvent support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blazorstorage.