Toggle

interface Toggle

Types

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class DefaultValue(val defaultValue: Toggle.DefaultFeatureValue)

This annotation is required. It specifies the default value of the feature flag when it's not remotely defined

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class Experiment

This annotation should be used in feature flags that related to experimentation. It will make the feature flag to set the default variant if isEnabled is called BEFORE any variant has been allocated. It will make the feature flag to consider the target variants during the isEnabled evaluation.

Link copied to clipboard
data class FeatureName(val parentName: String?, val name: String)

The feature name the name of the feature parentName the name of the parent feature, or null if the feature has no parent (root feature)

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class InternalAlwaysEnabled

This annotation is optional. It will make the feature flag ALWAYS enabled for internal builds

Link copied to clipboard
data class State(val remoteEnableState: Boolean? = null, val enable: Boolean = false, val minSupportedVersion: Int? = null, val rollout: List<Double>? = null, val rolloutThreshold: Double? = null, val targets: List<Toggle.State.Target> = emptyList(), val metadataInfo: String? = null, val cohorts: List<Toggle.State.Cohort> = emptyList(), val assignedCohort: Toggle.State.Cohort? = null, val settings: String? = null, val exceptions: List<FeatureException> = emptyList())

This represents the state of a Toggle

Link copied to clipboard
interface Store
Link copied to clipboard

It is possible to add feature Targets. To do that, just add the property inside the Target and implement the TargetMatcherPlugin to do the matching

Functions

Link copied to clipboard
abstract suspend fun enroll(): Boolean

This method

Link copied to clipboard
Link copied to clipboard
abstract suspend fun getCohort(): Toggle.State.Cohort?

WARNING: This method always returns the cohort assigned regardless it the experiment is still enabled or not.

Link copied to clipboard
Link copied to clipboard

The usage of this API is only useful for internal/dev settings/features If you find yourself having to call this method in production code, then YOU'RE DOING SOMETHING WRONG The raw state is the stored state. isEnabled method takes the raw state and computes whether the feature should be enabled or disabled. eg. by factoring in State.minSupportedVersion amongst others.

Link copied to clipboard
abstract fun getSettings(): String?
Link copied to clipboard
abstract fun isEnabled(): Boolean

This method - Returns whether the feature flag state is enabled or disabled. - It is not affected by experiment cohort assignment. It just checks whether the feature is enabled or not. - It considers all other constraints like targets, minSupportedVersion, etc.

Link copied to clipboard
abstract suspend fun isEnrolled(): Boolean

Convenience method that checks if getCohort is not null

Link copied to clipboard
Link copied to clipboard
abstract fun setRawStoredState(state: Toggle.State)

The usage of this API is only useful for internal/dev settings/features If you find yourself having to call this method in production code, then YOU'RE DOING SOMETHING WRONG