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

feat(viewport-ruler): add common window resize handler #6680

Merged
merged 1 commit into from
Sep 12, 2017

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Aug 28, 2017

Adds the change method to the ViewportRuler, allowing for components to hook up to a common window resize handler.

BREAKING CHANGE: Previously the ScrollDispatcher.scrolled subscription would react both on scroll events and on window resize events. Now it only reacts to scroll events. To react to resize events, subscribe to the ViewportRuler.change() stream.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 28, 2017
merge<Event>(
fromEvent(window, 'resize'),
fromEvent(window, 'orientationchange')
).subscribe(event => this._changed.next(event.type));
Copy link
Member

Choose a reason for hiding this comment

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

Why subscribe and emit instead of exposing this Observable?

@@ -20,9 +28,22 @@ export class ViewportRuler {
/** Cached document client rectangle. */
private _documentRect?: ClientRect;

constructor(scrollDispatcher: ScrollDispatcher) {
/** Stream of viewport change events. */
private _changed = new Subject<string>();
Copy link
Member

Choose a reason for hiding this comment

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

Is the difference between resize and orientationchange useful here? If we make it void we can change it to a more robust object later without it being a breaking change

Copy link
Member Author

Choose a reason for hiding this comment

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

The intention was to let people react differently depending on the event, but we can always change it if somebody asks for it.

// Subscribe to scroll and resize events and update the document rectangle on changes.
scrollDispatcher.scrolled(0, () => this._cacheViewportGeometry());
this.change().subscribe(() => this._cacheViewportGeometry());
Copy link
Member

Choose a reason for hiding this comment

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

Need to unsubscribe in ngOnDestroy?

@crisbeto
Copy link
Member Author

Addressed the feedback @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM- can you amend your commit to include a breaking change message?

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Aug 31, 2017
@jelbourn jelbourn added the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Sep 1, 2017
@jelbourn
Copy link
Member

jelbourn commented Sep 1, 2017

@crisbeto

src/cdk/scrolling/viewport-ruler.ts(40,7): error TS2322: Type 'Observable<Event>' is not assignable to type 'Subject<void>'.
  Property 'observers' is missing in type 'Observable<Event>'.

@crisbeto
Copy link
Member Author

crisbeto commented Sep 1, 2017

Fixed @jelbourn.

@crisbeto crisbeto removed the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Sep 1, 2017
@mmalerba
Copy link
Contributor

@crisbeto looks like prerender CI task is failing

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Sep 12, 2017
Adds the `change` method to the `ViewportRuler`, allowing for components to hook up to a common window resize handler.

BREAKING CHANGE: Previously the `ScrollDispatcher.scrolled` subscription would react both on scroll events and on window resize events. Now it only reacts to scroll events. To react to resize events, subscribe to the `ViewportRuler.change()` stream.
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Sep 12, 2017
@crisbeto
Copy link
Member Author

Sorted out the prerender failure.

@mmalerba mmalerba merged commit 881630f into angular:master Sep 12, 2017
mmalerba added a commit that referenced this pull request Sep 13, 2017
mmalerba added a commit that referenced this pull request Sep 13, 2017
* Revert "Revert "fix(menu): multiple close events for a single close" (#7036)"

This reverts commit dcfe515.

* Revert "feat(datepicker): Add Moment.js adapter (#6860)"

This reverts commit 9545427.

* Revert "fix(menu): multiple close events for a single close (#6961)"

This reverts commit 1cccd4b.

* Revert "fix(menu): nested trigger staying highlighted after click (#6853)"

This reverts commit 04bf3d1.

* Revert "feat(viewport-ruler): add common window resize handler (#6680)"

This reverts commit 881630f.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Sep 15, 2017
Adds the `change` method to the `ViewportRuler`, allowing for components to hook up to a common window resize handler.

BREAKING CHANGE: Previously the `ScrollDispatcher.scrolled` subscription would react both on scroll events and on window resize events. Now it only reacts to scroll events. To react to resize events, subscribe to the `ViewportRuler.change()` stream.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Sep 15, 2017
…lar#7054)

* Revert "Revert "fix(menu): multiple close events for a single close" (angular#7036)"

This reverts commit dcfe515.

* Revert "feat(datepicker): Add Moment.js adapter (angular#6860)"

This reverts commit 9545427.

* Revert "fix(menu): multiple close events for a single close (angular#6961)"

This reverts commit 1cccd4b.

* Revert "fix(menu): nested trigger staying highlighted after click (angular#6853)"

This reverts commit 04bf3d1.

* Revert "feat(viewport-ruler): add common window resize handler (angular#6680)"

This reverts commit 881630f.
@rolandjitsu
Copy link

Is this public? And it's listed in beta 11, but I cannot seem to find the .change() method.

@willshowell
Copy link
Contributor

@rolandjitsu it was reverted and reopened #7113. I think that is an oversight in the changelog

@rolandjitsu
Copy link

@willshowell thanks, I'll keep an eye on that.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants