RedMadRobot / flipper

Flipper is a simple and useful tool to deal with feature toggles
MIT License
71 stars 3 forks source link

Composite flipper config #6

Open osipxd opened 4 years ago

osipxd commented 4 years ago

It would be great to have the ability to simply create complex flipper configs compositions.

We have three configs (in order of priority):

  1. debug - configured from in-app debug panel
  2. remote - values from Firebase remote config
  3. local - hardcoded default values

If value not found in debug config, it will get from remote config. If value not configured in remote config it will get from local.

Our current solution

class LocalFlipperConfig() : FlipperConfig { /*...*/ }

class RemoteFlipperConfig(localConfig: LocalFlipperConfig) : FlipperConfig { 
    override fun featureIsEnabled(feature: Feature): Boolean {
        return if (hasValue(feature.id)) ... else localConfig.featureIsEnabled(feature)
    }
}

class DebugFlipperConfig(remoteConfig: RemoteFlipperConfig) : FlipperConfig { 
    override fun featureIsEnabled(feature: Feature): Boolean {
        return if (hasValue(feature.id)) ... else remoteConfig.featureIsEnabled(feature)
    }
}

ToggleRouter.init(DebugFlipperConfig(RemoteFlipperConfig(LocalFlipperConfig())))

Desired solution

class LocalFlipperConfig() : FlipperConfig { /*...*/ }

class RemoteFlipperConfig() : FlipperConfig { /*...*/ }

class DebugFlipperConfig() : FlipperConfig { /*...*/ }

ToggleRouter.init(
    DebugFlipperConfig(), 
    RemoteFlipperConfig(), 
    LocalFlipperConfig()
)
osipxd commented 4 years ago

One of the ways I see - add method contains to FlipperConfig. Iterate over all configs and check if it contains the desired feature.