-1

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, Socket.IO, generic MemoryDatabase and a Disk Database.

The repository exposes CRUD operations such as get, create, etc.... When adding an item to the repository it will persist it on memory and disk and then emit it via Socket.

Because of the clean architecture design pattern I am able to observe the sending of message and state via a callback from the sendMessageUseCase to MessagesRepository.

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 memory and 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 SoC Principle.

Temporarily I have a refresh button that I press to see the changes.

This is a simple diagram of my current architecture This is a simple diagram of my current architecture

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 commitand 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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.