Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Question About Seeing Changes #400

Closed
SubutaDan opened this issue Aug 16, 2024 · 7 comments
Closed

A Question About Seeing Changes #400

SubutaDan opened this issue Aug 16, 2024 · 7 comments

Comments

@SubutaDan
Copy link

My Flutter app use offline-first-with-REST to manage a collection of items ("kokos"). The user's kokos are displayed in a Listview on a stateful widget screen. The user can navigate to a detail screen where they can add a new koko or edit or delete an existing koko. After any of these actions the detail screen closes and the list screen reloads, rebuilding the list.

When the list screen reloads and the list is rebuilt, the change (create, update or delete) that the user just performed is reflected in the newly rebuilt list. This is the result I want, but I am wondering whether it will work reliably. My thinking is that the mutating operation happens asynchronously and so may not occur before the list is rebuilt, in which case its result would not be visible. Is this a legitimate concern? Do I need to add some form of change notification to ensure that the list will be up to date?

Thanks very much.

@hortigado
Copy link

hortigado commented Aug 16, 2024

Hi, there are several methods that can be implemented, such as adding an effect on the modified item when loading or a shimmer effect; or as you mentioned with a toast notification.
But in order to do these, a problem arises that is already being discussed #393 . How could we know if the document was successfully modified on the server if this information cannot be obtained; locally it is not the case because this can be known. It is a feature that still needs to be worked on in the package.

One idea that occurs to me is to create a RespondBrick() variable in each class and brick lea has the power to modify it locally. And thus be able to have more information about the status of this document, but this idea would be yet to be implemented by brick

class RespondBrick {
  String? remoteRespond;
  bool? synced;

  RespondBrick({this.remoteRespond, this.synced});

  RespondBrick.fromJson(Map<String, dynamic> json) {
    remoteRespond = json['remote_respond'];
    synced = json['synced'];
  }

@tshedor
Copy link
Collaborator

tshedor commented Aug 16, 2024

It sounds like your list just needs to reflect the latest state, so it should be built using a stream from OfflineFirstRepository#subscribe.

I'm unclear if this is about managing server response and potential rejection. What would trigger a list rebuild if it wasn't a mutating action the user performed themselves?

@SubutaDan
Copy link
Author

SubutaDan commented Aug 16, 2024 via email

@tshedor
Copy link
Collaborator

tshedor commented Aug 16, 2024

Brick is not designed to handle any state changes. #subscribe will notify when your query's result has changed. Based on your follow-up, I think this is a UI/state question and outside the scope of Brick.

@SubutaDan
Copy link
Author

SubutaDan commented Aug 16, 2024 via email

@SubutaDan
Copy link
Author

Hi @tshedor ,
Thanks for pointing me at the subscribe() method. I have started working with it and it seems to be just what I needed.
BTW, the comments in the code say that it works for upserts. I am glad to report that it seems to work for deletes too.
Unless you think I have missed something I suggest we close this ticket.
Thanks again.
-Dan

@tshedor
Copy link
Collaborator

tshedor commented Aug 19, 2024

@SubutaDan Good to know if works for deletes too. Glad you've got the right tools to help you out here, good luck

@tshedor tshedor closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants