Skip to content

Commit

Permalink
remove convertVariant()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Yiu authored and Tim Yiu committed Sep 26, 2023
1 parent b42db02 commit ee7379c
Showing 1 changed file with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ internal class DefaultExperimentClient internal constructor(
return Variant(value, payload, expKey, evaluationVariant.key, metadata)
}

private fun convertVariant(value: Variant?): Variant {
if (value == null) {
return Variant()
}
return value
}

/**
* This function assumes the flag exists and is local evaluation mode. For
* local evaluation, fallback order goes:
Expand All @@ -468,21 +461,21 @@ internal class DefaultExperimentClient internal constructor(
val isLocalEvaluationDefault = variant?.metadata?.get("default") as? Boolean
if (variant != null && isLocalEvaluationDefault != true) {
return VariantAndSource(
variant = convertVariant(variant),
variant = variant,
source = source,
hasDefaultVariant = false
)
} else if (isLocalEvaluationDefault == true) {
defaultVariantAndSource = VariantAndSource(
variant = convertVariant(variant),
variant = variant,
source = source,
hasDefaultVariant = true
)
}
// Inline fallback
if (fallback != null) {
return VariantAndSource(
variant = convertVariant(fallback),
variant = fallback,
source = VariantSource.FALLBACK_INLINE,
hasDefaultVariant = defaultVariantAndSource.hasDefaultVariant
)
Expand All @@ -491,13 +484,13 @@ internal class DefaultExperimentClient internal constructor(
val initialVariant = config.initialVariants[key]
if (initialVariant != null) {
return VariantAndSource(
variant = convertVariant(initialVariant),
variant = initialVariant,
source = VariantSource.SECONDARY_INITIAL_VARIANTS,
hasDefaultVariant = defaultVariantAndSource.hasDefaultVariant
)
}
// Configured fallback, or default variant
val fallbackVariant = convertVariant(config.fallbackVariant)
val fallbackVariant = config.fallbackVariant
val fallbackVariantAndSource = VariantAndSource(
variant = fallbackVariant,
source = VariantSource.FALLBACK_CONFIG,
Expand Down Expand Up @@ -529,21 +522,21 @@ internal class DefaultExperimentClient internal constructor(
val isLocalStorageDefault = localStorageVariant?.metadata?.get("default") as? Boolean
if (localStorageVariant != null && isLocalStorageDefault != true) {
return VariantAndSource(
variant = convertVariant(localStorageVariant),
variant = localStorageVariant,
source = VariantSource.LOCAL_STORAGE,
hasDefaultVariant = false
)
} else if (isLocalStorageDefault == true) {
defaultVariantAndSource = VariantAndSource(
variant = convertVariant(localStorageVariant),
variant = localStorageVariant,
source = VariantSource.LOCAL_STORAGE,
hasDefaultVariant = true
)
}
// Inline fallback
if (fallback != null) {
return VariantAndSource(
variant = convertVariant(fallback),
variant = fallback,
source = VariantSource.FALLBACK_INLINE,
hasDefaultVariant = defaultVariantAndSource.hasDefaultVariant
)
Expand All @@ -552,13 +545,13 @@ internal class DefaultExperimentClient internal constructor(
val initialVariant = config.initialVariants[key]
if (initialVariant != null) {
return VariantAndSource(
variant = convertVariant(initialVariant),
variant = initialVariant,
source = VariantSource.SECONDARY_INITIAL_VARIANTS,
hasDefaultVariant = defaultVariantAndSource.hasDefaultVariant
)
}
// Configured fallback, or default variant
val fallbackVariant = convertVariant(config.fallbackVariant)
val fallbackVariant = config.fallbackVariant
val fallbackVariantAndSource = VariantAndSource(
variant = fallbackVariant,
source = VariantSource.FALLBACK_CONFIG,
Expand Down Expand Up @@ -589,7 +582,7 @@ internal class DefaultExperimentClient internal constructor(
val initialVariantsVariant = config.initialVariants[key]
if (initialVariantsVariant != null) {
return VariantAndSource(
variant = convertVariant(initialVariantsVariant),
variant = initialVariantsVariant,
source = VariantSource.INITIAL_VARIANTS,
hasDefaultVariant = false
)
Expand All @@ -599,27 +592,27 @@ internal class DefaultExperimentClient internal constructor(
val isLocalStorageDefault = localStorageVariant?.metadata?.get("default") as? Boolean
if (localStorageVariant != null && isLocalStorageDefault != true) {
return VariantAndSource(
variant = convertVariant(localStorageVariant),
variant = localStorageVariant,
source = VariantSource.LOCAL_STORAGE,
hasDefaultVariant = false
)
} else if (isLocalStorageDefault == true) {
defaultVariantAndSource = VariantAndSource(
variant = convertVariant(localStorageVariant),
variant = localStorageVariant,
source = VariantSource.LOCAL_STORAGE,
hasDefaultVariant = true
)
}
// Inline fallback
if (fallback != null) {
return VariantAndSource(
variant = convertVariant(fallback),
variant = fallback,
source = VariantSource.FALLBACK_INLINE,
hasDefaultVariant = defaultVariantAndSource.hasDefaultVariant
)
}
// Configured fallback, or default variant
val fallbackVariant = convertVariant(config.fallbackVariant)
val fallbackVariant = config.fallbackVariant
val fallbackVariantAndSource = VariantAndSource(
variant = fallbackVariant,
source = VariantSource.FALLBACK_CONFIG,
Expand Down

0 comments on commit ee7379c

Please sign in to comment.