Requirements
In the current implementation, the API is provided only via Observable. Unfortunately, using Observable isn't always convenient if you need to know the current value instantly, without a subscription. For example, in a function to branch its algorithm.
I propose creating an additional API using Angular Signals. It will internally work based on the existing Observable API (with toSignal) and doesn't require creating a new service or extending an existing one. We'll only need to create a set of functions that will be called in the injection context. Here's an example with all possible API use cases:
@Component({})
export class SomeComponent {
public readonly parameter1 = featureToggle.preloaded.boolean('boolean-parameter', true); // Signal<EvaluationDetails<boolean>>
public readonly parameter2 = featureToggle.preloaded.string('string-parameter', 'true'); // Signal<EvaluationDetails<string>>
public readonly parameter3 = featureToggle.preloaded.number('number-parameter', 1); // Signal<EvaluationDetails<number>>
public readonly parameter4 = featureToggle.preloaded.object('object-parameter', []); // Signal<EvaluationDetails<JsonValue>>
public readonly parameter5 = featureToggle.boolean('boolean-parameter', true); // Signal<EvaluationDetails<boolean> | undefined>
public readonly parameter6 = featureToggle.string('string-parameter', 'true'); // Signal<EvaluationDetails<string> | undefined>
public readonly parameter7 = featureToggle.number('number-parameter', 1); // Signal<EvaluationDetails<number> | undefined>
public readonly parameter8 = featureToggle.object('object-parameter', []); // Signal<EvaluationDetails<JsonValue> | undefined>
public someAction() {
if (this.parameter1().value) {
// some action
} else {
// some another action
}
}
}
There are two use cases for the function: with and without preloaded. Using preloaded will make the value available without undefined, but this assumes the value has already been preloaded. If not, then undefined will appear within the signal until the value is preloaded.
I'm willing to consider your comments, implement this, and create a MR.
Requirements
In the current implementation, the API is provided only via
Observable. Unfortunately, usingObservableisn't always convenient if you need to know the current value instantly, without a subscription. For example, in a function to branch its algorithm.I propose creating an additional API using Angular Signals. It will internally work based on the existing Observable API (with
toSignal) and doesn't require creating a new service or extending an existing one. We'll only need to create a set of functions that will be called in the injection context. Here's an example with all possible API use cases:There are two use cases for the function: with and without
preloaded. Usingpreloadedwill make the value available withoutundefined, but this assumes the value has already been preloaded. If not, thenundefinedwill appear within the signal until the value is preloaded.I'm willing to consider your comments, implement this, and create a MR.