Merge pull request #907 from alexcrichton/catch-errors

Add `catch(console.error)` to all examples
This commit is contained in:
Alex Crichton 2018-09-28 21:31:14 -07:00 committed by GitHub
commit 10fce93c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 91 additions and 69 deletions

View File

@ -1,4 +1,6 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example // example
const rust = import('./add'); const rust = import('./add');
rust.then(m => alert('1 + 2 = ' + m.add(1, 2))); rust
.then(m => alert('1 + 2 = ' + m.add(1, 2)))
.catch(console.error);

View File

@ -1,5 +1,5 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example. // example.
import('./canvas').then(canvas => { import('./canvas')
canvas.draw(); .then(canvas => canvas.draw())
}); .catch(console.error);

View File

@ -4,13 +4,15 @@ let imp = import('./char.js');
let mod; let mod;
let counters = []; let counters = [];
imp.then(wasm => { imp
mod = wasm; .then(wasm => {
addCounter(); mod = wasm;
let b = document.getElementById('add-counter'); addCounter();
if (!b) throw new Error('Unable to find #add-counter'); let b = document.getElementById('add-counter');
b.addEventListener('click', ev => addCounter()); if (!b) throw new Error('Unable to find #add-counter');
}); b.addEventListener('click', ev => addCounter());
})
.catch(console.error);
function addCounter() { function addCounter() {
let ctr = mod.Counter.new(randomChar(), 0); let ctr = mod.Counter.new(randomChar(), 0);

View File

@ -1,4 +1,6 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example // example
const rust = import('./closures'); const rust = import('./closures');
rust.then(m => m.run()); rust
.then(m => m.run())
.catch(console.error);

View File

@ -2,4 +2,6 @@
// example // example
const rust = import('./console_log'); const rust = import('./console_log');
rust.then(m => m.run()); rust
.then(m => m.run())
.catch(console.error);

View File

@ -1,4 +1,6 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example // example
const rust = import('./dom'); const rust = import('./dom');
rust.then(m => m.run()); rust
.then(m => m.run())
.catch(console.error);

View File

@ -1,11 +1,12 @@
const rust = import('./fetch'); const rust = import('./fetch');
rust
.then(m => {
m.run().then((data) => {
console.log(data);
rust.then(m => { console.log("The latest commit to the wasm-bindgen %s branch is:", data.name);
m.run().then((data) => { console.log("%s, authored by %s <%s>", data.commit.sha, data.commit.commit.author.name, data.commit.commit.author.email);
console.log(data); })
})
console.log("The latest commit to the wasm-bindgen %s branch is:", data.name); .catch(console.error);
console.log("%s, authored by %s <%s>", data.commit.sha, data.commit.commit.author.name, data.commit.commit.author.email);
})
});

View File

@ -3,4 +3,6 @@
// will work here one day as well! // will work here one day as well!
const rust = import('./hello_world'); const rust = import('./hello_world');
rust.then(m => m.greet('World!')); rust
.then(m => m.greet('World!'))
.catch(console.error);

View File

@ -2,4 +2,6 @@
// example // example
const rust = import('./import_js'); const rust = import('./import_js');
rust.then(m => m.run()); rust
.then(m => m.run())
.catch(console.error);

View File

@ -14,4 +14,5 @@ import('./julia_set')
}); });
wasm.draw(ctx, 600, 600, -0.15, 0.65); wasm.draw(ctx, 600, 600, -0.15, 0.65);
}); })
.catch(console.error);

View File

@ -1,5 +1,5 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example. // example.
import('./wasm_bindgen_paint').then(paint => { import('./wasm_bindgen_paint')
paint.main(); .then(paint => paint.main())
}); .catch(console.error);

View File

@ -1,4 +1,6 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example // example
const rust = import('./performance'); const rust = import('./performance');
rust.then(m => m.run()); rust
.then(m => m.run())
.catch(console.error);

View File

@ -1,4 +1,6 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example // example
const rust = import('./wasm_in_wasm'); const rust = import('./wasm_in_wasm');
rust.then(m => m.run()); rust
.then(m => m.run())
.catch(console.error);

View File

@ -1,38 +1,40 @@
import('./webaudio').then(rust_module => { import('./webaudio')
let fm = null; .then(rust_module => {
let fm = null;
const play_button = document.getElementById("play"); const play_button = document.getElementById("play");
play_button.addEventListener("click", event => { play_button.addEventListener("click", event => {
if (fm === null) { if (fm === null) {
fm = new rust_module.FmOsc(); fm = new rust_module.FmOsc();
fm.set_note(50); fm.set_note(50);
fm.set_fm_frequency(0); fm.set_fm_frequency(0);
fm.set_fm_amount(0); fm.set_fm_amount(0);
fm.set_gain(0.8); fm.set_gain(0.8);
} else { } else {
fm.free(); fm.free();
fm = null; fm = null;
} }
}); });
const primary_slider = document.getElementById("primary_input"); const primary_slider = document.getElementById("primary_input");
primary_slider.addEventListener("input", event => { primary_slider.addEventListener("input", event => {
if (fm) { if (fm) {
fm.set_note(event.target.value); fm.set_note(event.target.value);
} }
}); });
const fm_freq = document.getElementById("fm_freq"); const fm_freq = document.getElementById("fm_freq");
fm_freq.addEventListener("input", event => { fm_freq.addEventListener("input", event => {
if (fm) { if (fm) {
fm.set_fm_frequency(event.target.value); fm.set_fm_frequency(event.target.value);
} }
}); });
const fm_amount = document.getElementById("fm_amount"); const fm_amount = document.getElementById("fm_amount");
fm_amount.addEventListener("input", event => { fm_amount.addEventListener("input", event => {
if (fm) { if (fm) {
fm.set_fm_amount(event.target.value); fm.set_fm_amount(event.target.value);
} }
}); });
}); })
.catch(console.error);

View File

@ -1,5 +1,5 @@
// For more comments about what's going on here, check out the `hello_world` // For more comments about what's going on here, check out the `hello_world`
// example. // example.
import('./webgl').then(webgl => { import('./webgl')
webgl.draw(); .then(webgl => webgl.draw())
}); .catch(console.error);