CombineCommunity / CombineDataSources

Table and collection view data sources for Combine
https://combine.community
MIT License
627 stars 44 forks source link

implement "modelSelected" and more methods "combine way" for UICollectionView and UITableview #11

Open nathan-hh opened 4 years ago

icanzilb commented 4 years ago

I think this might be useful - currently the api allows you to implement this via table delegates but having something along the lines of what RxDataSources has would be fine. I always had an issue with the fact that RxDataSources is supposed to be a data-source but it does user input handling as well, but honestly is the simplest way and people seem to like it so who am I to argue with that :)

@nathan-hh do you have a list in mind of which methods besides modelSelected you'd like to see implemented?

nathan-hh commented 4 years ago

@freak4pc i saw that you updated "delegate proxy" on CombineCocoa but didn't tag it for Pod version yet.. @icanzilb to solve this issue i guess need to use CombineCocoa library. is it ok if i'll do it?

freak4pc commented 4 years ago

@nathan-hh there seems to be some bug in it with the latest version of Xcode / Swift. @jdisho is working on it AFAIK.

kevinrenskers commented 4 years ago

I would love this! This is how I currently deal with selection using the delegate proxy stuff from CombineCocoa.

viewModel.models
  .bind(subscriber: collectionView.itemsSubscriber(cellIdentifier: Cell.reuseIdentifier, cellType: Cell.self) { cell, _, model in
    cell.configure(model: model)
  })
  .store(in: &subscriptions)

collectionView.didSelectItemPublisher
  .combineLatest(viewModel.models)
  .map { indexPath, models in
    models[indexPath.item]
  }
  .sink { model in
    // Do whatever you want with the model
  }
  .store(in: &subscriptions)

Not having to do the translation from the IndexPath to a model would be pretty nice :)

freak4pc commented 4 years ago

Right, to be honest I'm not 100% sure you could deal with it in the context of this repo without copy-pasting all of the DelegateProxy stuff or have CombineExt as a dependency

kevinrenskers commented 4 years ago

Maybe some conditional imports and functions for if the user happens to have both modules installed?

freak4pc commented 4 years ago

Sounds more reasonable to have a RxDataSourcesCore and RxDataSources (or the other way - RxDataSourcesModel vs. RxDataSources) , different dependencies

nathan-hh commented 4 years ago

@freak4pc i forked and i'll solve it with CombineCocoa library. i'll pull request and let @icanzilb to decide