Code Monkey home page Code Monkey logo

Comments (4)

martino2k6 avatar martino2k6 commented on July 21, 2024

For the IllegalArgumentException I can workaround this and make it return null instead, although this doesn't seem ideal. The correct solution here would be to allow for versioning (in a similar fashion to how the SQLiteOpenHelper does it) and letting the client implementation decide how to handle this change, whether to clear the value or update it.

However if it's the default value that you're concerned about ('default' in this case meaning when it is absent, not when there is a value in the preferences which no longer matches against a changed enum declaration), then I would suggest using a getter with a default (or perhaps me adding an annotation for this, to go along with @DefaultValue). This solution would remove the need for supplying a custom type adapter for a type which is already supported, as I'm not particularly sure of the benefits.

from storebox.

artyommironov avatar artyommironov commented on July 21, 2024

I mostly concerned about changes in code that can crash app after updating its version, such as changing preference type (for example from Integer to String) without changing the key or renaming enum values. I would try catch all such errors by default and return null, but maybe better solution to pass something like ErrorHandlingStrategy to StoreBox build method. Versioning for preference look like overkill, they meant to be simpler than sqlite db.

from storebox.

martino2k6 avatar martino2k6 commented on July 21, 2024

Let's say that you weren't using StoreBox and you changed the type of a stored preference (ie using your integer to string example) or changed an enum, how would you handle this? Would you put try-catch blocks when getting these values? Would you clear these values when starting up the updated version of the app for the first time?

Preferences are meant to be simpler, but if you've changed the schema of how the values are stored then that needs to be accounted for. Detecting when this has happened and provide some kind of sensible strategy on this (ie sending out nulls/0/0f/0d/etc could hardly be considered 'safe') would be difficult, and could potentially mask other issues -- not something I'd like to see.

from storebox.

martino2k6 avatar martino2k6 commented on July 21, 2024

After having left this ticket stale for a while, I have decided to remove the preference version handling support for now. I will considering adding it back in if it will look like there might be more demand for it.

For now people will just have to be careful about changing the schema of their stored preferences, which is something that they would have needed to do without using this library as well.

from storebox.

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.