-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathmain.swift
More file actions
28 lines (21 loc) · 722 Bytes
/
main.swift
File metadata and controls
28 lines (21 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import JavaScriptKit
let alert = JSObject.global.alert.function!
let document = JSObject.global.document
print("Hello from WASM, document title: \(document.title.string ?? "")")
var count = 0
var divElement = document.createElement("div")
divElement.innerText = .string("Count \(count)")
_ = document.body.appendChild(divElement)
var buttonElement = document.createElement("button")
buttonElement.innerText = "Click me"
buttonElement.onclick = JSValue.object(
JSClosure { _ in
count += 1
divElement.innerText = .string("Count \(count)")
return .undefined
}
)
_ = document.body.appendChild(buttonElement)
func print(_ message: String) {
_ = JSObject.global.console.log(message)
}