Skip to content

Support observing multiple boxes #59

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

Open
FabianTerhorst opened this issue Mar 16, 2017 · 10 comments
Open

Support observing multiple boxes #59

FabianTerhorst opened this issue Mar 16, 2017 · 10 comments
Labels
enhancement New feature or request

Comments

@FabianTerhorst
Copy link

Maybe support an store.boxFor(Class[]).query()?

@greenrobot
Copy link
Member

You can use one of the BoxStore.subscribe() methods to achieve that. Does that work for you?

@FabianTerhorst
Copy link
Author

Does the method only triggers one time after an transaction with multiple types involved?

@greenrobot
Copy link
Member

No, it invokes per Class passing the Class as an parameter.

@FabianTerhorst
Copy link
Author

Ok, what would be the best practice to get all objects from 3 boxes?

@greenrobot
Copy link
Member

@FabianTerhorst Getting all objects (box.getAll()) or getting notifications? The latter would involve BoxStore.subscribe() and check the class in the callback. The callback is called 3 times for three boxes. If you want just a single call being made, we may consider an additional method to be implemented. In that case it would help to see the use case. If that may be useful for other users, we will consider it.

@FabianTerhorst
Copy link
Author

@greenrobot i have a list of objects inside an recyclerview, the list is containing 3 different types of objects.

@greenrobot
Copy link
Member

Thinking about changing the callback to receive a list of changed entity classes...

@greenrobot greenrobot added the enhancement New feature or request label Apr 6, 2017
@zoltish
Copy link

zoltish commented Mar 29, 2018

If you have an entity with a list of other entities, shouldnt the other entities changing also trigger the parents change?

E.g.:

  1. ExerciseEntity has a list of BodypartEntity
  2. A BodypartEntity changes
  3. BodypartEntity gets notified, but not ExerciseEntity

I understand that this makes it far more complex, but a hint on whether you are planning to incorporate it or not would be great!

@udyr-woo
Copy link

udyr-woo commented Apr 7, 2025

You can use one of the BoxStore.subscribe() methods to achieve that. Does that work for you?

which subscribe()?

public SubscriptionBuilder subscribe()

this one? how to use it?

I understood how to subscribe to other class of changes, but I don't know how to subscribe to more than one class of changes at the same time.

@greenrobot-team
Copy link
Member

greenrobot-team commented Apr 14, 2025

@udyr-woo As I noted in #1204 (comment), your code can use BoxStore.subscribe(Class<T> forClass).

To subscribe to multiple, create multiple subscriptions. You would have to write logic to combine updates from each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants