@@ -8,14 +8,17 @@ use dodrio::{
88 bumpalo::{self, Bump},
99 Attribute, Listener, Node, NodeKey, Render, RenderContext, RootRender, VdomWeak,
1010};
11+use gloo::net::{self, http::Request};
1112use nock::{
1213 cue::cue_bytes,
1314 interpreter::{generate_interpreter_context, ram_ttanks, slam, InterpreterContext},
1415 noun::{cell, Noun},
1516};
1617use wasm_bindgen::prelude::*;
17−use wasm_bindgen_futures::JsFuture;
18−use web_sys::{console::error_1, Element};
18+use web_sys::{
19+ console::{error_1, log_1},
20+ Element,
21+};
1922
2023#[wasm_bindgen]
2124extern "C" {
@@ -162,14 +165,17 @@ fn tape_to_bump_str<'a>(bump: &'a Bump, non: &Rc<Noun>) -> &'a str {
162165#[wasm_bindgen]
163166pub async fn main(path: &str) {
164167 let nock = load_nock(path).await.unwrap_or_else(|err| {
165− error_1(&err);
168+ error(&*err.to_string());
166169 panic!("Could not load nock.")
167170 });
168171
169172 let document = gloo::utils::document();
170173 let output_el: Element = document.get_element_by_id("output").unwrap();
171174
172− let mut ctx = generate_interpreter_context();
175+ let mut ctx = InterpreterContext {
176+ slog: |str: &String| log_1(&JsValue::from_str(&*str)),
177+ ..generate_interpreter_context()
178+ };
173179
174180 let model = slam(
175181 &mut ctx,
@@ -196,19 +202,10 @@ pub async fn main(path: &str) {
196202 .forget();
197203}
198204
199−pub async fn load_nock(path: &str) -> Result<Rc<Noun>, JsValue> {
200− let window = web_sys::window().unwrap();
201−
202− let resp = JsFuture::from(window.fetch_with_str(path)).await?;
203− assert!(resp.is_instance_of::<web_sys::Response>());
204− let resp: web_sys::Response = resp.dyn_into()?;
205− let blob = JsFuture::from(resp.blob()?).await?;
206− assert!(blob.is_instance_of::<web_sys::Blob>());
207− let blob: web_sys::Blob = blob.dyn_into()?;
208−
209− let nock = js_sys::Uint8Array::new(&JsFuture::from(blob.array_buffer()).await?).to_vec();
205+pub async fn load_nock(path: &str) -> Result<Rc<Noun>, net::Error> {
206+ let blob = Request::get(path).send().await?.binary().await?;
210207
211− let nock = cue_bytes(&*nock);
208+ let nock = cue_bytes(&*blob);
212209 let (_typ, nok) = nock.as_cell().unwrap();
213210
214211 Ok(nok.clone())