File tree Expand file tree Collapse file tree 6 files changed +31
-40
lines changed
Expand file tree Collapse file tree 6 files changed +31
-40
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ public class Amplitude {
2020 ) {
2121 self . configuration = configuration
2222 self . instanceName = instanceName
23- //_ = add(LifecyclePlugin())
23+ // _ = add(LifecyclePlugin())
2424 _ = add ( plugin: ContextPlugin ( ) )
2525 _ = add ( plugin: AmplitudeDestinationPlugin ( ) )
2626 }
Original file line number Diff line number Diff line change 11//
2- // File .swift
3- //
2+ // Mediator .swift
3+ //
44//
55// Created by Hao Yu on 11/9/22.
66//
77
8- import Foundation
9-
108internal class Mediator {
119 // create an array with certain type.
1210 internal var plugins = [ Plugin] ( )
1311
1412 internal func add( plugin: Plugin ) {
1513 plugins. append ( plugin)
1614 }
17-
15+
1816 internal func remove( plugin: Plugin ) {
1917 plugins. removeAll { ( storedPlugin) -> Bool in
2018 return storedPlugin === plugin
2119 }
2220 }
23-
21+
2422 internal func execute( event: BaseEvent ) -> BaseEvent ? {
25- var result : BaseEvent ? = event;
23+ var result : BaseEvent ? = event
2624 plugins. forEach { plugin in
2725 if let r = result {
2826 if plugin is DestinationPlugin {
@@ -47,7 +45,7 @@ internal class Mediator {
4745 }
4846 return result
4947 }
50-
48+
5149 internal func applyClosure( _ closure: ( Plugin ) -> Void ) {
5250 plugins. forEach { plugin in
5351 closure ( plugin)
Original file line number Diff line number Diff line change 11//
2- // File .swift
2+ // Timeline .swift
33//
44//
55// Created by Marvin Liu on 10/27/22.
66//
77
8- import Foundation
9-
108public class Timeline {
119 internal let plugins : [ PluginType : Mediator ]
1210
13-
1411 init ( ) {
1512 self . plugins = [
1613 PluginType . before: Mediator ( ) ,
1714 PluginType . enrichment: Mediator ( ) ,
1815 PluginType . destination: Mediator ( ) ,
19- PluginType . utility: Mediator ( )
16+ PluginType . utility: Mediator ( ) ,
2017 ]
2118 }
2219
@@ -29,13 +26,13 @@ public class Timeline {
2926
3027 internal func applyPlugin( pluginType: PluginType , event: BaseEvent ? ) -> BaseEvent ? {
3128 var result : BaseEvent ? = event
32- if let mediator = plugins [ pluginType] , let e = event {
33- result = mediator. execute ( event: e )
29+ if let mediator = plugins [ pluginType] {
30+ result = mediator. execute ( event: event! )
3431 }
3532 return result
36-
33+
3734 }
38-
35+
3936 internal func add( plugin: Plugin ) {
4037 if let mediator = plugins [ plugin. type] {
4138 mediator. add ( plugin: plugin)
Original file line number Diff line number Diff line change 11//
2- // File .swift
2+ // Types .swift
33//
44//
55// Created by Marvin Liu on 10/27/22.
66//
77
8- import Foundation
9-
108public struct Plan {
119 var branch : String ?
1210 var source : String ?
@@ -49,7 +47,7 @@ public enum PluginType: String {
4947public protocol Plugin : AnyObject {
5048 var type : PluginType { get }
5149 var amplitude : Amplitude ? { get set }
52- func setup( amplitude: Amplitude )
50+ func setup( amplitude: Amplitude )
5351 func execute( event: BaseEvent ) -> BaseEvent ?
5452}
5553
Original file line number Diff line number Diff line change 11@testable import Amplitude_Swift
22
3- class testEnrichmentPlugin : Plugin {
3+ class TestEnrichmentPlugin : Plugin {
44 let type : PluginType
55 var amplitude : Amplitude ?
66 let trackCompletion : ( ( ) -> Bool ) ?
7-
7+
88 init ( trackCompletion: ( ( ) -> Bool ) ? = nil ) {
99 self . type = PluginType . enrichment
1010 self . trackCompletion = trackCompletion
1111 }
12-
12+
1313 func setup( amplitude: Amplitude ) {
14- self . amplitude = amplitude;
14+ self . amplitude = amplitude
1515 }
16-
16+
1717 func execute( event: BaseEvent ) -> BaseEvent ? {
1818 var returnEvent : BaseEvent ? = event
1919 if let completion = trackCompletion {
@@ -23,7 +23,5 @@ class testEnrichmentPlugin : Plugin {
2323 }
2424 return returnEvent
2525 }
26-
27-
28-
26+
2927}
Original file line number Diff line number Diff line change @@ -5,39 +5,39 @@ import XCTest
55
66final class TimelineTest : XCTestCase {
77 private var timeline : Timeline !
8-
8+
99 func testTimeline( ) {
1010 let expectation = XCTestExpectation ( description: " First Plugin " )
11- let testPlugin = testEnrichmentPlugin {
11+ let testPlugin = TestEnrichmentPlugin {
1212 expectation. fulfill ( )
1313 return true
1414 }
15-
15+
1616 let amplitude = Amplitude ( configuration: Configuration ( apiKey: " testApiKey " ) )
1717 amplitude. add ( plugin: testPlugin)
1818 amplitude. track ( event: BaseEvent ( eventType: " testEvent " ) )
19-
19+
2020 wait ( for: [ expectation] , timeout: 1.0 )
2121 }
22-
22+
2323 func testTimelineWithTwoPlugin( ) {
2424 let expectation = XCTestExpectation ( description: " First Plugin " )
2525 let expectation2 = XCTestExpectation ( description: " Second Plugin " )
26- let testPlugin = testEnrichmentPlugin {
26+ let testPlugin = TestEnrichmentPlugin {
2727 expectation. fulfill ( )
2828 return true
2929 }
30-
31- let testPlugin2 = testEnrichmentPlugin {
30+
31+ let testPlugin2 = TestEnrichmentPlugin {
3232 expectation2. fulfill ( )
3333 return true
3434 }
35-
35+
3636 let amplitude = Amplitude ( configuration: Configuration ( apiKey: " testApiKey " ) )
3737 amplitude. add ( plugin: testPlugin)
3838 amplitude. add ( plugin: testPlugin2)
3939 amplitude. track ( event: BaseEvent ( eventType: " testEvent " ) )
40-
40+
4141 wait ( for: [ expectation, expectation2] , timeout: 1.0 )
4242 }
4343}
You can’t perform that action at this time.
0 commit comments