Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove need to extend UntilDestroyedMixin

Oliver Günther19bdf77f783d
diff --git a/frontend/src/app/core/state/effects/effect-handler.decorator.ts b/frontend/src/app/core/state/effects/effect-handler.decorator.ts
index ee2e028265e..bb45c19458f 100644
--- a/frontend/src/app/core/state/effects/effect-handler.decorator.ts
+++ b/frontend/src/app/core/state/effects/effect-handler.decorator.ts
@@ -1,11 +1,9 @@
import 'reflect-metadata';
import { debugLog } from 'core-app/shared/helpers/debug_output';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { untilComponentDestroyed } from '@w11k/ngx-componentdestroyed';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
import { ActionCreator } from 'ts-action/action';
-import { Injector } from '@angular/core';
import { Action } from 'ts-action';
+import { takeWhile } from 'rxjs/operators';
/**
* This interface specifies a constraint on the classes that can
@@ -13,8 +11,9 @@ import { Action } from 'ts-action';
*
* As we depend on the ActionsService, we need that as a public property.
*/
-export interface EffectClass extends UntilDestroyedMixin {
+export interface EffectClass {
actions$:ActionsService;
+ ngOnDestroy?():void;
}
const EffectHandlers = Symbol('EffectHandlers');
@@ -40,8 +39,9 @@ type EffectHandlerItem = { callback:(action:Action) => void, action:ActionCreato
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(constructor:T):any {
return class extends constructor {
- /* The class decorator requires any[] args to it to function */
+ private serviceDestroyed = false;
+ /* The class decorator requires any[] args to it to function */
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
constructor(...args:any[]) {
super(...args);
@@ -57,7 +57,9 @@ export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(cons
// Subscribe to the specified action for the duration of this service's life.
this.actions$
.ofType(item.action)
- .pipe(untilComponentDestroyed(this))
+ .pipe(
+ takeWhile(() => !this.serviceDestroyed),
+ )
.subscribe((instance) => {
// Wrap callback in a try-catch to avoid completing the subscription.
try {
@@ -70,6 +72,13 @@ export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(cons
});
}
}
+
+ ngOnDestroy():void {
+ this.serviceDestroyed = true;
+ if (super.ngOnDestroy) {
+ super.ngOnDestroy();
+ }
+ }
};
}
diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
index ac93a9ce40f..a143b94ae3c 100644
--- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
@@ -25,23 +25,28 @@ import {
EffectCallback,
EffectHandler,
} from 'core-app/core/state/effects/effect-handler.decorator';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
@EffectHandler
@Injectable()
-export class InAppNotificationsService extends UntilDestroyedMixin {
+export class InAppNotificationsService {
protected store = new InAppNotificationsStore();
readonly query = new InAppNotificationsQuery(this.store);
+ private get notificationsPath():string {
+ return this
+ .apiV3Service
+ .notifications
+ .path;
+ }
+
constructor(
readonly actions$:ActionsService,
private http:HttpClient,
private apiV3Service:APIV3Service,
private notifications:NotificationsService,
) {
- super();
}
fetchNotifications(params:Apiv3ListParameters):Observable<IHALCollection<InAppNotification>> {
@@ -119,13 +124,6 @@ export class InAppNotificationsService extends UntilDestroyedMixin {
);
}
- private get notificationsPath():string {
- return this
- .apiV3Service
- .notifications
- .path;
- }
-
/**
* Mark the given notification IDs as read through the API.
*/
diff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
index 9df19c9649a..fef96084f7d 100644
--- a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
@@ -13,12 +13,11 @@ import {
EffectHandler,
} from 'core-app/core/state/effects/effect-handler.decorator';
import { notificationsMarkedRead } from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
@Injectable()
@EffectHandler
-export class IanBellService extends UntilDestroyedMixin {
+export class IanBellService {
readonly id = 'ian-center';
readonly store = new IanBellStore();
@@ -31,7 +30,6 @@ export class IanBellService extends UntilDestroyedMixin {
readonly actions$:ActionsService,
readonly ianService:InAppNotificationsService,
) {
- super();
}
fetchUnread():Observable<number> {
diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
index fd704ccb14f..ae3be1d159f 100644
--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
@@ -21,7 +21,6 @@ import {
EffectCallback,
EffectHandler,
} from 'core-app/core/state/effects/effect-handler.decorator';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
@@ -31,7 +30,7 @@ import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';
@Injectable()
@EffectHandler
-export class IanCenterService extends UntilDestroyedMixin {
+export class IanCenterService {
readonly id = 'ian-center';
readonly store = new IanCenterStore();
@@ -44,7 +43,6 @@ export class IanCenterService extends UntilDestroyedMixin {
readonly actions$:ActionsService,
readonly apiV3Service:APIV3Service,
) {
- super();
}
setFacet(facet:InAppNotificationFacet):void {
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts
index 8bcb0a0ec03..68b98b03f72 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts
@@ -10,7 +10,6 @@ import {
notificationsMarkedRead,
} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import {
EffectCallback,
EffectHandler,
@@ -18,7 +17,7 @@ import {
@EffectHandler
@Injectable()
-export class WpSingleViewService extends UntilDestroyedMixin {
+export class WpSingleViewService {
id = 'WorkPackage Activity Store';
protected store = new WpSingleViewStore();
@@ -29,7 +28,6 @@ export class WpSingleViewService extends UntilDestroyedMixin {
readonly actions$:ActionsService,
private ianService:InAppNotificationsService,
) {
- super();
}
setFilters(workPackageId:string):void {