Skip to content

Commit

Permalink
Updated IsFeatureOff, IsFeatureOn and IsFlagsOverrideOn guards to be …
Browse files Browse the repository at this point in the history
…functional guards
  • Loading branch information
swapnil-verma-gl committed Jun 26, 2024
1 parent 49b79b6 commit ac2006f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
17 changes: 6 additions & 11 deletions lib/core/feature-flags/src/lib/guards/is-feature-off.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
return this.featuresServiceToken.isOff$(route?.data?.['feature']);
}
}
export const IsFeatureOff = (route: Route): Observable<boolean> => {
return inject(FeaturesServiceToken).isOff$(route?.data?.['feature']);
};
17 changes: 6 additions & 11 deletions lib/core/feature-flags/src/lib/guards/is-feature-on.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
return this.featuresServiceToken.isOn$(route?.data?.['feature']);
}
}
export const IsFeatureOn = (route: Route): Observable<boolean> => {
return inject(FeaturesServiceToken).isOn$(route?.data?.['feature']);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit ac2006f

Please sign in to comment.