Open philipp-mohr opened 7 years ago
Okay, I have a suspicion: result.removeSource(dbSource) disconnects the dbSource from result live data. Then the change in db happens due to insertion of new network data. When we reconnect to dbSource nothing will be emitted because result live data was disconnected when the change happened.
This issue is resolved by extracting a new db live data object using loadFromDb(). Right?
When the network call fails don't we need to call loadFromDb() as well, to communicate the Resource.error immediately? If we use dbSource there I would expect that the Resource.error is not emmitted immediatly, since the dbSource data does not change.
@JoseAlcerreca Would you like to add something?
@piveloper If dbSource has already emitted a value, result.addSource(dbSource) will emit cache value. result.addSource(loadFromDb()) will emit newly Value.
Why is loadFromDb() called another time after network data is fetched successfully? Why can't we use dbSource live data object again?
The way I understand live data object of a database is that if we extract it once, all changes in db will be notified to the observer. If this is correct dbSource can replace loadFromDb(), right?
NetworkBoundResource.class: