@@ -2,7 +2,7 @@
4use core::panic;
4use core::panic;
5−use std::{cell::RefCell, rc::Rc};
5+use std::{borrow::BorrowMut, cell::RefCell, rc::Rc};
7use dodrio::{
7use dodrio::{
8 bumpalo::{self, Bump},
8 bumpalo::{self, Bump},
@@ -30,15 +30,18 @@ extern "C" {
32#[derive(Clone)]
32#[derive(Clone)]
33−struct WockApp {
33+struct Urbit {
35− ctx: RefCell<InterpreterContext>,
37 urbit: RefCell<Option<Rc<Noun>>>,
34 urbit: RefCell<Option<Rc<Noun>>>,
40−impl WockApp {
37+impl Urbit {
40+ urbit: RefCell::new(None),
41− async fn get_urbit(self: &Self) -> Rc<Noun> {
44+ async fn get(self: &Self) -> Rc<Noun> {
42 match self.urbit.borrow().clone() {
45 match self.urbit.borrow().clone() {
43 Some(urbit) => urbit,
46 Some(urbit) => urbit,
@@ -55,6 +58,14 @@ impl WockApp {
64+ ctx: RefCell<InterpreterContext>,
58impl<'a> Render<'a> for WockApp {
69impl<'a> Render<'a> for WockApp {
59 fn render(&self, cx: &mut dodrio::RenderContext<'a>) -> dodrio::Node<'a> {
70 fn render(&self, cx: &mut dodrio::RenderContext<'a>) -> dodrio::Node<'a> {
60 match slam(
71 match slam(
@@ -67,7 +78,7 @@ impl<'a> Render<'a> for WockApp {
67 let wock_app = self.clone();
78 let wock_app = self.clone();
68 let mut ctx = (*self.ctx.borrow()).clone();
79 let mut ctx = (*self.ctx.borrow()).clone();
69 spawn_local(async move {
80 spawn_local(async move {
70− let urbit = wock_app.get_urbit().await;
81+ let urbit = wock_app.urbit.get().await;
71 let str = wash(&mut ctx, &urbit, tanks);
82 let str = wash(&mut ctx, &urbit, tanks);
72 error_1(&JsValue::from_str(&str));
83 error_1(&JsValue::from_str(&str));
@@ -111,7 +122,8 @@ fn render_sail<'a>(ctx: &mut RenderContext<'a>, manx: Rc<Noun>) -> Node<'a> {
111 _event: web_sys::Event| {
122 _event: web_sys::Event| {
112 let app = root.unwrap_mut::<WockApp>();
123 let app = root.unwrap_mut::<WockApp>();
125+ let binding = app.ctx.clone();
114− let mut ctx = app.ctx.borrow_mut();
126+ let mut ctx = binding.borrow_mut();
116 let sig = ctx.nouns.sig.clone();
128 let sig = ctx.nouns.sig.clone();
@@ -129,10 +141,19 @@ fn render_sail<'a>(ctx: &mut RenderContext<'a>, manx: Rc<Noun>) -> Node<'a> {
129 app.model = new_model;
141 app.model = new_model;
130 vdom.schedule_render();
142 vdom.schedule_render();
145+ let urbit = app.urbit.clone();
146+ let mut ctx = ctx.borrow_mut().clone();
147+ spawn_local(async move {
148+ let urbit = urbit.get().await;
149+ let str = wash(&mut ctx, &urbit, tanks);
150+ error_1(&JsValue::from_str(&str));
132− Err(_) => error(&*format!(
152+ error(&*format!(
133− "Application failed to process event: {}",
153+ "Application failed to process event: {}",
@@ -212,7 +233,7 @@ pub async fn main(path: &str) {
214 ctx: RefCell::new(ctx),
235 ctx: RefCell::new(ctx),
215− urbit: RefCell::new(None),
236+ urbit: Rc::new(Urbit::new()),
218 .forget();
239 .forget();