Comments (4)
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.
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.
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.
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)
- methods using @DefaultValue should cache value
- add RxJava Observable support to preference change listeners
- add caching of method annotations
- improved type adapter declarations
- Clear method request HOT 2
- Using Enum as default value HOT 2
- automate sdk initialisation
- methods using @KeyByResource should cache value
- Not wokring harness package
- Add support for EncryptedSharaedPreferences
- allow other types through custom type adapters
- add support for explicit apply/commit methods
- provide instructions for proguard
- investigate annotation processors
- Set<String> support HOT 2
- Remove? HOT 2
- add support for change listeners HOT 4
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 storebox.