Skip to content

Commit 5329eda

Browse files
committed
make enrichment closure a property of event
1 parent 347333c commit 5329eda

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ open class Analytics protected constructor(
513513

514514
log("applying base attributes on ${Thread.currentThread().name}")
515515
analyticsScope.launch(analyticsDispatcher) {
516-
event.applyBaseEventData(store)
516+
event.applyBaseEventData(store, enrichment)
517517
log("processing event on ${Thread.currentThread().name}")
518-
timeline.process(event, enrichment)
518+
timeline.process(event)
519519
}
520520
}
521521

core/src/main/java/com/segment/analytics/kotlin/core/Events.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ typealias AnalyticsContext = JsonObject
1212
typealias Integrations = JsonObject
1313
typealias Properties = JsonObject
1414
typealias Traits = JsonObject
15+
typealias EnrichmentClosure = (event: BaseEvent?) -> BaseEvent?
1516

1617
val emptyJsonObject = JsonObject(emptyMap())
1718
val emptyJsonArray = JsonArray(emptyList())
@@ -75,6 +76,8 @@ sealed class BaseEvent {
7576

7677
abstract var _metadata: DestinationMetadata
7778

79+
var enrichment: EnrichmentClosure? = null
80+
7881
companion object {
7982
internal const val ALL_INTEGRATIONS_KEY = "All"
8083
}
@@ -85,9 +88,10 @@ sealed class BaseEvent {
8588
this.messageId = UUID.randomUUID().toString()
8689
}
8790

88-
internal suspend fun applyBaseEventData(store: Store) {
91+
internal suspend fun applyBaseEventData(store: Store, enrichment: EnrichmentClosure?) {
8992
val userInfo = store.currentState(UserInfo::class) ?: return
9093

94+
this.enrichment = enrichment
9195
this.anonymousId = userInfo.anonymousId
9296
this.integrations = emptyJsonObject
9397

core/src/main/java/com/segment/analytics/kotlin/core/platform/Timeline.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ internal class Timeline {
2424
lateinit var analytics: Analytics
2525

2626
// initiate the event's lifecycle
27-
fun process(incomingEvent: BaseEvent, enrichmentClosure: EnrichmentClosure? = null): BaseEvent? {
27+
fun process(incomingEvent: BaseEvent): BaseEvent? {
2828
val beforeResult = applyPlugins(Plugin.Type.Before, incomingEvent)
2929
var enrichmentResult = applyPlugins(Plugin.Type.Enrichment, beforeResult)
30-
enrichmentClosure?.let {
30+
enrichmentResult?.enrichment?.let {
3131
enrichmentResult = it(enrichmentResult)
3232
}
3333

core/src/main/java/com/segment/analytics/kotlin/core/platform/plugins/StartupQueue.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class StartupQueue : Plugin, Subscriber {
7272
// after checking if the queue is empty so we only process if the event
7373
// if it is indeed not NULL.
7474
event?.let {
75-
analytics.process(it)
75+
analytics.process(it, it.enrichment)
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)