This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[wasm_bindgen] | |
extern "C" { | |
#[wasm_bindgen(js_namespace = console)] | |
fn log(s: &str); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" { | |
fn name() -> String; | |
type MyClass; | |
#[wasm_bindgen(constructor)] | |
fn new() -> MyClass; | |
#[wasm_bindgen(method, getter)] | |
fn number(this: &MyClass) -> u32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use wasm_bindgen::prelude::*; | |
#[wasm_bindgen(module = "/defined-in-js.js")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function name() { | |
return 'World'; | |
} | |
export class MyClass { | |
constructor() { | |
this._number = 42; | |
} | |
get number() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const loadPageInto = (main) => { | |
main.innerText = 'Video game page'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
link.addEventListener('click', async (event) => { | |
event.preventDefault(); | |
try { | |
const module = await import(`/${link.dataset.entryModule}.mjs`); | |
// The module exports a function named `loadPageInto`. | |
module.loadPageInto(main); | |
} catch (error) { | |
main.textContent = error.message; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav> | |
<a href="books.html" data-entry-module="books">Books</a> | |
<a href="movies.html" data-entry-module="movies">Movies</a> | |
<a href="video-games.html" data-entry-module="video-games">Video Games</a> | |
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const module = await import(`/${link.dataset.entryModule}.mjs`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="module"> | |
import * as module from './utils.mjs'; | |
module.default(); | |
// → logs 'Hi from the default export!' | |
module.doStuff(); | |
// → logs 'Doing stuff…' | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Default export | |
export default () => { | |
console.log('Hi from the default export!'); | |
}; | |
// Named export `doStuff` | |
export const doStuff = () => { | |
console.log('Doing stuff…'); | |
}; |