pBouillon / ngx-flagr

🚩 Effortless feature flag management in Angular
https://pbouillon.github.io/ngx-flagr/
MIT License
9 stars 2 forks source link

Add support for a default `FeatureFlagService` #4

Closed pBouillon closed 1 year ago

pBouillon commented 1 year ago

Issue Summary

Implement a default FeatureFlagService based on the environment.json file.

Category

- [ ] Bug report
- [ ] Regression
- [x] Feature suggestion
- [ ] Documentation issue
- [ ] Other

Expected Behavior

The default FeatureFlagService will look for a featureFlags object in the environment.json file, and use it to evaluate whether a feature flag provided to the FeatureFlagDirective is enabled or not.

Actual Behavior

Currently, there is no default FeatureFlagService implementation, and users need to create their own implementation to use the FeatureFlagDirective.

If none is provided, the resolution of the FeatureFlagService will throw an error.

Steps to Reproduce

N/A

Environment

Additional Information

This feature would simplify the usage of the library for developers who are already using the environment.json file to manage environment-specific configurations.

The default FeatureFlagService could be implemented in a way that allows for customization by users who need to use a different configuration file or a different configuration structure.

The FeatureFlagService could be implemented with a default behavior based on the environment.json file. The service would look for a structure similar to:

// environment.json
{
  // ...
  "featureFlags": {
    "shoppingCart": true,
    "fastDelivery": false
  }
}

Alternatively, the FeatureFlagService could be configured to throw an error when no feature flags are found, or to fallback to a default value for each flag that is not defined in the environment.json file.

It could be great if this option could be set during the configuration.

pBouillon commented 1 year ago

As stated in #5, it might be beneficial to move all implementations of FeatureFlagServices to a dedicated package

pBouillon commented 1 year ago

Accessing the environment variable from the library seems impossible. Instead, passing the feature flags at configuration time is recommended.

The feature flags should be passed on at config-time.