@@ -1,8 +1,12 @@
1+#![feature(iter_collect_into)]
3use std::rc::Rc;
4use std::rc::Rc;
5−use gloo::events::EventListener;
6+use dodrio::{
7+ bumpalo::{self, Bump},
8+ Attribute, Node, NodeKey, Render, RenderContext,
6use nock::{
10use nock::{
7 cue::cue_bytes,
11 cue::cue_bytes,
8 interpreter::{generate_interpreter_context, slam},
12 interpreter::{generate_interpreter_context, slam},
@@ -10,7 +14,7 @@ use nock::{
11use wasm_bindgen::prelude::*;
15use wasm_bindgen::prelude::*;
12use wasm_bindgen_futures::JsFuture;
16use wasm_bindgen_futures::JsFuture;
13−use web_sys::{Element, HtmlInputElement};
17+use web_sys::Element;
15#[wasm_bindgen]
19#[wasm_bindgen]
16extern "C" {
20extern "C" {
@@ -20,45 +24,89 @@ extern "C" {
20 fn log(s: &str);
24 fn log(s: &str);
23−#[wasm_bindgen]
27+struct WockApp {
24−pub fn greet() {
28+ nock: Rc<Noun>,
25− alert("Hello, wock-web!");
29+}
31+impl<'a> Render<'a> for WockApp {
32+ fn render(&self, cx: &mut dodrio::RenderContext<'a>) -> dodrio::Node<'a> {
33+ let mut ctx = generate_interpreter_context();
35+ let sail = slam(&mut ctx, &self.nock, &Rc::new(Noun::from_u32(0))).unwrap();
37+ render_sail(cx, &sail)
41+fn render_sail<'a>(ctx: &mut RenderContext<'a>, manx: &Rc<Noun>) -> Node<'a> {
42+ let (marx, marl) = manx.as_cell().unwrap();
43+ let (mane, mart) = marx.as_cell().unwrap();
48+ .map(|attr| attr.as_cell().unwrap())
49+ .find(|(key, _)| key.is_sig())
50+ .map(|(_, value)| tape_to_bump_str(ctx.bump, value))
54+ let mut children = bumpalo::collections::Vec::new_in(&ctx.bump);
56+ .map(|child| render_sail(ctx, child))
57+ .collect_into(&mut children);
59+ let mut attributes = bumpalo::collections::Vec::new_in(ctx.bump);
62+ let (name, value) = attr.as_cell().unwrap();
64+ name: cord_to_bump_str(ctx.bump, name),
65+ value: cord_to_bump_str(ctx.bump, value),
68+ .collect_into(&mut attributes);
70+ let listeners = bumpalo::collections::Vec::new_in(ctx.bump);
75+ cord_to_bump_str(ctx.bump, mane),
76+ listeners.into_bump_slice(),
77+ attributes.into_bump_slice(),
78+ children.into_bump_slice(),
28−static mut LISTENER: Option<EventListener> = None;
84+fn cord_to_bump_str<'a>(bump: &'a Bump, non: &Rc<Noun>) -> &'a str {
86+ bumpalo::collections::Vec::from_iter_in(non.as_bytes().unwrap().iter().cloned(), bump);
87+ &*bumpalo::collections::String::from_utf8(bytes)
92+fn tape_to_bump_str<'a>(bump: &'a Bump, non: &Rc<Noun>) -> &'a str {
93+ let bytes = bumpalo::collections::Vec::from_iter_in(
94+ non.list_iter().map(|char| char.as_u32().unwrap() as u8),
97+ &*bumpalo::collections::String::from_utf8(bytes)
30#[wasm_bindgen]
102#[wasm_bindgen]
31pub async fn main(path: &str) {
103pub async fn main(path: &str) {
32 let nock = load_nock(path).await;
104 let nock = load_nock(path).await;
34− let mut ctx = generate_interpreter_context();
36 let document = gloo::utils::document();
106 let document = gloo::utils::document();
37− let input_element: web_sys::HtmlInputElement = document
38− .get_element_by_id("input")
42 let output_el: Element = document.get_element_by_id("output").unwrap();
107 let output_el: Element = document.get_element_by_id("output").unwrap();
44− LISTENER = Some(EventListener::new(&input_element, "input", move |ev| {
45− let el: HtmlInputElement = ev.target().unwrap().dyn_into().unwrap();
50− &Rc::new(Noun::from_bytes(el.value().as_bytes())),
54− let foo = bar.as_bytes().unwrap();
55− let qux = String::from_utf8(foo).unwrap();
57− output_el.set_inner_html(&*qux);
61− // window.get_eleme
109+ dodrio::Vdom::new(&output_el, WockApp { nock }).forget();
64pub async fn load_nock(path: &str) -> Rc<Noun> {
112pub async fn load_nock(path: &str) -> Rc<Noun> {