Skip to content
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

_dataSource.numberOfItems(in: section) always return zero #3

Closed
steve21124 opened this issue Aug 20, 2017 · 7 comments
Closed

_dataSource.numberOfItems(in: section) always return zero #3

steve21124 opened this issue Aug 20, 2017 · 7 comments

Comments

@steve21124
Copy link

steve21124 commented Aug 20, 2017

Great library. thanks for sharing.
Not sure where I did the mistake. it always return zero when calling _dataSource.numberOfItems(in: section) . Basically, I am trying to see if DataSources will work without using RxSwift and RxCocoa. Since the demo only use (RxSwift and RxCocoa)

`
private lazy var _dataSource: DataSource = .init(adapter: .init(collectionView: self.collectionView))

private let section0 = Section(ModelA.self, isEqual: { $0.identity == $1.identity })

var section0Models: [ModelA] = [ModelA(identity: UUID().uuidString, title: String.randomEmoji())] {
    didSet {
        _dataSource.update(
            in: section0,
            items: section0Models,
            updateMode: .partial(animated: true),
            completion: {
                
        })
    }
}

    for _ in 0..<20 {
        _dataSource.add(section: section0)
    }
    for _ in 0..<20 {           
        section0Models.append(ModelA(identity: UUID().uuidString, title: String.randomEmoji()))
    }

// then calling this below always return zero. do you know why?
_dataSource.numberOfItems(in: 0)

`

@muukii
Copy link
Collaborator

muukii commented Aug 20, 2017

@steve21124
Thank you.
I think you should not add section 20 times.

@muukii
Copy link
Collaborator

muukii commented Aug 20, 2017

@steve21124
I've added validation.
94aba9b

Thank you!

@muukii
Copy link
Collaborator

muukii commented Aug 20, 2017

@steve21124
And also, I've renamed few classes.
Please, check this PR.
#2

@steve21124
Copy link
Author

Thank you for the help.
https://gist.github.com/steve21124/cf1a11e30b58e6957812fdbea583de01

I still have problem with this line
https://gist.github.com/steve21124/cf1a11e30b58e6957812fdbea583de01#file-viewcontroller-L48

It return zero items. Do you have simple example without using "RxSwift and RxCocoa" ?

@muukii
Copy link
Collaborator

muukii commented Aug 21, 2017

@steve21124
Hi, Thank you for sample code.

I've fixed your code. please check it.
https://gist.github.com/muukii/dac32876237c127cbfa4fc0257905686

And sorry.
Calling update will be throttled, therefore updating numberOfItems will be updated asynchronously.

You can get an actual count of data in update.completion closure.

@steve21124
Copy link
Author

steve21124 commented Aug 21, 2017

Thank you so much for the fixes. Now it make sense. It take a while to debug it. :)

With this sample code, I now know, it will work without using "RxSwift and RxCocoa" .

@steve21124
Copy link
Author

fyi: currently, i am planning to remove "import RxSwift, EasyPeasy, AsyncDisplayKit" dependencies of Component.swift the reason because I am using ios 11 beta 5 and these libraries is not compatible yet with swift 4.0. If you do have solution for it. feel free to share it. Thank you

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

No branches or pull requests

2 participants