Skip to content

Commit bc4b998

Browse files
committed
Rename
1 parent bd94547 commit bc4b998

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

NTLBridgeDemo/NTLBridgeDemo/ContentView.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ struct ContentView: View {
6767
Text(model.jsResult ?? "No result yet")
6868
}
6969
Button("Call js sync") {
70-
model.webView.callBridge(method: "syn.tag") { process($0) }
70+
model.webView.callHandler("syn.tag") { process($0) }
7171
}
7272
Button("Call js sync multiparam") {
73-
model.webView.callBridge(method: "syn.multi", args: [["1": 111]]) { process($0) }
73+
model.webView.callHandler("syn.multi", arguments: [["1": 111]]) { process($0) }
7474
}
7575
Button("Call js error") {
76-
model.webView.callBridge(method: "syn.error") { process($0) }
76+
model.webView.callHandler("syn.error") { process($0) }
7777
}
7878
Button("Call js async") {
79-
model.webView.callBridge(method: "asyn.tag", args: ["AAA"]) { process($0) }
79+
model.webView.callHandler("asyn.tag", arguments: ["AAA"]) { process($0) }
8080
}
8181
Button("Call js async error") {
82-
model.webView.callBridge(method: "asyn.error", args: ["AAA"]) { process($0) }
82+
model.webView.callHandler("asyn.error", arguments: ["AAA"]) { process($0) }
8383
}
8484
Button("Call js async multiParam") {
85-
model.webView.callBridge(method: "asyn.multiParam", args: ["BBB", ["ppp": "ttt"]]) { process($0) }
85+
model.webView.callHandler("asyn.multiParam", arguments: ["BBB", ["ppp": "ttt"]]) { process($0) }
8686
}
8787

8888
// Example of new Codable parameter support
@@ -93,7 +93,7 @@ struct ContentView: View {
9393
}
9494

