From ac2006f6c926a382f8ddfd97e9fa3271a1a91cae Mon Sep 17 00:00:00 2001 From: "swapnil.verma" Date: Wed, 26 Jun 2024 11:51:47 +0530 Subject: [PATCH] Updated IsFeatureOff, IsFeatureOn and IsFlagsOverrideOn guards to be functional guards --- .../src/lib/guards/is-feature-off.guard.ts | 17 ++++++----------- .../src/lib/guards/is-feature-on.guard.ts | 17 ++++++----------- .../lib/guards/is-flags-override-on.guard.ts | 14 ++++---------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/lib/core/feature-flags/src/lib/guards/is-feature-off.guard.ts b/lib/core/feature-flags/src/lib/guards/is-feature-off.guard.ts index 4375c4827e4..6dd9fdd79fc 100644 --- a/lib/core/feature-flags/src/lib/guards/is-feature-off.guard.ts +++ b/lib/core/feature-flags/src/lib/guards/is-feature-off.guard.ts @@ -15,18 +15,13 @@ * limitations under the License. */ -import { Inject, Injectable, inject } from '@angular/core'; -import { FeaturesServiceToken, IFeaturesService } from '../interfaces/features.interface'; -import { CanMatch, Route } from '@angular/router'; +import { inject } from '@angular/core'; +import { FeaturesServiceToken } from '../interfaces/features.interface'; +import { Route } from '@angular/router'; import { Observable } from 'rxjs'; export const isFeatureOff = (flag: string) => () => inject(FeaturesServiceToken).isOff$(flag); -@Injectable({ providedIn: 'root' }) -export class IsFeatureOff implements CanMatch { - constructor(@Inject(FeaturesServiceToken) private featuresServiceToken: IFeaturesService) {} - - canMatch(route: Route): Observable { - return this.featuresServiceToken.isOff$(route?.data?.['feature']); - } -} +export const IsFeatureOff = (route: Route): Observable => { + return inject(FeaturesServiceToken).isOff$(route?.data?.['feature']); +}; diff --git a/lib/core/feature-flags/src/lib/guards/is-feature-on.guard.ts b/lib/core/feature-flags/src/lib/guards/is-feature-on.guard.ts index 29ebd81aeae..7c65f7ed54e 100644 --- a/lib/core/feature-flags/src/lib/guards/is-feature-on.guard.ts +++ b/lib/core/feature-flags/src/lib/guards/is-feature-on.guard.ts @@ -15,18 +15,13 @@ * limitations under the License. */ -import { Inject, Injectable, inject } from '@angular/core'; -import { FeaturesServiceToken, IFeaturesService } from '../interfaces/features.interface'; -import { CanMatch, Route } from '@angular/router'; +import { inject } from '@angular/core'; +import { FeaturesServiceToken } from '../interfaces/features.interface'; +import { Route } from '@angular/router'; import { Observable } from 'rxjs'; export const isFeatureOn = (flag: string) => () => inject(FeaturesServiceToken).isOn$(flag); -@Injectable({ providedIn: 'root' }) -export class IsFeatureOn implements CanMatch { - constructor(@Inject(FeaturesServiceToken) private featuresServiceToken: IFeaturesService) {} - - canMatch(route: Route): Observable { - return this.featuresServiceToken.isOn$(route?.data?.['feature']); - } -} +export const IsFeatureOn = (route: Route): Observable => { + return inject(FeaturesServiceToken).isOn$(route?.data?.['feature']); +}; diff --git a/lib/core/feature-flags/src/lib/guards/is-flags-override-on.guard.ts b/lib/core/feature-flags/src/lib/guards/is-flags-override-on.guard.ts index 4f3eb074b80..e291a83e69f 100644 --- a/lib/core/feature-flags/src/lib/guards/is-flags-override-on.guard.ts +++ b/lib/core/feature-flags/src/lib/guards/is-flags-override-on.guard.ts @@ -15,17 +15,11 @@ * limitations under the License. */ -import { Inject, Injectable, Optional, inject } from '@angular/core'; +import { inject } from '@angular/core'; import { FlagsOverrideToken } from '../interfaces/features.interface'; -import { CanMatch } from '@angular/router'; export const isFlagsOverrideOn = () => () => inject(FlagsOverrideToken) ?? false; -@Injectable({ providedIn: 'root' }) -export class IsFlagsOverrideOn implements CanMatch { - constructor(@Optional() @Inject(FlagsOverrideToken) private devToolsToken: boolean) {} - - canMatch(): boolean { - return !!this.devToolsToken; - } -} +export const IsFlagsOverrideOn = (): boolean => { + return !!inject(FlagsOverrideToken); +};