Skip to content

Commit

Permalink
Fix Luigi Context Observable running outside of Angular Zone (SAP#2403)
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeKay authored Dec 9, 2021
1 parent 2d4e9e7 commit d2c2081
Showing 1 changed file with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import { Injectable } from '@angular/core';
import { Injectable, NgZone } from '@angular/core';
import { ReplaySubject, Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import {
Context,
addInitListener,
addContextUpdateListener
} from '@luigi-project/client';
import {
IContextMessage,
ILuigiContextTypes,
LuigiContextService
} from './luigi-context-service';
import { Context, addInitListener, addContextUpdateListener } from '@luigi-project/client';
import { IContextMessage, ILuigiContextTypes, LuigiContextService } from './luigi-context-service';

@Injectable({
providedIn: 'root'
})
export class LuigiContextServiceImpl implements LuigiContextService {
private subject: ReplaySubject<IContextMessage> = new ReplaySubject<
IContextMessage
>(1);
private subject: ReplaySubject<IContextMessage> = new ReplaySubject<IContextMessage>(1);
private currentContext: IContextMessage = (null as unknown) as IContextMessage;

constructor() {
constructor(private zone: NgZone) {
addInitListener(initContext => {
this.addListener(ILuigiContextTypes.INIT, initContext);
});
Expand Down Expand Up @@ -62,8 +52,10 @@ export class LuigiContextServiceImpl implements LuigiContextService {
* Set current context
*/
protected setContext(obj: IContextMessage): void {
this.currentContext = obj;
this.subject.next(obj);
this.zone.run(() => {
this.currentContext = obj;
this.subject.next(obj);
});
}

addListener(contextType: ILuigiContextTypes, context: Context): void {
Expand Down

0 comments on commit d2c2081

Please sign in to comment.