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

fix: Fix the bug regarding accessing flags using with context #172

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Confidence/src/main/java/com/spotify/confidence/Confidence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Confidence internal constructor(
private val parent: ConfidenceContextProvider? = null,
private val region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
private val debugLogger: DebugLogger?
) : Contextual, EventSender {
) : ConfidenceAPI {
private val removedKeys = mutableListOf<String>()
private val contextMap = MutableStateFlow(initialContext)
private var currentFetchJob: Job? = null
Expand All @@ -50,11 +50,13 @@ class Confidence internal constructor(
private val eventProducers: MutableList<EventProducer> = mutableListOf()

init {
coroutineScope.launch {
contextChanges
.collect {
fetchAndActivate()
}
if (parent == null) {
coroutineScope.launch {
contextChanges
.collect {
fetchAndActivate()
}
}
}
}

Expand Down Expand Up @@ -144,7 +146,7 @@ class Confidence internal constructor(
it.getContext().filterKeys { key -> !removedKeys.contains(key) } + contextMap.value
} ?: contextMap.value

override fun withContext(context: Map<String, ConfidenceValue>): Confidence = Confidence(
override fun withContext(context: Map<String, ConfidenceValue>): ConfidenceAPI = Confidence(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventSender interface already extends Contextual: can we just return the EventSender type from withContext?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can good point.

clientSecret,
dispatcher,
eventSenderEngine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface Contextual : ConfidenceContextProvider {
fun putContext(context: Map<String, ConfidenceValue>)
fun putContext(key: String, value: ConfidenceValue)
fun removeContext(key: String)
}
}

interface ConfidenceAPI : Contextual, EventSender
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.example.confidencedemoapp

import android.app.Application
Expand Down
Loading