From f29ea23c4e2edcb7a944f9b88ab21fcf7e620abe Mon Sep 17 00:00:00 2001 From: frelodev Date: Wed, 21 Aug 2024 17:14:19 +0200 Subject: [PATCH] feat: new fn for controllers --- src/ffi/js/buffer.rs | 12 +++++++++++- src/ffi/js/cursor.rs | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ffi/js/buffer.rs b/src/ffi/js/buffer.rs index 9e141c7..2210418 100644 --- a/src/ffi/js/buffer.rs +++ b/src/ffi/js/buffer.rs @@ -22,7 +22,7 @@ impl BufferController { tokio::time::sleep(std::time::Duration::from_millis(200)).await; match _controller.recv().await { Ok(event) => { - tsfn.call(event, ThreadsafeFunctionCallMode::NonBlocking); //check this shit with tracing also we could use Ok(event) to get the error + tsfn.call(event, ThreadsafeFunctionCallMode::NonBlocking); //check this with tracing also we could use Ok(event) to get the error }, Err(crate::Error::Deadlocked) => continue, Err(e) => break tracing::warn!("error receiving: {}", e), @@ -32,6 +32,11 @@ impl BufferController { Ok(()) } + #[napi(js_name = "try_recv")] + pub async fn js_try_recv(&self) -> napi::Result> { + Ok(self.try_recv().await?) + } + #[napi(js_name = "recv")] pub async fn js_recv(&self) -> napi::Result { Ok(self.recv().await?.into()) @@ -41,4 +46,9 @@ impl BufferController { pub async fn js_send(&self, op: TextChange) -> napi::Result<()> { Ok(self.send(op).await?) } + + #[napi(js_name = "content")] + pub async fn js_content(&self) -> napi::Result { + Ok(self.content().await?) + } } diff --git a/src/ffi/js/cursor.rs b/src/ffi/js/cursor.rs index c84d90d..4b4e024 100644 --- a/src/ffi/js/cursor.rs +++ b/src/ffi/js/cursor.rs @@ -76,4 +76,9 @@ impl CursorController { Ok(self.try_recv().await? .map(|x| JsCursor::from(x))) } + + #[napi(js_name= "recv")] + pub async fn js_recv(&self) -> napi::Result { + Ok(self.recv().await?.into()) + } }