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(carousel): change sildes on prev/next/select API calls with OnPush #2776

Merged

Conversation

maxokorokov
Copy link
Member

Regression introduced after marking carousel OnPush due to lack of tests. Now calling detectChanges() on interval and all public API actions.

Fixes #2766

@@ -202,6 +199,9 @@ export class NgbCarousel implements AfterContentChecked,
this._start$.next();
this.activeId = selectedSlide.id;
}

// we get here after the interval fires or any external API call like next(), prev() or select()
this._cd.detectChanges();

Choose a reason for hiding this comment

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

Shouldn't this be markForCheck? What would happen in a scenario where click on prev / next is calling prev / next on a carousel and is adding a new slide (ex. from ngFor). Would the content of a carousel be checked if we just call detect changes on the carousel itself?

Copy link
Member

Choose a reason for hiding this comment

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

I get your point, nonetheless, what we want to achieve here is to refresh right away. markForCheck would only refresh it on next CD, isn't it correct ?

Choose a reason for hiding this comment

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

markForCheck would only refresh it on next CD, isn't it correct ?

I would say: in the current CD (the one that would be run at the end of JS loop, before any rendering is done). So I believe that this is the behaviour we actually want.

We should add a test for the above scenario to be sure.

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

I would like to see a test where we add a new slide when prev/ next is triggered. I believe that we should be doing mark for check instead of detect changes, but we need to confirm this with a test.

Regression introduced after marking carousel OnPush due to lack of tests

Fixes ng-bootstrap#2766
@maxokorokov maxokorokov force-pushed the careousel/fix/manual-slide-change branch from 8dc1f68 to 14907a9 Compare October 11, 2018 09:32
@maxokorokov
Copy link
Member Author

maxokorokov commented Oct 11, 2018

@pkozlowski-opensource, sure shouldn't run CD synchronously right away, will change to markForCheck

Actually you're right, your example won't work with detectChanges, didn't get it at first. Added a test for it

@pkozlowski-opensource
Copy link
Member

LGTM. Feel free to merge when CI gets green.

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.

None yet

3 participants