Skip to content

Commit ed482fe

Browse files
BridgeJS: Update examples and documentation for @JS init
1 parent 7df801c commit ed482fe

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Examples/ExportSwift/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js";
22
const { exports } = await init({});
33

44
const Greeter = exports.Greeter;
5-
const greeter = new Greeter("World");
5+
const greeter = Greeter.init("World");
66
const circle = exports.renderCircleSVG(100);
77

88
// Display the results

Examples/PlayBridgeJS/Sources/JavaScript/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class BridgeJSPlayground {
5252
createTS2Skeleton: this.createTS2Skeleton
5353
}
5454
});
55-
this.playBridgeJS = new exports.PlayBridgeJS();
55+
this.playBridgeJS = exports.PlayBridgeJS.init();
5656
console.log('BridgeJS initialized successfully');
5757
} catch (error) {
5858
console.error('Failed to initialize BridgeJS:', error);
@@ -162,4 +162,4 @@ export class BridgeJSPlayground {
162162
hideError() {
163163
this.errorDisplay.classList.remove('show');
164164
}
165-
}
165+
}

Sources/JavaScriptKit/Documentation.docc/Articles/Exporting-Swift-to-JavaScript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ In JavaScript:
133133
import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js";
134134
const { exports } = await init({});
135135

136-
const cart = new exports.ShoppingCart();
136+
const cart = exports.ShoppingCart.init();
137137
cart.addItem("Laptop", 999.99, 1);
138138
cart.addItem("Mouse", 24.99, 2);
139139
console.log(`Items in cart: ${cart.getItemCount()}`);
@@ -158,7 +158,7 @@ export interface ShoppingCart extends SwiftHeapObject {
158158

159159
export type Exports = {
160160
ShoppingCart: {
161-
new(): ShoppingCart;
161+
init(): ShoppingCart;
162162
}
163163
}
164164
```
@@ -175,8 +175,8 @@ You can export functions to specific namespaces by providing a namespace paramet
175175
import JavaScriptKit
176176

177177
// Export a function to a custom namespace
178-
@JS(namespace: "MyModule.Utils") func namespacedFunction() -> String {
179-
return "namespaced"
178+
@JS(namespace: "MyModule.Utils") func namespacedFunction() -> String {
179+
return "namespaced"
180180
}
181181
```
182182

0 commit comments

Comments
 (0)