Add catch(console.error) to all examples

Some examples have been failing to load in some browsers, and this
ensures that whenever the promise to load Rust code fails we log any
errors happening instead of accidentally failing silently.

This helped debug a bit in #897
This commit is contained in:
Alex Crichton
2018-09-28 13:54:29 -07:00
parent 11bcaf42d5
commit bc36b6f84b
15 changed files with 91 additions and 69 deletions

View File

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