Open Maradox opened 8 years ago
Not at present.
A quick way to work around this is to debounce the notifications by, say, 100ms.
On Wed, Jun 8, 2016 at 12:06 PM Martin Perebner notifications@github.com wrote:
Is it possible to bulk set/observe several values?
For example I have one string and two enums, which I set at the same time. Currently this causes as to be expected three emissions (I use combineLatest) .
Is there a way to delay the apply so all three values are set together, and observe this set as a whole, while still using different datatypes?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/f2prateek/rx-preferences/issues/46, or mute the thread https://github.com/notifications/unsubscribe/AAEEET8amUECAZpPol6NKnwK6Pzxdh_Kks5qJuiEgaJpZM4IxIRP .
If you can guarantee they are always set together you can use zip
.
Otherwise you could consider storing them as one object or String, perhaps as JSON.
Thanks for the suggestion, but I can't use zip, since if one of the fields is overwritten with the same value, it won't emit an item, and thus zip won't work.
TL;DR: rx-preferences drops atomicity of multi-preference commits.
If I need atomicity I'd want access to the wrapped SharedPreferences object to use the standard Editor builder approach. However the object is not visible; I'd have to keep track of the original SharedPreferences object separately.
For the time being I am forking the project to give me the customizations that I need - I find rx-preferences very useful otherwise. Sadly I doubt that my changes (besides the trivial object visibility change) would be acceptable to this project, as they are not very "reactive".
If they really belog together, just create a model class that holds these 3 values and store that.
@PaulWoitaschek Using a model sounds like a good solution, but you that introduces different kinds of problems. For storing models into SharedPreferences
, you'll have to serialize them in some manner. If the models ever change, you have to ensure you don't forget to handle the migration. If you start writing migrations, it might just be a better idea to store them in a DB so that your database abstraction (Room for e.g.,) complains if you forget to write a migration.
Is it possible to bulk set/observe several values?
For example I have one string and two enums, which I set at the same time. Currently this causes as to be expected three emissions (I use combineLatest) .
Is there a way to delay the
apply
so all three values are set together, and observe this set as a whole, while still using different datatypes?