Skip to content

Commit

Permalink
Feed automerge with text
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Dec 7, 2024
1 parent 7de167f commit 0806ada
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ use crate::config::VERSION;
use crate::network;
use crate::AardvarkWindow;
use crate::glib::closure_local;
use automerge::transaction::Transactable;
use automerge::ObjType;
use std::cell::RefCell;
use automerge::ObjId;

mod imp {
use super::*;

#[derive(Debug, Default)]
#[derive(Debug)]
pub struct AardvarkApplication {
automerge: AutoCommit,
automerge: RefCell<AutoCommit>,
root: ObjId,
}

impl AardvarkApplication {
fn update_text(&self, text: &str) {
println!("app: {}", text);
let mut doc = self.automerge.borrow_mut();
doc.update_text(&self.root, text).unwrap();
}
}

#[glib::object_subclass]
Expand All @@ -44,8 +57,13 @@ mod imp {
type ParentType = adw::Application;

fn new() -> Self {
let automerge = AutoCommit::new();
AardvarkApplication { automerge }
let mut am = AutoCommit::new();
let root = am.put_object(automerge::ROOT, "root", ObjType::Text).unwrap();
let automerge = RefCell::new(am);
AardvarkApplication {
automerge,
root,
}
}
}

Expand Down Expand Up @@ -73,7 +91,7 @@ mod imp {
"text-changed",
false,
closure_local!(|_window: AardvarkWindow, text: &str| {
app.update_text(text);
app.imp().update_text(text);
}),
);
window.upcast()
Expand Down Expand Up @@ -129,8 +147,4 @@ impl AardvarkApplication {

about.present(Some(&window));
}

fn update_text(&self, text: &str) {
println!("app: {}", text);
}
}

0 comments on commit 0806ada

Please sign in to comment.