@@ -11,50 +11,49 @@ import RxSwift
1111import RIBs
1212
1313public protocol RIBsTreeViewer {
14- init ( router: Routing , option : [ RIBsTreeViewerOption : Any ] ? )
14+ init ( router: Routing , options : [ RIBsTreeViewerOption ] ? )
1515 func start( )
1616 func stop( )
1717}
1818
1919public enum RIBsTreeViewerOption {
20- case webSocketURL
21- case monitoringInterval
20+ case webSocketURL( String )
21+ case monitoringIntervalMillis ( Int )
2222}
2323
2424@available ( iOS 13 . 0 , * )
2525public class RIBsTreeViewerImpl : RIBsTreeViewer {
2626
2727 private let router : Routing
2828 private let webSocket : WebSocketClient
29+ private let monitoringIntervalMillis : Int
2930 private var watchingDisposable : Disposable ?
30- private let option : [ RIBsTreeViewerOption : Any ] ?
3131
32- required public init ( router: Routing , option: [ RIBsTreeViewerOption : Any ] ? ) {
33- self . option = option
32+ required public init ( router: Routing , options: [ RIBsTreeViewerOption ] ? ) {
3433 self . router = router
3534
36- let webSocketURL : String
37- if let url = option ? [ . webSocketURL] as? String {
38- webSocketURL = url
39- } else {
40- webSocketURL = " ws://0.0.0.0:8080 "
41- }
35+ var webSocketURLString = " ws://0.0.0.0:8080 "
36+ var monitoringIntervalMillis = 1000
37+
38+ options? . forEach ( { option in
39+ switch option {
40+ case . webSocketURL( let url) :
41+ webSocketURLString = url
42+ break
43+ case . monitoringIntervalMillis( let intervalMillis) :
44+ monitoringIntervalMillis = intervalMillis
45+ break
46+ }
47+ } )
4248
43- self . webSocket = WebSocketClient . init ( url: URL ( string: webSocketURL) !)
49+ self . monitoringIntervalMillis = monitoringIntervalMillis
50+ self . webSocket = WebSocketClient . init ( url: URL ( string: webSocketURLString) !)
4451 self . webSocket. delegate = self
4552 }
4653
4754 public func start( ) {
4855 webSocket. connect ( )
49-
50- let watchingInterval : Int
51- if let interval = option ? [ . monitoringInterval] as? Int {
52- watchingInterval = interval
53- } else {
54- watchingInterval = 1000
55- }
56-
57- watchingDisposable = Observable < Int > . interval ( . milliseconds( watchingInterval) , scheduler: MainScheduler . instance)
56+ watchingDisposable = Observable < Int > . interval ( . milliseconds( monitoringIntervalMillis) , scheduler: MainScheduler . instance)
5857 . map { [ unowned self] _ in
5958 self . tree ( router: self . router)
6059 }
0 commit comments