-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
RFC: Remove item-level updates from IGListCollectionContext, require them done in batch updates #392
Comments
💯 |
Wow this is great! I just started learning IGListKit a couple days ago and was wondering how those two update APIs would play together. What would it mean for two section controllers to do something like this in the same run loop? Would the updates be coalesced and performed all in one batch? Tangential but related: if I wanted to build a fully data driven arch (~ #38) would something like this be appropriate? // Pseudocode
- (void)didUpdateToObject:(id)object {
self.model = object;
NSArray *oldItems = self.items;
self.items = [self.class itemsFromObject:object];
IGListDiff *diff = …;
[self.collectionContext applyDiff:diff inSectionController:self];
} Another tangential point, would |
Here the consumer of the API is alredy on the path down a slipperly slope of "unkowns errors so if you can help him "do the right thing" early on, this sounds like a good idea. |
Diff up internally to make this change! 🎉 |
It is way too easy to execute an item-level update out-of-sync with coalesced batch updates and break things. We've observed this in Instagram. Although rare, at our scale its still a measurable problem.
By item-level updates, I'm specifically talking about:
The Problem
The preferred way to use them is to batch update your state (e.g. w/e powers
numberOfItems
) and item changes:However I've seen lots of examples not-using the batch update block:
We even do this in one of the examples.
The problem w/ this is that if a batch update is in progress, you might update while the
UICollectionViewData
(private structure) is changing the state of theUICollectionView
. While this is all main-thread affined, the whole operation happens over multiple runloop turns, so it should be treated as an async operation (e.g. racing).Proposal
I propose we remove all of the item-update operations from
IGListCollectionContext
so they cannot be done w/out batch updates. Instead, we provide a newIGListBatchUpdateContext
object as a parameter to the update block that has all of the above batch update methods.So now your batch updates would look like:
Considerations
That way the design and compiler forces when we can update. The only thing we can't enforce is when the state changes happen. We can use documentation and examples to try get the message across, but there's nothing stopping someone from doing:
Maybe we could add some fancy asserting or something just before performBatchUpdates: that checks the data source's
numberOfSections
andnumberOfItemsInSection:
and throws if the data source and UICV are out of sync?That might be useful as its own thing. We could pinpoint which section controller is borked.
The text was updated successfully, but these errors were encountered: