CombineDataSources icon indicating copy to clipboard operation
CombineDataSources copied to clipboard

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

Open nathan-hh opened this issue 5 years ago • 8 comments

nathan-hh avatar Jul 16 '20 13:07 nathan-hh

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?

icanzilb avatar Jul 25 '20 12:07 icanzilb

@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?

nathan-hh avatar Sep 17 '20 15:09 nathan-hh

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

freak4pc avatar Sep 17 '20 16:09 freak4pc

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 :)

kevinrenskers avatar Oct 02 '20 18:10 kevinrenskers

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

freak4pc avatar Oct 02 '20 18:10 freak4pc

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

kevinrenskers avatar Oct 02 '20 18:10 kevinrenskers

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

freak4pc avatar Oct 02 '20 18:10 freak4pc

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

nathan-hh avatar Oct 02 '20 18:10 nathan-hh