so this all works, but how do I set this as an Observable so that it will be available throughout the app and also automatically updates when the value changes?
Thank you very much @rapropos, this code will take me some time to try and understand - I am still struggeling to get my head around Observables, but I’m sure this will help me a lot!
Thank you.
Now you are boxed in to having your single source of truth be device storage, which is slow, and must maintain strict discipline about waiting on writes lest you generate race conditions, which are hard to diagnose.
Ok thats true. I looked at your example and I think thats the better way of doing it. I usually dispatch an action with ngxs to update the value in the store.
@rapropos Does that change anything in your opinion? If I store the value in state management?
from(this.getStorage).subscribe(value => {
do something with value here.
})
I frankly can’t say anything about ngxs in particular, because I’ve never used it. I looked at ngrx once, which appears to have a similar goal, but it reminded me too much of ORMs in terms of the bondage level and need for complete buy-in. There’s plenty of room for reasonable people to have different opinions about those sorts of tools, though, so I’m not intending to say I think they’re bad - just not my cup of tea.
Whatever you do, though, I think the rule of “only read from device storage at app start and resume time” has value.