mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 05:52:21 +03:00
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:
parent
11bcaf42d5
commit
bc36b6f84b
@ -1,4 +1,6 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example
|
||||
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);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example.
|
||||
import('./canvas').then(canvas => {
|
||||
canvas.draw();
|
||||
});
|
||||
import('./canvas')
|
||||
.then(canvas => canvas.draw())
|
||||
.catch(console.error);
|
||||
|
@ -4,13 +4,15 @@ let imp = import('./char.js');
|
||||
let mod;
|
||||
|
||||
let counters = [];
|
||||
imp.then(wasm => {
|
||||
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);
|
||||
|
@ -1,4 +1,6 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example
|
||||
const rust = import('./closures');
|
||||
rust.then(m => m.run());
|
||||
rust
|
||||
.then(m => m.run())
|
||||
.catch(console.error);
|
||||
|
@ -2,4 +2,6 @@
|
||||
// example
|
||||
const rust = import('./console_log');
|
||||
|
||||
rust.then(m => m.run());
|
||||
rust
|
||||
.then(m => m.run())
|
||||
.catch(console.error);
|
||||
|
@ -1,4 +1,6 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example
|
||||
const rust = import('./dom');
|
||||
rust.then(m => m.run());
|
||||
rust
|
||||
.then(m => m.run())
|
||||
.catch(console.error);
|
||||
|
@ -1,11 +1,12 @@
|
||||
const rust = import('./fetch');
|
||||
|
||||
|
||||
rust.then(m => {
|
||||
rust
|
||||
.then(m => {
|
||||
m.run().then((data) => {
|
||||
console.log(data);
|
||||
|
||||
console.log("The latest commit to the wasm-bindgen %s branch is:", data.name);
|
||||
console.log("%s, authored by %s <%s>", data.commit.sha, data.commit.commit.author.name, data.commit.commit.author.email);
|
||||
})
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
@ -3,4 +3,6 @@
|
||||
// will work here one day as well!
|
||||
const rust = import('./hello_world');
|
||||
|
||||
rust.then(m => m.greet('World!'));
|
||||
rust
|
||||
.then(m => m.greet('World!'))
|
||||
.catch(console.error);
|
||||
|
@ -2,4 +2,6 @@
|
||||
// example
|
||||
const rust = import('./import_js');
|
||||
|
||||
rust.then(m => m.run());
|
||||
rust
|
||||
.then(m => m.run())
|
||||
.catch(console.error);
|
||||
|
@ -14,4 +14,5 @@ import('./julia_set')
|
||||
});
|
||||
|
||||
wasm.draw(ctx, 600, 600, -0.15, 0.65);
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example.
|
||||
import('./wasm_bindgen_paint').then(paint => {
|
||||
paint.main();
|
||||
});
|
||||
import('./wasm_bindgen_paint')
|
||||
.then(paint => paint.main())
|
||||
.catch(console.error);
|
||||
|
@ -1,4 +1,6 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example
|
||||
const rust = import('./performance');
|
||||
rust.then(m => m.run());
|
||||
rust
|
||||
.then(m => m.run())
|
||||
.catch(console.error);
|
||||
|
@ -1,4 +1,6 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example
|
||||
const rust = import('./wasm_in_wasm');
|
||||
rust.then(m => m.run());
|
||||
rust
|
||||
.then(m => m.run())
|
||||
.catch(console.error);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import('./webaudio').then(rust_module => {
|
||||
import('./webaudio')
|
||||
.then(rust_module => {
|
||||
let fm = null;
|
||||
|
||||
const play_button = document.getElementById("play");
|
||||
@ -35,4 +36,5 @@ import('./webaudio').then(rust_module => {
|
||||
fm.set_fm_amount(event.target.value);
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example.
|
||||
import('./webgl').then(webgl => {
|
||||
webgl.draw();
|
||||
});
|
||||
import('./webgl')
|
||||
.then(webgl => webgl.draw())
|
||||
.catch(console.error);
|
||||
|
Loading…
Reference in New Issue
Block a user