Skip to content

Commit 84caf13

Browse files
author
yuki tamazawa
committed
Update Option Interface
1 parent e410ed8 commit 84caf13

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

RIBsTreeViewerClient.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
"@executable_path/Frameworks",
319319
"@loader_path/Frameworks",
320320
);
321-
MARKETING_VERSION = 1.0.5;
321+
MARKETING_VERSION = 1.0.6;
322322
PRODUCT_BUNDLE_IDENTIFIER = co.minipro.app.RIBsTreeViewerClient;
323323
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
324324
SKIP_INSTALL = YES;
@@ -352,7 +352,7 @@
352352
"@executable_path/Frameworks",
353353
"@loader_path/Frameworks",
354354
);
355-
MARKETING_VERSION = 1.0.5;
355+
MARKETING_VERSION = 1.0.6;
356356
PRODUCT_BUNDLE_IDENTIFIER = co.minipro.app.RIBsTreeViewerClient;
357357
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
358358
SKIP_INSTALL = YES;

RIBsTreeViewerClient/Sources/RIBsTreeViewer.swift

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,49 @@ import RxSwift
1111
import RIBs
1212

1313
public protocol RIBsTreeViewer {
14-
init(router: Routing, option: [RIBsTreeViewerOption: Any]?)
14+
init(router: Routing, options: [RIBsTreeViewerOption]?)
1515
func start()
1616
func stop()
1717
}
1818

1919
public enum RIBsTreeViewerOption {
20-
case webSocketURL
21-
case monitoringInterval
20+
case webSocketURL(String)
21+
case monitoringIntervalMillis(Int)
2222
}
2323

2424
@available(iOS 13.0, *)
2525
public 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

Comments
 (0)