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

Initial value of ObservableMedia not received #245

Closed
erikkolo opened this issue Apr 4, 2017 · 9 comments · Fixed by #313
Closed

Initial value of ObservableMedia not received #245

erikkolo opened this issue Apr 4, 2017 · 9 comments · Fixed by #313
Assignees
Labels
has pr A PR has been created to address this issue P0 Critical issue that needs to be resolved immediately
Milestone

Comments

@erikkolo
Copy link

erikkolo commented Apr 4, 2017

If I subscribe to ObservableMedia, the first (initial) value ist not received.
plunker.

The plunker example never receives the first value. In my own app, I get this first value in "xs" and "sm" size. If my browser windows is larger (gt-sm) at the time of loading the app (or refreshing), I do not get the first value.

@intellix
Copy link

intellix commented Apr 4, 2017

Dupe: #240

@rolandjitsu
Copy link

#240 was closed despite the fact that this is an issue that more than one user is experiencing.

@rolandjitsu
Copy link

I also think I know what the issue is (or might be). Right now, I'm subscribing to the ObservableMedia in a ngOnInit() block, whereas if I subscribe to it in a constructor it seems to be triggered. So I wonder if the ObservableMedia acts as a Subject or BehaviorSubject?

The behaviour I'm experiencing leads to the conclusion it's probably not a BehaviorSubject, but it should be. As a user, when I subscribe to it, I'd expect to get the last registered value.

I haven't looked at the actual implementation, but I guess this might be the reason why some users don't see a value on subscribe, or at least that's why I don't.

@karser
Copy link

karser commented Apr 20, 2017

As a possible workaround I created an intermediary service that keeps MediaChange value in a ReplaySubject and it's initialized in AppComponent. So you can subscribe on MediaReplay.subject$ within your app.

export class MediaReplay {
    private _media$: ReplaySubject<MediaChange> = new ReplaySubject(1);

    constructor(media:ObservableMedia) {
        media.asObservable()
            .subscribe(res => this._media$.next(res), err => this._media$.error(err), () => this._media$.complete());
    }

    get media$(): Observable<MediaChange> {
        return this._media$.asObservable();
    }
}

export class AppComponent {
    constructor(mediaReplay: MediaReplay) {} //so it's initialized when the app starts
}

@jurafa
Copy link

jurafa commented Jun 7, 2017

IMHO this is a quite serious issue. It makes the JavaScript API unreliable. Are the developers going to fix this anytime soon?

@ThomasBurleson ThomasBurleson added P0 Critical issue that needs to be resolved immediately in-progress labels Jun 7, 2017
@ThomasBurleson ThomasBurleson self-assigned this Jun 7, 2017
@ThomasBurleson ThomasBurleson added this to the v2.0.0-beta.9 milestone Jun 7, 2017
@ThomasBurleson
Copy link
Contributor

This will be fixed by next week and included in the upcoming Beta.9 Release.

@ThomasBurleson
Copy link
Contributor

ObservableMedia uses BehaviorSubject internally; however it only reports breakpoint activations. This issue 245 is a bug. We are investigating.

@ThomasBurleson
Copy link
Contributor

Will be fixed with PR #313.

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

@ThomasBurleson ThomasBurleson added has pr A PR has been created to address this issue and removed in-progress labels Jun 10, 2017
ThomasBurleson added a commit that referenced this issue 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.

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

Fixes #245, #275.
ThomasBurleson added a commit that referenced this issue Jun 12, 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

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

Fixes #245, #275, #303
ThomasBurleson added a commit that referenced this issue Jun 12, 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

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

Fixes #245, #275, #303
ThomasBurleson added a commit that referenced this issue Jun 12, 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

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

Fixes #245, #275, #303
ThomasBurleson added a commit that referenced this issue Jun 13, 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

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

Fixes #245, #275, #303
ThomasBurleson added a commit that referenced this issue Jun 13, 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

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

Fixes #245, #275, #303
@kara kara closed this as completed in #313 Jun 13, 2017
@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 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has pr A PR has been created to address this issue P0 Critical issue that needs to be resolved immediately
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants