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

MediaMonitor does not merge aliases as promised by the API #785

Closed
@simeyla

Description

@simeyla

Bug Report

What is the expected behavior?

MediaMonitor.observe should return a subscription to MediaChange items with alias filled in

What is the current behavior?

Alias is only filled in if an alias is passed into observe(alias?: string) - in which case you already know what the alias is.

What are the steps to reproduce?

  • Inject MediaMonitor

  • Subscribe to events

  • Monitor the console output

      mm.observe().subscribe(e => {
          console.log('MediaMonitor event: ', e);
      });
    

It is also trivial to see based on the source that the alias won't be added if no valid is provided for alias in observe(alias?: string)

What is the use-case or motivation for changing an existing behavior?

The documentation tells me that it is the MediaMonitor that 'injects alias information into each raw MediaChange event'. It is useful to know the alias.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

All

Is there anything else we should know?

The documentation also says

If specific breakpoint is observed, only return activated events

But this doesn't seem to be accounted for by the current implementation:


  observe(alias?: string): Observable<MediaChange> {
    let bp = this._breakpoints.findByAlias(alias || '') ||
      this._breakpoints.findByQuery(alias || '');
    let hasAlias = (change: MediaChange) => (bp ? change.mqAlias !== '' : true);
    // Note: the raw MediaChange events [from MatchMedia] do not contain important alias information
    let media$ = this._matchMedia.observe(bp ? bp.mediaQuery : alias);
    return media$.pipe(
      map(change => mergeAlias(change, bp)),
      filter(hasAlias)
    );
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions