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

Fix for #348 - IGListStackedSectionController's children need to know numberOrItems before didUpdate is called #390

Closed
wants to merge 15 commits into from

Conversation

jeffbailey
Copy link
Contributor

@jeffbailey jeffbailey commented Jan 6, 2017

Changes in this pull request

The reloadData method in IGListStackedSectionController was being called too soon. It was moved from the constructor to the didUpdateToObject method. Tests were updated to reflect the change.

Pull request checklist

  • All tests pass. Demo project builds and runs.
  • I added tests, an experiment, or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • I have reviewed the contributing guide

@jessesquires jessesquires added this to the 2.2.0 milestone Jan 6, 2017
@jessesquires
Copy link
Contributor

Nice. Thanks @jeffbailey ! 💯

Copy link
Contributor

@rnystrom rnystrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woot, thanks @jeffbailey!

If we change all the tests to use batch updates we'll need to add an expectation so the asserts actually trigger.


XCTAssertEqual([stack numberOfItems], 6);
[stack performBatchAnimated:false updates:^{} completion:^(BOOL finished) {
XCTAssertEqual([stack numberOfItems], 6);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests use IGListAdapterUpdater which asynchronously collect updates during a runloop turn, so this assert wont execute w/out an expectation+wait setup. Here's an example. Same goes for all the asserts in this change that got moved into the completion block.

A really easy way to check that the block executes is:

__block BOOL executed = NO;
[adapter performUpdates:^{
  executed = YES;
}];
XCTAssertTrue(executed);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it should have dawned on me I made the changed tests asynchronous :). The issue with these particular tests is that they don't follow the normal pattern of the other tests because they don't use the adapter. I don't know without digging further why they don't use the adapter or if they can be changed easily. Also, my proposed solution wouldn't work anyway since the completion block never gets called because there's no CollectionContext set on the section controller. One easy way to use to fix the broken tests would be to use the following pattern:

- (void)test_whenInitializingStack_thatNumberOfItemsMatches {
    IGListTestSection *section1 = [[IGListTestSection alloc] init];
    section1.items = 2;
    IGListTestSection *section2 = [[IGListTestSection alloc] init];
    section2.items = 3;
    IGListTestSection *section3 = [[IGListTestSection alloc] init];
    section3.items = 0;
    IGListTestSection *section4 = [[IGListTestSection alloc] init];
    section4.items = 1;

    IGListStackedSectionController *stack = [[IGListStackedSectionController alloc] initWithSectionControllers:@[section1, section2, section3, section4]];
    [stack performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:TRUE];
    XCTAssertEqual([stack numberOfItems], 6);
}

Basically just call the private reloadData method using performSelector. Let me know what you think the best way to proceed would be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnystrom - let me know what you think about just using:
[stack performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:TRUE];
to get the unit tests working.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffbailey oh! I missed that. Good call.

Instead of doing the performSelector hack, how about we expose reloadData in the internal header and call it directly?

https://github.com/Instagram/IGListKit/blob/master/Source/Internal/IGListStackedSectionControllerInternal.h

The header is already imported to the test.

@coveralls
Copy link

coveralls commented Jan 6, 2017

Coverage Status

Coverage decreased (-0.0007%) to 97.978% when pulling 1d4de97 on jeffbailey:master into c19379e on Instagram:master.

@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

1 similar comment
@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

Copy link
Contributor

@rnystrom rnystrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we need to add a CHANGELOG entry!


XCTAssertEqual([stack numberOfItems], 6);
[stack performBatchAnimated:false updates:^{} completion:^(BOOL finished) {
XCTAssertEqual([stack numberOfItems], 6);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffbailey oh! I missed that. Good call.

Instead of doing the performSelector hack, how about we expose reloadData in the internal header and call it directly?

https://github.com/Instagram/IGListKit/blob/master/Source/Internal/IGListStackedSectionControllerInternal.h

The header is already imported to the test.

@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

1 similar comment
@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

@jessesquires
Copy link
Contributor

Friendly ping ✨ any updates here?

@rnystrom if this is good, we can follow up with a changelog entry separately.

@jeffbailey
Copy link
Contributor Author

The internal header is a great option. I'll get this done today. Thanks @rnystrom

@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0007%) to 98.064% when pulling fbfebf9 on jeffbailey:master into dd3b9ed on Instagram:master.

@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

@rnystrom
Copy link
Contributor

@jeffbailey looks great! Very last thing is a quick note in the CHANGELOG.md file about this fix and we're g2g. It should go under the 2.2.0 list.

@facebook-github-bot
Copy link
Contributor

@jeffbailey updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

jessesquires pushed a commit that referenced this pull request Jan 15, 2017
… numberOrItems before didUpdate is called

Summary:
The reloadData method in IGListStackedSectionController was being called too soon.  It was moved from the constructor to the `didUpdateToObject` method.  Tests were updated to reflect the change.

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes #390

Differential Revision: D4419751

Pulled By: rnystrom

fbshipit-source-id: 7c812d306b23dd251c160425873930eb8022b1a5
@jessesquires jessesquires modified the milestones: 2.2.0, 3.0.0 Feb 23, 2017
marciomeschini pushed a commit to marciomeschini/IGListKit that referenced this pull request May 4, 2017
…d to know numberOrItems before didUpdate is called

Summary:
The reloadData method in IGListStackedSectionController was being called too soon.  It was moved from the constructor to the `didUpdateToObject` method.  Tests were updated to reflect the change.

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes Instagram#390

Differential Revision: D4419751

Pulled By: rnystrom

fbshipit-source-id: 7c812d306b23dd251c160425873930eb8022b1a5

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

Successfully merging this pull request may close these issues.

5 participants