Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

fix(core): improve use of breakpoint priorities #946

Closed
wants to merge 1 commit into from

Conversation

ThomasBurleson
Copy link
Contributor

Use breakpoint priority as the only sorting/scanning mechanism;
used to ensure correct MediaChange event notifications.

  • prioritize breakpoints: non-overlaps hightest, lt- lowest
  • consistently sort breakpoints ascending by priority
    • highest priority === smallest range
    • remove hackery with reverse(), etc.
  • memoize BreakPointRegistry findBy lookups
  • fix MatchMedia::observe() to support lazy breakpoint registration
  • fix fragile logic in MediaMarshaller
    • fix breakpoint registration usage
    • clarify update/clear builder function callbacks
  • fix MediaObserver breakpoint registration usage

@googlebot
Copy link
Collaborator

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot googlebot added the cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ label Dec 20, 2018
@ThomasBurleson
Copy link
Contributor Author

This includes the PR to remove deprecated APIs; to ensure optimizations work as desired.

Copy link
Member

@CaerusKaru CaerusKaru left a comment

Choose a reason for hiding this comment

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

This is stellar work; I'm especially amazed that more tests didn't need to be patched as a result. Just some minor cosmetic changes; functionally everything looks great!

.firebase/hosting.ZGlzdC9wYWNrYWdlcy9kZW1vLWFwcA.cache Outdated Show resolved Hide resolved
src/lib/core/breakpoints/break-point-registry.ts Outdated Show resolved Hide resolved
src/lib/core/breakpoints/break-point-registry.ts Outdated Show resolved Hide resolved
src/lib/core/breakpoints/breakpoint-tools.ts Outdated Show resolved Hide resolved
src/lib/server/server-provider.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
@ThomasBurleson ThomasBurleson force-pushed the thomas/fix-bp-priority branch 2 times, most recently from d4c9619 to 6e66ab6 Compare December 20, 2018 19:14
Copy link
Member

@CaerusKaru CaerusKaru left a comment

Choose a reason for hiding this comment

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

Some things missed the first time around. If there's a reason you're keeping them as-is, please provide.

src/lib/core/breakpoints/break-point-registry.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
src/lib/core/match-media/match-media.ts Outdated Show resolved Hide resolved
@@ -99,7 +118,7 @@ export class MatchMedia {
* Private global registry for all dynamically-created, injected style tags
* @see prepare(query)
*/
const ALL_STYLES: {[key: string]: any} = {};
const ALL_STYLES: { [key: string]: any } = {};
Copy link
Member

Choose a reason for hiding this comment

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

Still no spaces (per style guide)

src/lib/core/media-marshaller/media-marshaller.ts Outdated Show resolved Hide resolved
if (builder) {
builder();
const clearFn: ClearCallback = builders.get(key) as ClearCallback;
if (!!clearFn) {
Copy link
Member

Choose a reason for hiding this comment

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

Again, if(clearFn !== undefined)

if (builder) {
builder(value);
const updateFn: UpdateCallback = builders.get(key) as UpdateCallback;
if (!!updateFn) {
Copy link
Member

Choose a reason for hiding this comment

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

Again, if (updateFn !== undefined)

private _registerBreakPoints() {
const queries = this.breakpoints.sortedItems.map(bp => bp.mediaQuery);
this.mediaWatcher.registerQuery(queries);
private watchActivations() {
Copy link
Member

Choose a reason for hiding this comment

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

Again, add return type

@CaerusKaru
Copy link
Member

This is also supposed to fix #648 and #426, please add an explicit test case for the former (the latter may be trickier).

@CaerusKaru CaerusKaru added this to the 7.0.0-beta.23 milestone Dec 21, 2018
@CaerusKaru CaerusKaru self-assigned this Dec 21, 2018
let nonOverlaps = this._registry.filter(it => it.overlapping !== true);

return [...overlaps, ...nonOverlaps];
constructor(@Inject(BREAKPOINTS) list: BreakPoint[]) {
Copy link
Member

Choose a reason for hiding this comment

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

Here's a thought: the items remain static, so instead of memoizing, why not just prime it at startup by creating two maps on init, one for aliases, one for mediaqueries?

Use breakpoint priority as the only sorting/scanning mechanism;
used to ensure correct MediaChange event notifications.

* prioritize breakpoints: non-overlaps hightest, lt- lowest
  * consistently sort breakpoints ascending by priority
  * highest priority === smallest range
  * remove hackery with reverse(), etc.
* memoize BreakPointRegistry findBy lookups
* fix MatchMedia::observe() to support lazy breakpoint registration
* fix fragile logic in MediaMarshaller
* fix breakpoint registration usage
* clarify update/clear builder function callbacks
* fix MediaObserver breakpoint registration usage

Fixes #648, Fixes #426
@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ labels Dec 22, 2018
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants