@@ -5,12 +5,12 @@ use std::rc::Rc;
6use dodrio::{
6use dodrio::{
7 bumpalo::{self, Bump},
7 bumpalo::{self, Bump},
8− Attribute, Node, NodeKey, Render, RenderContext,
8+ Attribute, Listener, Node, NodeKey, Render, RenderContext, RootRender, VdomWeak,
10use nock::{
10use nock::{
11 cue::cue_bytes,
11 cue::cue_bytes,
12 interpreter::{generate_interpreter_context, slam},
12 interpreter::{generate_interpreter_context, slam},
13− noun::Noun,
13+ noun::{cell, Noun},
15use wasm_bindgen::prelude::*;
15use wasm_bindgen::prelude::*;
16use wasm_bindgen_futures::JsFuture;
16use wasm_bindgen_futures::JsFuture;
@@ -26,19 +26,25 @@ extern "C" {
27struct WockApp {
27struct WockApp {
28 nock: Rc<Noun>,
28 nock: Rc<Noun>,
31impl<'a> Render<'a> for WockApp {
32impl<'a> Render<'a> for WockApp {
32 fn render(&self, cx: &mut dodrio::RenderContext<'a>) -> dodrio::Node<'a> {
33 fn render(&self, cx: &mut dodrio::RenderContext<'a>) -> dodrio::Node<'a> {
33 let mut ctx = generate_interpreter_context();
34 let mut ctx = generate_interpreter_context();
35− let sail = slam(&mut ctx, &self.nock, &Rc::new(Noun::from_u32(0))).unwrap();
36+ let sail = slam(
39+ &cell(&Rc::new(Noun::from_bytes(b"view")), &self.model),
37− render_sail(cx, &sail)
43+ render_sail(cx, sail)
41−fn render_sail<'a>(ctx: &mut RenderContext<'a>, manx: &Rc<Noun>) -> Node<'a> {
47+fn render_sail<'a>(ctx: &mut RenderContext<'a>, manx: Rc<Noun>) -> Node<'a> {
42 let (marx, marl) = manx.as_cell().unwrap();
48 let (marx, marl) = manx.as_cell().unwrap();
43 let (mane, mart) = marx.as_cell().unwrap();
49 let (mane, mart) = marx.as_cell().unwrap();
@@ -53,21 +59,51 @@ fn render_sail<'a>(ctx: &mut RenderContext<'a>, manx: &Rc<Noun>) -> Node<'a> {
54 let mut children = bumpalo::collections::Vec::new_in(&ctx.bump);
60 let mut children = bumpalo::collections::Vec::new_in(&ctx.bump);
55 marl.list_iter()
61 marl.list_iter()
56− .map(|child| render_sail(ctx, child))
62+ .map(|child| render_sail(ctx, child.clone()))
57 .collect_into(&mut children);
63 .collect_into(&mut children);
59 let mut attributes = bumpalo::collections::Vec::new_in(ctx.bump);
65 let mut attributes = bumpalo::collections::Vec::new_in(ctx.bump);
66+ let mut listeners = bumpalo::collections::Vec::new_in(ctx.bump);
60− mart.list_iter()
68+ mart.list_iter().for_each(|attr| {
62− let (name, value) = attr.as_cell().unwrap();
69+ let (name, value) = attr.as_cell().unwrap();
70+ match &*name.as_bytes().unwrap() {
71+ b"on-click" => listeners.push(Listener {
74+ let value = value.clone();
76+ move |root: &mut dyn RootRender,
78+ _event: web_sys::Event| {
79+ let mut ctx = generate_interpreter_context();
80+ let sig = ctx.nouns.sig.clone();
82+ let app = root.unwrap_mut::<WockApp>();
84+ let new_model = slam(
88+ &Rc::new(Noun::from_bytes(b"move")),
89+ &cell(&app.model, &cell(&value, &sig)),
94+ app.model = new_model;
96+ vdom.schedule_render();
63− Attribute {
101+ _ => attributes.push(Attribute {
64 name: cord_to_bump_str(ctx.bump, name),
102 name: cord_to_bump_str(ctx.bump, name),
65− value: cord_to_bump_str(ctx.bump, value),
103+ value: tape_to_bump_str(ctx.bump, value),
68− .collect_into(&mut attributes);
106+ });
70− let listeners = bumpalo::collections::Vec::new_in(ctx.bump);
72 Node::element(
108 Node::element(
73 &ctx.bump,
109 &ctx.bump,
@@ -106,7 +142,16 @@ pub async fn main(path: &str) {
106 let document = gloo::utils::document();
142 let document = gloo::utils::document();
107 let output_el: Element = document.get_element_by_id("output").unwrap();
143 let output_el: Element = document.get_element_by_id("output").unwrap();
145+ let mut ctx = generate_interpreter_context();
150+ &cell(&Rc::new(Noun::from_bytes(b"init")), &Rc::new(Noun::SIG)),
109− dodrio::Vdom::new(&output_el, WockApp { nock }).forget();
154+ dodrio::Vdom::new(&output_el, WockApp { nock, model }).forget();
112pub async fn load_nock(path: &str) -> Rc<Noun> {
157pub async fn load_nock(path: &str) -> Rc<Noun> {