Skip to content

Commit 9f34011

Browse files
Update Example
1 parent 4df1d54 commit 9f34011

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

Diff for: Example/JavaScriptKitExample/Sources/JavaScriptKitExample/main.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ divElement.innerText = "Hello, world"
88
let body = document.body.object!
99
_ = body.appendChild!(divElement)
1010

11-
alert("Swift is running on browser!")
11+
let buttonElement = document.createElement!("button").object!
12+
buttonElement.innerText = "Click me!"
13+
buttonElement.onclick = .function { _ in
14+
alert("Swift is running on browser!")
15+
}
16+
17+
_ = body.appendChild!(buttonElement)

Diff for: Example/index.html renamed to Example/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<title>Getting Started</title>
55
</head>
66
<body>
7-
<script src="./dist/main.js"></script>
7+
<script src="main.js"></script>
88
</body>
99
</html>

Diff for: Example/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let wasi = new WASI({
1717

1818
const startWasiTask = async () => {
1919
// Fetch our Wasm File
20-
const response = await fetch("./dist/JavaScriptKitExample.wasm");
20+
const response = await fetch("JavaScriptKitExample.wasm");
2121
const responseArrayBuffer = await response.arrayBuffer();
2222

2323
// Instantiate the WebAssembly file

Diff for: Example/webpack.config.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports = {
99
path: outputPath,
1010
},
1111
devServer: {
12-
hot: true
13-
}
12+
inline: true,
13+
watchContentBase: true,
14+
contentBase: [
15+
path.join(__dirname, 'public'),
16+
path.join(__dirname, 'dist'),
17+
],
18+
},
1419
};

Diff for: Sources/JavaScriptKit/JSValue.swift

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public enum JSValue: Equatable {
4444
}
4545
}
4646

47+
extension JSValue {
48+
public static func function(_ body: @escaping ([JSValue]) -> JSValue) -> JSValue {
49+
.function(JSFunctionRef.from(body))
50+
}
51+
}
52+
4753
extension JSValue: ExpressibleByStringLiteral {
4854
public init(stringLiteral value: String) {
4955
self = .string(value)

0 commit comments

Comments
 (0)