Skip to content

Commit 4e595de

Browse files
authored
Use copies of Events in the Mediator instead of referring to the same… (#162)
* Use copies of Events in the Mediator instead of referring to the same event which has side-effect issues. * update to val.
1 parent e4e41ab commit 4e595de

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ internal class Mediator(internal var plugins: CopyOnWriteArrayList<Plugin> = Cop
3030

3131
plugins.forEach { plugin ->
3232
result?.let {
33+
val copy = it.copy<BaseEvent>()
3334
try {
3435
when (plugin) {
3536
is DestinationPlugin -> {
36-
plugin.execute(it)
37+
plugin.execute(copy)
3738
}
3839
else -> {
39-
result = plugin.execute(it)
40+
result = plugin.execute(copy)
4041
}
4142
}
4243
} catch (t: Throwable) {

core/src/test/kotlin/com/segment/analytics/kotlin/core/platform/plugins/DestinationPluginTests.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ class DestinationPluginTests {
155155

156156
val result = timeline.process(trackEvent)
157157

158-
assertEquals(expected, result)
158+
assertEquals(expected.type, result?.type)
159+
assertEquals(expected.event, (result as TrackEvent).event)
160+
assertEquals(expected.properties, (result as TrackEvent).properties)
159161
}
160162

161163
@Test

0 commit comments

Comments
 (0)