Git Product home page Git Product logo

Comments (2)

LunicLynx avatar LunicLynx commented on June 14, 2024 1

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.

scottsauber avatar scottsauber commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.