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(ObservableMedia): startup should propagate lastReplay value properly #313

Merged
merged 1 commit into from
Jun 13, 2017

Conversation

ThomasBurleson
Copy link
Contributor

@ThomasBurleson ThomasBurleson commented Jun 10, 2017

ObservableMedia only dispatches notifications for activated, non-overlapping breakpoints.
If the MatchMedia lastReplay value is an overlapping breakpoint
(e.g. lt-md, gt-lg) then that value will be filtered by ObservableMedia
and not be emitted to subscribers.

  • MatchMedia breakpoints registration was not correct
    • overlapping breakpoints were registered in the wrong order
    • non-overlapping breakpoints should be registered last; so the BehaviorSubject's last replay value should be an non-overlapping breakpoint range.
  • Optimize stylesheet injection to group n mediaQuerys in a single stylesheet

    screen shot 2017-06-12 at 1 44 43 pm

Fixes #245, #275, #303.

See working plunker: https://plnkr.co/edit/yylQr2IdbGy2Yr00srrN?p=preview

@@ -31,7 +31,9 @@ export class MediaQueryStatus implements OnDestroy {
private _watcher : Subscription;
activeMediaQuery : string;

constructor(media$ : ObservableMedia) { this.watchMediaQueries(media$); }
constructor(media$ : ObservableMedia) {
this.watchMediaQueries(media$);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the $ for in the variable name? If it's for private but cannot be marked as such for Angular reasons, we use an underscore to preface the variable

Copy link
Contributor Author

@ThomasBurleson ThomasBurleson Jun 13, 2017

Choose a reason for hiding this comment

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

The $ suffix is a community convention to indicate a variable reference that is actually an observable to future value(S)... originally seen in use by Andre Stalz (2 yrs ago).

I believe this is used consistently throughout the library.

@@ -30,6 +30,20 @@ export class BreakPointRegistry {
}

/**
* Accessor to sorted list used for
Copy link
Contributor

Choose a reason for hiding this comment

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

Can combine the two lines into one

Copy link
Contributor Author

@ThomasBurleson ThomasBurleson Jun 13, 2017

Choose a reason for hiding this comment

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

So I do not mind these comments. It is my hope however that reviewers will focus mostly on content and less on format.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tried to give focus to both equally :) My understanding is that we'll want to review this library with the same rigor we give to Material, and we're often strict about even the small things just to maintain quality (even in comments). Apologies if it seems pedantic, just wanting to make sure I'm fair to all PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. Thanks for helping review these. Much appreciated.

* so the non-overlaps will trigger the MatchMedia:BehaviorSubject last!
* And the largest, non-overlap, matching breakpoint should be the lastReplay value
*/
get sortedItems(): BreakPoint[ ] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove space between [ ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k

* And the largest, non-overlap, matching breakpoint should be the lastReplay value
*/
get sortedItems(): BreakPoint[ ] {
let overlaps = this._registry.filter(it=>it.overlapping === true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add spaces around =>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Will fix with style Linter tool.

let current: MediaChange, activated;
let query1 = "screen and (min-width: 610px) and (max-width: 620px)";
let query2 = "(min-width: 730px) and (max-width: 950px)";

matchMedia.registerQuery(query1);
matchMedia.registerQuery(query2);
matchMedia.registerQuery([query1,query2]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add space after ,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k.

this._source.next(change);
});
};
registerQuery(mediaQuery: string | Array<string>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use string[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k.

ObservableMedia only dispatches notifications for activated, non-overlapping breakpoints.
If the MatchMedia lastReplay value is an *overlapping* breakpoint
(e.g. `lt-md`, `gt-lg`) then that value will be filtered by ObservableMedia
and not be emitted to subscribers.

* MatchMedia breakpoints registration was not correct
  *  overlapping breakpoints were registered in the wrong order
  * non-overlapping breakpoints should be registered last; so the BehaviorSubject's last replay value should be an non-overlapping breakpoint range.
* Optimize stylesheet injection to group `n` mediaQuerys in a single stylesheet

> See working plunker:  https://plnkr.co/edit/yylQr2IdbGy2Yr00srrN?p=preview

Fixes #245, #275, #303
@ThomasBurleson
Copy link
Contributor Author

ThomasBurleson commented Jun 13, 2017

Updated. Thx @andrewseguin.

@andrewseguin andrewseguin added pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for the caretaker to presubmit and merge and removed pr: needs review labels Jun 13, 2017
@kara kara added pr: needs presubmit pr: merge ready This PR is ready for the caretaker to presubmit and merge and removed pr: merge ready This PR is ready for the caretaker to presubmit and merge pr: needs presubmit labels Jun 13, 2017
@kara kara merged commit 00ac57a into master Jun 13, 2017
@ThomasBurleson ThomasBurleson deleted the thomas/fix-issue-245 branch August 7, 2017 22:36
@bogacg
Copy link

bogacg commented Dec 12, 2017

Please re-check this issue. I think we still have problem when used with --prod flag with latest Angular-CLI (1.6)

@ThomasBurleson
Copy link
Contributor Author

ThomasBurleson commented Dec 14, 2017

@bogacg - Would you mind opening a new issue and perhaps provide a StackBlitz or zip that demonstrates this issue ?

Note the latest source/nightly builds have been upgraded to Angular 5.1 and RxJS 5.5.

@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for the caretaker to presubmit and merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial value of ObservableMedia not received
6 participants