on master help sign in
Merge pull request #54 from fitzgen/use-local-js-snippets
6b0cbf4Nick Fitzgerald
build.sh+2−2
@@ -4,8 +4,8 @@ cd $(dirname $0)
4set -eux
4set -eux
5
5
6cargo fmt --all || true
6cargo fmt --all || true
7−cargo check --all --target wasm32-unknown-unknown
7+cargo build --all --target wasm32-unknown-unknown
8
8
9for x in ./examples/*; do
9for x in ./examples/*; do
10− wasm-pack build --target no-modules "$x"
10+ wasm-pack build --target web "$x"
11done
11done
examples/counter/README.md+1−1
@@ -9,7 +9,7 @@ See `src/lib.rs`.
9## Build
9## Build
10
10
11```
11```
12−wasm-pack build --target no-modules
12+wasm-pack build --target web
13```
13```
14
14
15## Serve
15## Serve
examples/counter/index.html+3−3
@@ -5,9 +5,9 @@
5 <title>Counter</title>
5 <title>Counter</title>
6 </head>
6 </head>
7 <body>
7 <body>
8+ <script type="module">
8− <script src="pkg/dodrio_counter.js"></script>
9+ import init from "./pkg/dodrio_counter.js";
9− <script>
10− wasm_bindgen("pkg/dodrio_counter_bg.wasm");
10+ init("./pkg/dodrio_counter_bg.wasm");
11 </script>
11 </script>
12 </body>
12 </body>
13</html>
13</html>
examples/game-of-life/README.md+1−1
@@ -11,7 +11,7 @@ See `src/lib.rs`.
11## Build
11## Build
12
12
13```
13```
14−wasm-pack build --target no-modules
14+wasm-pack build --target web
15```
15```
16
16
17## Serve
17## Serve
examples/game-of-life/index.html+3−3
@@ -39,9 +39,9 @@
39 </style>
39 </style>
40 </head>
40 </head>
41 <body>
41 <body>
42+ <script type="module">
42− <script src="pkg/dodrio_game_of_life.js"></script>
43+ import init from "./pkg/dodrio_game_of_life.js";
43− <script>
44− wasm_bindgen("pkg/dodrio_game_of_life_bg.wasm");
44+ init("./pkg/dodrio_game_of_life_bg.wasm");
45 </script>
45 </script>
46 </body>
46 </body>
47</html>
47</html>
examples/hello-world/README.md+1−1
@@ -9,7 +9,7 @@ See `src/lib.rs`.
9## Build
9## Build
10
10
11```
11```
12−wasm-pack build --target no-modules
12+wasm-pack build --target web
13```
13```
14
14
15## Serve
15## Serve
examples/hello-world/index.html+3−3
@@ -5,9 +5,9 @@
5 <title>Hello, World!</title>
5 <title>Hello, World!</title>
6 </head>
6 </head>
7 <body>
7 <body>
8+ <script type="module">
8− <script src="pkg/dodrio_hello_world.js"></script>
9+ import init from "./pkg/dodrio_hello_world.js";
9− <script>
10− wasm_bindgen("pkg/dodrio_hello_world_bg.wasm");
10+ init("./pkg/dodrio_hello_world_bg.wasm");
11 </script>
11 </script>
12 </body>
12 </body>
13</html>
13</html>
examples/input-form/README.md+1−1
@@ -10,7 +10,7 @@ See `src/lib.rs`.
10## Build
10## Build
11
11
12```
12```
13−wasm-pack build --target no-modules
13+wasm-pack build --target web
14```
14```
15
15
16## Serve
16## Serve
examples/input-form/index.html+3−3
@@ -5,9 +5,9 @@
5 <title>Input Form</title>
5 <title>Input Form</title>
6 </head>
6 </head>
7 <body>
7 <body>
8+ <script type="module">
8− <script src="pkg/dodrio_input_form.js"></script>
9+ import init from "./pkg/dodrio_input_form.js";
9− <script>
10− wasm_bindgen("pkg/dodrio_input_form_bg.wasm");
10+ init("./pkg/dodrio_input_form_bg.wasm");
11 </script>
11 </script>
12 </body>
12 </body>
13</html>
13</html>
examples/js-component/README.md+1−1
@@ -11,7 +11,7 @@ See `src/lib.rs` for the Rust code.
11## Build
11## Build
12
12
13```
13```
14−wasm-pack build --target no-modules
14+wasm-pack build --target web
15```
15```
16
16
17## Serve
17## Serve
examples/js-component/index.html+3−3
@@ -6,9 +6,9 @@
6 </head>
6 </head>
7 <body>
7 <body>
8 <script src="greeting.js"></script>
8 <script src="greeting.js"></script>
9+ <script type="module">
9− <script src="pkg/dodrio_js_component.js"></script>
10+ import init from "./pkg/dodrio_js_component.js";
10− <script>
11− wasm_bindgen("pkg/dodrio_js_component_bg.wasm");
11+ init("./pkg/dodrio_js_component_bg.wasm");
12 </script>
12 </script>
13 </body>
13 </body>
14</html>
14</html>
examples/moire/README.md+1−1
@@ -14,7 +14,7 @@ conversion and other color utilities.
14## Build
14## Build
15
15
16```
16```
17−wasm-pack build --target no-modules
17+wasm-pack build --target web
18```
18```
19
19
20## Serve
20## Serve
examples/moire/index.html+3−3
@@ -42,9 +42,9 @@
42 <body>
42 <body>
43 <code>FPS: <output id="fps"></code></code>
43 <code>FPS: <output id="fps"></code></code>
44 <div id="scene"></div>
44 <div id="scene"></div>
45+ <script type="module">
45− <script src="pkg/dodrio_moire.js"></script>
46+ import init from "./pkg/dodrio_moire.js";
46− <script>
47− wasm_bindgen("pkg/dodrio_moire_bg.wasm");
47+ init("./pkg/dodrio_moire_bg.wasm");
48 </script>
48 </script>
49 <script>
49 <script>
50 let lastTime = 0
50 let lastTime = 0
examples/sierpinski-triangle/README.md+1−1
@@ -12,7 +12,7 @@ See `src/lib.rs`.
12## Build
12## Build
13
13
14```
14```
15−wasm-pack build --target no-modules
15+wasm-pack build --target web
16```
16```
17
17
18## Serve
18## Serve
examples/sierpinski-triangle/index.html+4−4
@@ -39,9 +39,9 @@
39 <code>FPS: <output id="fps">...</output></code>
39 <code>FPS: <output id="fps">...</output></code>
40 <div id="scene"></div>
40 <div id="scene"></div>
41
41
42+ <script type="module">
42− <script src="pkg/dodrio_sierpinski.js"></script>
43+ import init from "./pkg/dodrio_sierpinski.js";
43− <script>
44− wasm_bindgen("pkg/dodrio_sierpinski_bg.wasm");
44+ init("./pkg/dodrio_sierpinski_bg.wasm");
45 </script>
45 </script>
46
46
47 <script>
47 <script>
@@ -66,4 +66,4 @@
66 </script>
66 </script>
67</body>
67</body>
68
68
69−</html>
69+</html>
examples/todomvc/README.md+1−1
@@ -21,7 +21,7 @@ most important are:
21## Build
21## Build
22
22
23```
23```
24−wasm-pack build --target no-modules
24+wasm-pack build --target web
25```
25```
26
26
27## Serve
27## Serve
examples/todomvc/index.html+3−3
@@ -13,9 +13,9 @@
13 <footer class="info">
13 <footer class="info">
14 <p>Double-click to edit a todo</p>
14 <p>Double-click to edit a todo</p>
15 </footer>
15 </footer>
16+ <script type="module">
16− <script src="pkg/dodrio_todomvc.js"></script>
17+ import init from "./pkg/dodrio_todomvc.js";
17− <script>
18− wasm_bindgen("pkg/dodrio_todomvc_bg.wasm");
18+ init("./pkg/dodrio_todomvc_bg.wasm");
19 </script>
19 </script>
20 </body>
20 </body>
21</html>
21</html>
js/change-list.js+1−5
@@ -199,8 +199,7 @@ const OP_TABLE = [
199 }
199 }
200];
200];
201
201
202−// export
203−class ChangeList {
202+export class ChangeList {
204 constructor(container) {
203 constructor(container) {
205 this.trampoline = null;
204 this.trampoline = null;
206 this.container = container;
205 this.container = container;
@@ -284,6 +283,3 @@ class ChangeList {
284 }
283 }
285 }
284 }
286}
285}
287−window.ChangeList = ChangeList;
288−
289−//# sourceURL=dodrio/change-list.js
src/change_list.rs+1−18
@@ -16,12 +16,10 @@ pub mod js {
16 pub fn add_change_list_range(&self, _start: usize, _len: usize) {}
16 pub fn add_change_list_range(&self, _start: usize, _len: usize) {}
17 pub fn init_events_trampoline(&self, _trampoline: &crate::EventsTrampoline) {}
17 pub fn init_events_trampoline(&self, _trampoline: &crate::EventsTrampoline) {}
18 }
18 }
19−
20− pub fn eval_change_list() {}
21 } else {
19 } else {
22 use wasm_bindgen::prelude::*;
20 use wasm_bindgen::prelude::*;
23
21
24− #[wasm_bindgen]
22+ #[wasm_bindgen(module = "/js/change-list.js")]
25 extern "C" {
23 extern "C" {
26 #[derive(Clone, Debug)]
24 #[derive(Clone, Debug)]
27 pub type ChangeList;
25 pub type ChangeList;
@@ -44,20 +42,6 @@ pub mod js {
44 trampoline: &crate::EventsTrampoline,
42 trampoline: &crate::EventsTrampoline,
45 );
43 );
46 }
44 }
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− }
61 }
45 }
62 }
46 }
63}
47}
@@ -94,7 +78,6 @@ impl fmt::Debug for ChangeList {
94
78
95impl ChangeList {
79impl ChangeList {
96 pub(crate) fn new(container: &crate::Element) -> ChangeList {
80 pub(crate) fn new(container: &crate::Element) -> ChangeList {
97− js::eval_change_list();
98 let bump = Bump::new();
81 let bump = Bump::new();
99 let strings_cache = FxHashMap::default();
82 let strings_cache = FxHashMap::default();
100 let js = js::ChangeList::new(container);
83 let js = js::ChangeList::new(container);