Giter Site home page Giter Site logo

Comments (3)

kzaher avatar kzaher commented on May 13, 2024

Hi @plm75 ,

yeah, I agree. We need helpful feedback from people to understand how to best present this. Could you provide a list of questions you would like to be answered so we can write up some kind of FAQ?

from rxdatasources.

plm75 avatar plm75 commented on May 13, 2024

Hi @kzaher ,

Following up on your suggestion, the following is a quick and dirty list that summarizes what I currently understand of RxDataSources after literally only a few hours of playing with the examples and questions that I currently have.

Again, I've just started learning Rx so I may/probably have missed some obvious stuff so apologies in advance. Hope you or someone else will find time to review it and provide guidance for the questions.

  • How to implement dataSources the 'default' way without RxDataSources:
    Four methods are available:
    rx_itemsWithCellIdentifier(:String)
    rx_itemsWithCellIdentifier(:String:Cell.Type)
    rx_itemsWithCellFactory(:ObservableType)
    rx_itemsWithDataSource(:protocol<RxTableViewDataSourceType, UITableViewDataSource>)

    simplest example:

    let dataSource = Observable<[String]>.just(["first", "second", "third"])
    
    dataSource.bindTo(tableView.rx_itemsWithCellIdentifier("Cell")) { index, model, cell in
      cell.textLabel?.text = model
    }
    .addDisposableTo(disposeBag)

    [ Question:
    examples of when and how to use the other methods (withCellFactory, withDataSource)?
    ]

  • Why use RxDataSources vs default method ?
    The default method deals with very simple use cases.
    RxDataSources are required when the data is structured into different sections with potentially different item types.
    RxDataSources are required to perform animations on insert/modify/delete

    [ Question: is the above correct ? What did I miss ?]

  • How to use RxDataSources [no animations]
    1- Define a struct that conforms to the SectionModelType protocol (MySection)

    • Define Item, the type of items that the section will contain
    • Declare items property as an array of Item elements

    2- Create a dataSource object as an instance of either:

    • RxCollectionViewSectionedReloadDataSource

    • RxTableViewSectionedReloadDataSource

      and pass it MySection as generic type

    3- customize closures on the dataSource as needed:

    • configureCell
    • titleForHeaderInSection
    • titleForFooterInSection
    • etc

    4- Define actual data as an Observable stream of MySection objects

    5- Bind actual data to tableView with rx_itemsWithDataSource(dataSource)

    6- If needed, set delegate with `tableView.rx_setDelegate(self)``

    [ Question: is the above correct ? What did I miss ?]

  • How to use RxDataSources [with animations]
    Same as static sections, except MySection needs to conform to AnimatableSectionModelType
    and dataSource object needs to be an instance of either:

    • RxCollectionViewSectionedAnimatedDataSource
    • RxTableViewSectionedAnimatedDataSource

    [ Question: is the above correct ? What did I miss ?]

from rxdatasources.

kzaher avatar kzaher commented on May 13, 2024

Hi @plm75 ,

everything you've said is correct.

rx_itemsWithCellIdentifier(:String)
rx_itemsWithCellIdentifier(:String:Cell.Type)
rx_itemsWithCellFactory(:ObservableType)

... are just conveniences for rx_itemsWithDataSource(:protocol<RxTableViewDataSourceType, UITableViewDataSource>)

I think we can improve the docs in both the main repo and this repo. Feel free to create a PR with that FAQ, or I'll create it in a couple of days.

from rxdatasources.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.