-
Notifications
You must be signed in to change notification settings - Fork 41
feat: add feature flag service for angular #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Lukas Reining <[email protected]>
@lukas-reining, what would it look like if you left the |
@Component({
template: `
<div data-testid="value">{{ thumbs()?.value ? '👍' : '👎' }}</div>
<div data-testid="reason">reason: {{ thumbs()?.reason }}</div>
`,
standalone: true,
})
class TestSignalComponent {
private flagService = inject(FeatureFlagService);
thumbs = toSignal(this.flagService.getBooleanDetails(FLAG_KEY, false));
} @beeme1mr it would just be removing the methods for signals and wrapping the observable methods in |
This would mean that the user can choose to consume the evaluation as an Observable or as a Signal, right? If that is the case, and if it is also the case that Angular wants to continue supporting both Observables and Signals, then I really like the approach of leaving |
Exactly, I also lean towards only having the observables in the API of the service. Having it in would just be hiding |
Okay cool - I'd lean for leaving the |
Signed-off-by: Lukas Reining <[email protected]>
35a3ebc
to
1fe2926
Compare
Okay great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it - straightforward and easy to understand how it's used for both Observables and Signals 👍
* @param {FlagValue} other Second value to compare | ||
* @returns {boolean} True if the values are equal | ||
*/ | ||
export function isEqual(value: FlagValue, other: FlagValue): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this to core? I could go either way since it's small and is unlikely to change but the same function is also in the React SDK.
// Initial evaluation | ||
updateValue(); | ||
return () => { | ||
controller.abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will this callback fire? Sorry if it's a basic question, I'm not that familiar with Observables. I just want to make sure we're not prematurely unregistering the handlers.
|
||
export interface OpenFeatureConfig { | ||
provider: Provider; | ||
provider?: Provider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a JSDoc to explain these config options? It would help the developer to understand when to provide a Provider and when it's okay to omit that value. Thanks!
) { | ||
super(flagConfiguration); | ||
if (!delay) { | ||
Object.assign(this, { initialize: undefined }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clever. I know why you did this but future me may not. Could you please add a comment explaining why this was necessary?
Feature is enabled! Reason: {{ (isFeatureEnabled$ | async)?.reason }} | ||
</div> | ||
<div>Theme: {{ (currentTheme$ | async)?.value }}</div> | ||
<div>Max items: {{ (maxItems$ | async)?.value }}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need the ?
? Won't value always be there once the flag been evaluated?
NOTE: This is still a draft for discussion!
This PR
Adds a service for evaluating flags in angular services.
It enables application authors to evaluate flags directly as observables or signal.
I am not 100% sure about returning signals or leaving thetoSignal
to the application autors.As far as I understand, when used like the following, subscriptions for
toSignal
will still be cleaned up correctly, as the injection context will be captured correctly in that case:Edit: We decided to leave the
toSignal
to the app authors.@juanparadox please leave feedback.
I still have to clean up the tests and the code in general, if we decide this is the design we opt for.