Skip to content

Commit

Permalink
Update JustBridge.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
叶增峰 authored and 叶增峰 committed Jan 3, 2019
1 parent 6286b64 commit ad3fdd8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions JSBridge/Classes/JustBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class JustBridge: NSObject {
public typealias BridgeData = Any?

/// the key for messages between Swift and JavaScript
private struct MessageKey {
fileprivate struct MessageKey {
static let name = "name"
static let data = "data"
static let swiftCallbackId = "swiftCallbackId"
Expand All @@ -40,14 +40,14 @@ public class JustBridge: NSObject {
public typealias Callback = (_ responseData: BridgeData) -> Void
public typealias Handler = (_ data: BridgeData, _ callback: Callback) -> Void

private var handlers: [String: Handler] = [:]
private var callbacks: [String: Callback] = [:]
private var errorCallbacks: [String: ErrorCallback] = [:]
fileprivate var handlers: [String: Handler] = [:]
fileprivate var callbacks: [String: Callback] = [:]
fileprivate var errorCallbacks: [String: ErrorCallback] = [:]

/// unique id for callback
private var callbackId = 0
fileprivate var callbackId = 0

private var webview: WKWebView
fileprivate var webview: WKWebView

public init(with webView: WKWebView) {
self.webview = webView
Expand Down Expand Up @@ -93,12 +93,12 @@ public class JustBridge: NSObject {

extension JustBridge {

private func injectBridgeJS() {
fileprivate func injectBridgeJS() {
let script = WKUserScript(source: JustBridge.bridge_js, injectionTime: .atDocumentStart, forMainFrameOnly: true)
self.webview.configuration.userContentController.addUserScript(script)
}

private func postMessage(_ name: String, data: BridgeData, swiftCallbackId: String? = nil, jsCallbackId: String? = nil, error: String? = nil) {
fileprivate func postMessage(_ name: String, data: BridgeData, swiftCallbackId: String? = nil, jsCallbackId: String? = nil, error: String? = nil) {
var message = [String: Any]()
message[MessageKey.name] = name
message[MessageKey.data] = data
Expand Down

0 comments on commit ad3fdd8

Please sign in to comment.