Skip to content

Instantly share code, notes, and snippets.

@mts88
Created November 11, 2021 19:51
Show Gist options
  • Save mts88/bc0577b4826de56ac58d3cec67f36b29 to your computer and use it in GitHub Desktop.
Save mts88/bc0577b4826de56ac58d3cec67f36b29 to your computer and use it in GitHub Desktop.
Feature Flag Service
import { Injectable } from '@angular/core';
import { IMutableContext, UnleashClient } from 'unleash-proxy-client';
@Injectable({
providedIn: 'root',
})
export class FeatureFlagService {
unleash = new UnleashClient({
url: `http://localhost:3000/proxy`, // url to Unleash Proxy
clientKey: `my_secret_for_client`, // secret used in docker env UNLEASH_PROXY_SECRETS
appName: `development`, // the appName used in docker env UNLEASH_APP_NAME
environment: `development`, // you can configure it easily in environment.ts and environment.prod.ts
});
constructor() {}
start(): void {
this.unleash.start();
}
stop(): void {
this.unleash.stop();
}
updateContext(contextObj: IMutableContext): void {
this.unleash.updateContext(contextObj);
}
isEnabled(feature: string): boolean {
return this.unleash.isEnabled(feature);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment