Skip to content
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

Feature Flags Compact Offline Framework #1

Merged
merged 1 commit into from
Nov 30, 2020

Conversation

android10
Copy link
Owner

This PR aims to Introduce a first version, which will let to define Feature Flags at compile time.

API Usage:

        Flag.ExampleFeature whenActivated {
            doSomething()
        } otherwise {
            //do something else
        }

Flags are defined at compile time per Product Flavor:

File: FeatureFlags.kt

/**
 * Defines a map for activated flags per product flavor.
 */
object FeatureFlags {
    val activated = mapOf(

        //Enabled Features for DEV Product Flavor
        ProductFlavors.DEV to setOf(
            Features.FEATURE_HELLO,
            Features.FEATURE_BYE),

        //Enabled Features for INTERNAL Product Flavor
        ProductFlavors.INTERNAL to setOf(
            Features.FEATURE_BYE),

        //Enabled Features for PUBLIC Product Flavor
        ProductFlavors.PUBLIC to setOf(
            Features.FEATURE_HELLO))

Compile time flags values should be assigned to Flag class for usage at code level:

/**
 * Feature flags states (activated/deactivated) can be used as conditionals.
 *
 * ### Example:
 *
 * ```Flag.Conversations whenActivated { fn } otherwise { fn }```
 */
internal sealed class Flag(enabled: Boolean) : FeatureFlag(enabled) {

    /**
     * Defined Feature Flags.
     * @see "FeatureFlags.kt" file for compile-time feature definition.
     */
    object Search : Flag(BuildConfig.FEATURE_HELLO)
    object Conversations : Flag(BuildConfig.FEATURE_BYE)
}

@android10 android10 self-assigned this Nov 30, 2020
@android10 android10 added the enhancement New feature or request label Nov 30, 2020
@android10 android10 merged commit 370cbb3 into main Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant