Skip to content

Commit 7a9e2cc

Browse files
committed
Fix update(.initial) being called twice on destination plugin timeline.
1 parent e83f63e commit 7a9e2cc

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Sources/Segment/Settings.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ extension Settings: Equatable {
109109

110110
extension Analytics {
111111
internal func update(settings: Settings) {
112-
guard let system: System = store.currentState() else { return }
113112
apply { plugin in
114-
plugin.update(settings: settings, type: updateType(for: plugin, in: system))
113+
plugin.update(settings: settings, type: updateType(for: plugin))
115114
if let destPlugin = plugin as? DestinationPlugin {
116115
destPlugin.apply { subPlugin in
117-
subPlugin.update(settings: settings, type: updateType(for: subPlugin, in: system))
116+
subPlugin.update(settings: settings, type: updateType(for: subPlugin))
118117
}
119118
}
120119
}
@@ -125,19 +124,12 @@ extension Analytics {
125124
// if we're already running, update has already been called for existing plugins,
126125
// so we just wanna call it on this one if it hasn't been done already.
127126
if system.running, let settings = system.settings {
128-
let alreadyInitialized = system.initializedPlugins.contains { p in
129-
return plugin === p
130-
}
131-
if !alreadyInitialized {
132-
store.dispatch(action: System.AddPluginToInitialized(plugin: plugin))
133-
plugin.update(settings: settings, type: .initial)
134-
} else {
135-
plugin.update(settings: settings, type: .refresh)
136-
}
127+
plugin.update(settings: settings, type: updateType(for: plugin))
137128
}
138129
}
139130

140-
internal func updateType(for plugin: Plugin, in system: System) -> UpdateType {
131+
internal func updateType(for plugin: Plugin) -> UpdateType {
132+
guard let system: System = store.currentState() else { return .initial }
141133
let alreadyInitialized = system.initializedPlugins.contains { p in
142134
return plugin === p
143135
}

0 commit comments

Comments
 (0)