Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major API change on JSClosure #113

Merged
merged 11 commits into from
Jan 4, 2021
Prev Previous commit
Next Next commit
Add compatibility method for JSValue.function(_:JSClosure)
  • Loading branch information
kateinoigakukun committed Jan 3, 2021
commit aed4312ddf77d1cfe81c186ff352c03cd5f8b505
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ buttonElement.innerText = "Click me!"
let listener = JSClosure { _ in
alert("Swift is running on browser!")
}
buttonElement.onclick = .function(listener)
buttonElement.onclick = .object(listener)

_ = document.body.appendChild(buttonElement)
5 changes: 5 additions & 0 deletions Sources/JavaScriptKit/JSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ extension JSValue {
public static func function(_ body: @escaping ([JSValue]) -> JSValue) -> JSValue {
.object(JSClosure(body))
}

@available(*, deprecated, renamed: "object", message: "JSClosure is not a subclass of JSFunction now")
kateinoigakukun marked this conversation as resolved.
Show resolved Hide resolved
public static func function(_ closure: JSClosure) -> JSValue {
.object(closure)
}
}

extension JSValue: ExpressibleByStringLiteral {
Expand Down