9595
let user = TestUser(name: "Test User", age: 25)
96-
model.webView.callBridge(method: "asyn.tag", args: [user]) { process($0) }
96+
model.webView.callHandler("asyn.tag", arguments: [user]) { process($0) }
9797
}
9898
}
9999

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ webView.register(methodName: "calculate") { param in
9393

9494
```swift
9595
// 调用 JavaScript 方法
96-
webView.callBridge(method: "showAlert", args: ["来自 Swift 的问候!"]) { result in
96+
webView.callHandler("showAlert", arguments: ["来自 Swift 的问候!"]) { result in
9797
switch result {
9898
case .success(let value):
9999
print("JS 响应: \(value ?? .null)")
@@ -103,15 +103,15 @@ webView.callBridge(method: "showAlert", args: ["来自 Swift 的问候!"]) { r
103103
}
104104

105105
// 使用字面量语法调用
106-
webView.callBridge(method: "calculate", args: [10, 20, "add"])
106+
webView.callHandler("calculate", arguments: [10, 20, "add"])
107107

108108
// 支持Codable类型
109109
struct User: Codable {
110110
let id: String
111111
let name: String
112112
}
113113
let user = User(id: "123", name: "张三")
114-
webView.callBridge(method: "updateUser", args: [user])
114+
webView.callHandler("updateUser", arguments: [user])
115115
```
116116

117117
## Web 集成

Sources/NTLBridge/NTLWebView.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ open class NTLWebView: WKWebView {
258258
/// 调用 js bridge 方法,支持直接传入 Codable 参数数组
259259
/// - Parameters:
260260
/// - method: JavaScript注册方法名,比如 "nameA.funcB"
261-
/// - args: Codable 参数数组(会自动编码为 JSONValue 数组)
261+
/// - arguments: Codable 参数数组(会自动编码为 JSONValue 数组)
262262
/// - completion: 完成回调
263263
/// - discussion: 便捷方法,自动将 Codable 对象数组转换为 JSONValue 数组
264-
public func callBridge<T: Encodable>(
265-
method: String,
266-
args: [T],
264+
public func callHandler<T: Encodable>(
265+
_ method: String,
266+
arguments: [T],
267267
completion: ((Result<JSONValue?, Error>) -> Void)? = nil
268268
) {
269269
do {
270-
let callInfo = try NTLCallInfo(method: method, callbackId: generateCallbackId(), codableData: args)
271-
internalCallBridge(callInfo: callInfo, completion: completion)
270+
let callInfo = try NTLCallInfo(method: method, callbackId: generateCallbackId(), codableData: arguments)
271+
internalcallHandler(callInfo: callInfo, completion: completion)
272272
} catch {
273273
completion?(.failure(error))
274274
}
@@ -279,13 +279,13 @@ open class NTLWebView: WKWebView {
279279
/// - method: JavaScript注册方法名,比如 "nameA.funcB"
280280
/// - completion: 完成回调
281281
/// - discussion: 便捷方法,不需要传入参数数组
282-
public func callBridge(
283-
method: String,
282+
public func callHandler(
283+
_ method: String,
284284
completion: ((Result<JSONValue?, Error>) -> Void)? = nil
285285
) {
286286
do {
287287
let callInfo = try NTLCallInfo(method: method, callbackId: generateCallbackId(), codableData: [String]())
288-
internalCallBridge(callInfo: callInfo, completion: completion)
288+
internalcallHandler(callInfo: callInfo, completion: completion)
289289
} catch {
290290
completion?(.failure(error))
291291
}
@@ -294,17 +294,17 @@ open class NTLWebView: WKWebView {
294294
/// 调用 js bridge 方法,支持直接传入任意类型参数数组
295295
/// - Parameters:
296296
/// - method: JavaScript注册方法名,比如 "nameA.funcB"
297-
/// - args: 任意类型参数数组(会自动转换为JSONValue数组)
297+
/// - arguments: 任意类型参数数组(会自动转换为JSONValue数组)
298298
/// - completion: 完成回调
299299
/// - discussion: 便捷方法,支持传入[Any]类型的参数数组,自动转换为JSONValue
300-
public func callBridge(
301-
method: String,
302-
args: [Any],
300+
public func callHandler(
301+
_ method: String,
302+
arguments: [Any],
303303
completion: ((Result<JSONValue?, Error>) -> Void)? = nil
304304
) {
305305
do {
306-
let callInfo = try NTLCallInfo(method: method, callbackId: generateCallbackId(), anyArrayData: args)
307-
internalCallBridge(callInfo: callInfo, completion: completion)
306+
let callInfo = try NTLCallInfo(method: method, callbackId: generateCallbackId(), anyArrayData: arguments)
307+
internalcallHandler(callInfo: callInfo, completion: completion)
308308
} catch {
309309
completion?(.failure(error))
310310
}
@@ -313,15 +313,15 @@ open class NTLWebView: WKWebView {
313313
/// 调用 js bridge 方法,支持直接传入 Codable 参数数组并返回指定类型
314314
/// - Parameters:
315315
/// - method: JavaScript注册方法名,比如 "nameA.funcB"
316-
/// - args: Codable 参数数组(会自动编码为 JSONValue 数组)
316+
/// - arguments: Codable 参数数组(会自动编码为 JSONValue 数组)
317317
/// - completion: 完成回调,返回指定类型的结果
318318
/// - discussion: 便捷方法,自动将 Codable 对象数组转换为 JSONValue 数组
319-
public func callTypedBridge<T: Encodable, U: Decodable>(
320-
method: String,
321-
args: [T],
319+
public func callTypedHandler<T: Encodable, U: Decodable>(
320+
_ method: String,
321+
arguments: [T],
322322
completion: @escaping (Result<U, Error>) -> Void
323323
) {
324-
callBridge(method: method, args: args) { result in
324+
callHandler(method, arguments: arguments) { result in
325325
switch result {
326326
case .success(let jsonValue):
327327
do {
@@ -341,20 +341,20 @@ open class NTLWebView: WKWebView {
341341
/// - method: JavaScript注册方法名,比如 "nameA.funcB"
342342
/// - completion: 完成回调,返回指定类型的结果
343343
/// - discussion: 便捷方法,不需要传入参数数组
344-
public func callTypedBridge<U: Decodable>(
345-
method: String,
344+
public func callTypedHandler<U: Decodable>(
345+
_ method: String,
346346
completion: @escaping (Result<U, Error>) -> Void
347347
) {
348-
callTypedBridge(method: method, args: [String](), completion: completion)
348+
callTypedHandler(method, arguments: [String](), completion: completion)
349349
}
350350

351351
// MARK: - Internal Call Bridge Method
352352

353-
/// 内部统一的调用入口,所有 callBridge 重载方法最终都调用此方法
353+
/// 内部统一的调用入口,所有 callHandler 重载方法最终都调用此方法
354354
/// - Parameters:
355355
/// - callInfo: 调用信息
356356
/// - completion: 完成回调
357-
private func internalCallBridge(callInfo: NTLCallInfo, completion: ((Result<JSONValue?, Error>) -> Void)? = nil) {
357+
private func internalcallHandler(callInfo: NTLCallInfo, completion: ((Result<JSONValue?, Error>) -> Void)? = nil) {
358358
if isInitialized {
359359
// 如果已初始化,直接调度
360360
dispatchJavascriptCall(callInfo)

Tests/NTLBridgeTests/NTLWebViewTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ struct NTLWebViewTests {
360360
// MARK: - Generic Call Bridge Tests
361361

362362
@Test("Generic call bridge with string return")
363-
func genericCallBridgeWithStringReturn() async {
363+
func genericcallHandlerWithStringReturn() async {
364364
await MainActor.run {
365365
let webView = NTLWebView()
366366

367367
var result: String?
368368
var error: Error?
369369

370-
webView.callTypedBridge(method: "testStringMethod") { (response: Result<String, Error>) in
370+
webView.callTypedHandler("testStringMethod") { (response: Result<String, Error>) in
371371
switch response {
372372
case .success(let value):
373373
result = value
@@ -391,7 +391,7 @@ struct NTLWebViewTests {
391391
}
392392

393393
@Test("Generic call bridge with custom struct")
394-
func genericCallBridgeWithCustomStruct() async {
394+
func genericcallHandlerWithCustomStruct() async {
395395
await MainActor.run {
396396
let webView = NTLWebView()
397397

@@ -403,7 +403,7 @@ struct NTLWebViewTests {
403403
var result: TestUser?
404404
var error: Error?
405405

406-
webView.callTypedBridge(method: "testUserMethod") { (response: Result<TestUser, Error>) in
406+
webView.callTypedHandler("testUserMethod") { (response: Result<TestUser, Error>) in
407407
switch response {
408408
case .success(let value):
409409
result = value
@@ -431,7 +431,7 @@ struct NTLWebViewTests {
431431
}
432432

433433
@Test("Generic call bridge with array return")
434-
func genericCallBridgeWithArrayReturn() async {
434+
func genericcallHandlerWithArrayReturn() async {
435435
await MainActor.run {
436436
let webView = NTLWebView()
437437

@@ -443,7 +443,7 @@ struct NTLWebViewTests {
443443
var result: [TestItem]?
444444
var error: Error?
445445

446-
webView.callTypedBridge(method: "testArrayMethod") { (response: Result<[TestItem], Error>) in
446+
webView.callTypedHandler("testArrayMethod") { (response: Result<[TestItem], Error>) in
447447
switch response {
448448
case .success(let value):
449449
result = value
@@ -476,7 +476,7 @@ struct NTLWebViewTests {
476476
}
477477

478478
@Test("Generic call bridge with type conversion failure")
479-
func genericCallBridgeWithTypeConversionFailure() async {
479+
func genericcallHandlerWithTypeConversionFailure() async {
480480
await MainActor.run {
481481
let webView = NTLWebView()
482482

@@ -489,7 +489,7 @@ struct NTLWebViewTests {
489489
var result: StrictUser?
490490
var error: Error?
491491

492-
webView.callTypedBridge(method: "testIncompleteUserMethod") { (response: Result<StrictUser, Error>) in
492+
webView.callTypedHandler("testIncompleteUserMethod") { (response: Result<StrictUser, Error>) in
493493
switch response {
494494
case .success(let value):
495495
result = value
@@ -544,7 +544,7 @@ struct NTLWebViewTests {
544544
var syncCallCompleted = false
545545
var syncCallError: Error?
546546

547-
webView.callBridge(method: "test.cleanupMethod", args: [String]()) { result in
547+
webView.callHandler("test.cleanupMethod", arguments: [String]()) { result in
548548
switch result {
549549
case .success:
550550
syncCallCompleted = true
@@ -556,7 +556,7 @@ struct NTLWebViewTests {
556556
var asyncCallCompleted = false
557557
var asyncCallError: Error?
558558

559-
webView.callBridge(method: "test.asyncCleanupMethod", args: [String]()) { result in
559+
webView.callHandler("test.asyncCleanupMethod", arguments: [String]()) { result in
560560
switch result {
561561
case .success:
562562
asyncCallCompleted = true

0 commit comments

Comments
 (0)