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

RFC: Add section property to IGListSectionController #609

Closed
amonshiz opened this issue Apr 2, 2017 · 12 comments
Closed

RFC: Add section property to IGListSectionController #609

amonshiz opened this issue Apr 2, 2017 · 12 comments
Assignees
Milestone

Comments

@amonshiz
Copy link
Contributor

amonshiz commented Apr 2, 2017

IGListKit should remove the -[IGListCollectionContext sectionForSectionController:] method from IGListCollectionContext and replace it with a section property on IGListSectionController.

Reasons

  • sectionForSectionController: has nothing to do with the collection displaying the section/list. This method alone requires that the IGListAdapter be the collectionContext object.
  • A section controller's actual section index cannot change without the IGListAdapter knowing, and at that point it would be a new section controller anyhow.
  • The property allows the collectionContext object to really be anything and not something that owns a mapping from section controller to an index.

The reasons that this method was originally added are all solved by adding a section property and as mentioned, that property is known at creation time.

Options

  • Add this as a property to the init method of IGListSectionController
  • Add this as @property (nonatomic, readwrite, assign) NSInteger index;

The init option is great because it means the property can be readonly, but it does mean that all subclasses have to be careful to include the property also.

The readwrite property is nice because then the IGListKit infra can own setting it. The downside is everyone knows that property can be written to. Maybe this is declared in IGListSectionController.h as readonly and in IGListSectionControllerInternal.h it is redeclared as readwrite?

Context

Speaking with @rnystrom in person about ways to break up implicit dependencies on UICollectionView and this method stood out as one that could be culled and would easily break up a hidden dependency on IGListAdapter.

@jessesquires
Copy link
Contributor

jessesquires commented Apr 3, 2017

Makes sense to me.

Maybe this is declared in IGListSectionController.h as readonly and in IGListSectionControllerInternal.h it is redeclared as readwrite?

Yep. This is what we already do for .isFirstSection and .isLastSection

I would say we definitely don't want this in init since clients could then override the section, or simply make mistakes calling super

@jessesquires jessesquires added this to the 3.0.0 milestone Apr 3, 2017
@jessesquires
Copy link
Contributor

Let's do this in 3.0

@rnystrom
Copy link
Contributor

rnystrom commented Apr 3, 2017

On board w/ this, ++ 3.0

@amonshiz you wanna take this on?

@amonshiz
Copy link
Contributor Author

Will do. Finally back from a pretty crazy week. Gonna start this week and should have PR pretty quickly.

@Adlai-Holler
Copy link
Contributor

Adlai-Holler commented Apr 18, 2017

How would this handle updating the index of all section controllers, if I inserted a section at index 0?

If it's a matter of convenience, then we should make the property readonly and implement it under-the-hood by calling [self.collectionContext sectionForSectionController:]. That way we never get stale data.

@jessesquires
Copy link
Contributor

^^ I assumed that's always what this was about, just a convenience wrapper

@amonshiz
Copy link
Contributor Author

The overall goal was to remove sectionForSectionController: from IGListCollectionContext in order to clean up the protocol to be only methods that go through to the backing list view. With that goal, the sectionForSectionController: method doesn't fit because it was going through to the sectionMap property of IGListAdapter which is not necessarily something that would be present on all IGListCollectionContext conforming objects that handle the presentation of a list.

@Adlai-Holler
Copy link
Contributor

How would this handle updating the index of all section controllers, if I inserted a section at index 0?

@amonshiz
Copy link
Contributor Author

amonshiz commented Apr 18, 2017

How would this handle updating the index of all section controllers, if I inserted a section at index 0?

In a similar fashion to isFirstSection and isLastSection , but instead use the map to determine the section index right before calling didUpdateToItem:.

@Adlai-Holler
Copy link
Contributor

Adlai-Holler commented Apr 18, 2017

But if the object wasn't updated, then we wouldn't visit the section controller in that for loop.

@Adlai-Holler
Copy link
Contributor

You could set the section index right up there where you set isFirstSection by adding a counting variable for the for-loop.

@amonshiz
Copy link
Contributor Author

amonshiz commented May 1, 2017

just to follow back up with this, i kind of melded both suggestions: move setting the isFirstSection and isLastSection into the IGListSectionMap object's update method since it already has all the context, and then within the iteration during the update set the sectionIndex. this effectively unifies the location as @Adlai-Holler suggested and removes the necessity for an extra indexing variable which could theoretically get out of sync with the canonical mapping.

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

Successfully merging a pull request may close this issue.

4 participants