RocketData icon indicating copy to clipboard operation
RocketData copied to clipboard

Add ability to listen to ids with Rocket Data

Open plivesey opened this issue 8 years ago • 2 comments

For collection data providers, it'd be great to filter on model changes and insert them into the collection if they meet a certain filter. This would be like predicates in core data.

plivesey avatar Jan 11 '17 19:01 plivesey

Do you have an idea of how this could be possible, perhaps if it would be possible to listen for a type?

hebertialmeida avatar Jan 22 '20 18:01 hebertialmeida

Hmmm...looks like this may already be possible with data providers. It looks like you can create a DataProvider and set modelIdentifier. Then, once the model is available, it'll be set onto the data provider.

For the filter method, the easiest way seems to be to do this right after the data changes but before you notify any delegates? And it would just run it on the main thread before notifying listeners?

For listening to certain models for a collection data provider, you could use the consistency manager method:

    open func addModelUpdatesListener(_ updatesListener: ConsistencyManagerUpdatesListener) {
        modelUpdatesListeners.append(updatesListener)
    }

This basically fires for every single model change and so you could filter there. However, threading may be tough. Currently, it runs on the main thread:

     The `ConsistencyManagerUpdatesListener` methods are called on the **main thread** for every model updated in the system.
     It's recommended to do as minimal processing as possible here so you don't block the main thread.
     It's also recommended to have a small number of global listeners.

Maybe it's good enough to just filter on the main thread. Maybe you want to queue them up on a background thread but make sure they're in order (so you always get eventual consistency?)

It would be tough to manage because someone could also change the data on the data provider at any time? So...some ideas...some of this is certainly very tricky, but possible.

plivesey avatar Jan 22 '20 20:01 plivesey