I am developing a messaging application for
iOS (although my question is not iOS related).
I am using offline-first approach and I am adhering to the clean architecture design pattern.
I currently have a repository called
MessagesRepository this repository has multiple main data sources,
MemoryDatabase and a
The repository exposes
CRUD operations such as
get, create, etc.... When adding an item to the repository it will persist it on
disk and then emit it via
Because of the clean architecture design pattern I am able to observe the sending of message and state via a
callback from the
My question is how can I observe changes to the repository when for example some other user
emit a message and my
socket.io receives it? The logic would be on receiving it to store it on
disk but how can I notify my frontend?
I was thinking of creating a
use case called
Subscribe to... which will store a callback on the repository and when a socket event happens I will call that callback. I am not sure what would be the best way to tackle such a problem, I have done a ton of research but I don't seem to find an answer.
I thought of moving the
socket to the presentation layer but that doesn't make sense because
socket is some sort of data that tomorrow I may change to say something like
http pooling not that I will but it is a moving part that can't exist on the persentation layer to adhere to
Temporarily I have a
refresh button that I press to see the changes.
I guess to sum it all up, the question is. Can I Observe a Repository? if so what would be the best approach?
My repository also has 2 main functions
save I know they don't belong to the repository but not sure where else to put them. Basically
save will make the
data available only on device and
commit would send the data out.