on master help sign in
Merge pull request #54 from fitzgen/use-local-js-snippets

Use the new local JS snippets support in wasm-bindgen to load change-list.js

commit6b0cbf4ae7716121e872e22884888cceb3ca3185 authorNick Fitzgerald <fitzgen@gmail.com> dateSat 6 Apr 2019, 11:14 (8 years ago) parent473b3c62cf2233
19 files changed+37−58
build.sh+2−2 examples/counter/README.md+1−1 examples/counter/index.html+3−3 examples/game-of-life/README.md+1−1 examples/game-of-life/index.html+3−3 examples/hello-world/README.md+1−1 examples/hello-world/index.html+3−3 examples/input-form/README.md+1−1 examples/input-form/index.html+3−3 examples/js-component/README.md+1−1 examples/js-component/index.html+3−3 examples/moire/README.md+1−1 examples/moire/index.html+3−3 examples/sierpinski-triangle/README.md+1−1 examples/sierpinski-triangle/index.html+4−4 examples/todomvc/README.md+1−1 examples/todomvc/index.html+3−3 js/change-list.js+1−5 src/change_list.rs+1−18
build.sh+2−2
@@ -4,8 +4,8 @@ cd $(dirname $0)
44set -eux
55
66cargo fmt --all || true
7−cargo check --all --target wasm32-unknown-unknown
7+cargo build --all --target wasm32-unknown-unknown
88
99for x in ./examples/*; do
10− wasm-pack build --target no-modules "$x"
10+ wasm-pack build --target web "$x"
1111done
examples/counter/README.md+1−1
@@ -9,7 +9,7 @@ See `src/lib.rs`.
99## Build
1010
1111```
12−wasm-pack build --target no-modules
12+wasm-pack build --target web
1313```
1414
1515## Serve
examples/counter/index.html+3−3
@@ -5,9 +5,9 @@
55 <title>Counter</title>
66 </head>
77 <body>
8− <script src="pkg/dodrio_counter.js"></script>
9− <script>
10− wasm_bindgen("pkg/dodrio_counter_bg.wasm");
8+ <script type="module">
9+ import init from "./pkg/dodrio_counter.js";
10+ init("./pkg/dodrio_counter_bg.wasm");
1111 </script>
1212 </body>
1313</html>
examples/game-of-life/README.md+1−1
@@ -11,7 +11,7 @@ See `src/lib.rs`.
1111## Build
1212
1313```
14−wasm-pack build --target no-modules
14+wasm-pack build --target web
1515```
1616
1717## Serve
examples/game-of-life/index.html+3−3
@@ -39,9 +39,9 @@
3939 </style>
4040 </head>
4141 <body>
42− <script src="pkg/dodrio_game_of_life.js"></script>
43− <script>
44− wasm_bindgen("pkg/dodrio_game_of_life_bg.wasm");
42+ <script type="module">
43+ import init from "./pkg/dodrio_game_of_life.js";
44+ init("./pkg/dodrio_game_of_life_bg.wasm");
4545 </script>
4646 </body>
4747</html>
examples/hello-world/README.md+1−1
@@ -9,7 +9,7 @@ See `src/lib.rs`.
99## Build
1010
1111```
12−wasm-pack build --target no-modules
12+wasm-pack build --target web
1313```
1414
1515## Serve
examples/hello-world/index.html+3−3
@@ -5,9 +5,9 @@
55 <title>Hello, World!</title>
66 </head>
77 <body>
8− <script src="pkg/dodrio_hello_world.js"></script>
9− <script>
10− wasm_bindgen("pkg/dodrio_hello_world_bg.wasm");
8+ <script type="module">
9+ import init from "./pkg/dodrio_hello_world.js";
10+ init("./pkg/dodrio_hello_world_bg.wasm");
1111 </script>
1212 </body>
1313</html>
examples/input-form/README.md+1−1
@@ -10,7 +10,7 @@ See `src/lib.rs`.
1010## Build
1111
1212```
13−wasm-pack build --target no-modules
13+wasm-pack build --target web
1414```
1515
1616## Serve
examples/input-form/index.html+3−3
@@ -5,9 +5,9 @@
55 <title>Input Form</title>
66 </head>
77 <body>
8− <script src="pkg/dodrio_input_form.js"></script>
9− <script>
10− wasm_bindgen("pkg/dodrio_input_form_bg.wasm");
8+ <script type="module">
9+ import init from "./pkg/dodrio_input_form.js";
10+ init("./pkg/dodrio_input_form_bg.wasm");
1111 </script>
1212 </body>
1313</html>
examples/js-component/README.md+1−1
@@ -11,7 +11,7 @@ See `src/lib.rs` for the Rust code.
1111## Build
1212
1313```
14−wasm-pack build --target no-modules
14+wasm-pack build --target web
1515```
1616
1717## Serve
examples/js-component/index.html+3−3
@@ -6,9 +6,9 @@
66 </head>
77 <body>
88 <script src="greeting.js"></script>
9− <script src="pkg/dodrio_js_component.js"></script>
10− <script>
11− wasm_bindgen("pkg/dodrio_js_component_bg.wasm");
9+ <script type="module">
10+ import init from "./pkg/dodrio_js_component.js";
11+ init("./pkg/dodrio_js_component_bg.wasm");
1212 </script>
1313 </body>
1414</html>
examples/moire/README.md+1−1
@@ -14,7 +14,7 @@ conversion and other color utilities.
1414## Build
1515
1616```
17−wasm-pack build --target no-modules
17+wasm-pack build --target web
1818```
1919
2020## Serve
examples/moire/index.html+3−3
@@ -42,9 +42,9 @@
4242 <body>
4343 <code>FPS: <output id="fps"></code></code>
4444 <div id="scene"></div>
45− <script src="pkg/dodrio_moire.js"></script>
46− <script>
47− wasm_bindgen("pkg/dodrio_moire_bg.wasm");
45+ <script type="module">
46+ import init from "./pkg/dodrio_moire.js";
47+ init("./pkg/dodrio_moire_bg.wasm");
4848 </script>
4949 <script>
5050 let lastTime = 0
examples/sierpinski-triangle/README.md+1−1
@@ -12,7 +12,7 @@ See `src/lib.rs`.
1212## Build
1313
1414```
15−wasm-pack build --target no-modules
15+wasm-pack build --target web
1616```
1717
1818## Serve
examples/sierpinski-triangle/index.html+4−4
@@ -39,9 +39,9 @@
3939 <code>FPS: <output id="fps">...</output></code>
4040 <div id="scene"></div>
4141
42− <script src="pkg/dodrio_sierpinski.js"></script>
43− <script>
44− wasm_bindgen("pkg/dodrio_sierpinski_bg.wasm");
42+ <script type="module">
43+ import init from "./pkg/dodrio_sierpinski.js";
44+ init("./pkg/dodrio_sierpinski_bg.wasm");
4545 </script>
4646
4747 <script>
@@ -66,4 +66,4 @@
6666 </script>
6767</body>
6868
69−</html>
69+</html>
examples/todomvc/README.md+1−1
@@ -21,7 +21,7 @@ most important are:
2121## Build
2222
2323```
24−wasm-pack build --target no-modules
24+wasm-pack build --target web
2525```
2626
2727## Serve
examples/todomvc/index.html+3−3
@@ -13,9 +13,9 @@
1313 <footer class="info">
1414 <p>Double-click to edit a todo</p>
1515 </footer>
16− <script src="pkg/dodrio_todomvc.js"></script>
17− <script>
18− wasm_bindgen("pkg/dodrio_todomvc_bg.wasm");
16+ <script type="module">
17+ import init from "./pkg/dodrio_todomvc.js";
18+ init("./pkg/dodrio_todomvc_bg.wasm");
1919 </script>
2020 </body>
2121</html>
js/change-list.js+1−5
@@ -199,8 +199,7 @@ const OP_TABLE = [
199199 }
200200];
201201
202−// export
203−class ChangeList {
202+export class ChangeList {
204203 constructor(container) {
205204 this.trampoline = null;
206205 this.container = container;
@@ -284,6 +283,3 @@ class ChangeList {
284283 }
285284 }
286285}
287−window.ChangeList = ChangeList;
288−
289−//# sourceURL=dodrio/change-list.js
src/change_list.rs+1−18
@@ -16,12 +16,10 @@ pub mod js {
1616 pub fn add_change_list_range(&self, _start: usize, _len: usize) {}
1717 pub fn init_events_trampoline(&self, _trampoline: &crate::EventsTrampoline) {}
1818 }
19−
20− pub fn eval_change_list() {}
2119 } else {
2220 use wasm_bindgen::prelude::*;
2321
24− #[wasm_bindgen]
22+ #[wasm_bindgen(module = "/js/change-list.js")]
2523 extern "C" {
2624 #[derive(Clone, Debug)]
2725 pub type ChangeList;
@@ -44,20 +42,6 @@ pub mod js {
4442 trampoline: &crate::EventsTrampoline,
4543 );
4644 }
47−
48− pub fn eval_change_list() {
49− use std::sync::Once;
50− // XXX: Because wasm-bindgen-test doesn't support third party JS
51− // dependencies, we can't use `wasm_bindgen(module = "...")` for our
52− // `ChangeList` JS import. Instead, this *should* be a local JS snippet,
53− // but that isn't implemented yet:
54− // https://github.com/rustwasm/rfcs/pull/6
55− static EVAL: Once = Once::new();
56− EVAL.call_once(|| {
57− js_sys::eval(include_str!("../js/change-list.js"))
58− .expect_throw("should eval change-list.js OK");
59− });
60− }
6145 }
6246 }
6347}
@@ -94,7 +78,6 @@ impl fmt::Debug for ChangeList {
9478
9579impl ChangeList {
9680 pub(crate) fn new(container: &crate::Element) -> ChangeList {
97− js::eval_change_list();
9881 let bump = Bump::new();
9982 let strings_cache = FxHashMap::default();
10083 let js = js::ChangeList::new(container);