Skip to content

Commit

Permalink
Merge pull request #19 from hexedtech/fix/js-event
Browse files Browse the repository at this point in the history
fix: add Workspace::event to js api
  • Loading branch information
alemidev authored Sep 25, 2024
2 parents 8249888 + eb3d31b commit 799123c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 105 deletions.
1 change: 0 additions & 1 deletion src/ffi/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod client;
pub mod workspace;
pub mod cursor;
pub mod buffer;
pub mod op_cache;
pub mod ext;


Expand Down
104 changes: 0 additions & 104 deletions src/ffi/js/op_cache.rs

This file was deleted.

19 changes: 19 additions & 0 deletions src/ffi/js/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ use crate::Workspace;
use crate::buffer::controller::BufferController;
use crate::cursor::controller::CursorController;

#[napi(object, js_name = "Event")]
pub struct JsEvent {
pub r#type: String,
pub value: String,
}

impl From<crate::api::Event> for JsEvent {
fn from(value: crate::api::Event) -> Self {
match value {
crate::api::Event::FileTreeUpdated(value) => Self { r#type: "filetree".into(), value },
crate::api::Event::UserJoin(value) => Self { r#type: "join".into(), value },
crate::api::Event::UserLeave(value) => Self { r#type: "leave".into(), value },
}
}
}

#[napi]
impl Workspace {
Expand Down Expand Up @@ -46,4 +61,8 @@ impl Workspace {
Ok(self.delete(&path).await?)
}

#[napi(js_name = "event")]
pub async fn js_event(&self) -> napi::Result<JsEvent> {
Ok(JsEvent::from(self.event().await?))
}
}

0 comments on commit 799123c

Please sign in to comment.