Skip to content

Commit f2dd447

Browse files
committed
chore: napi ffi update for bump deps
1 parent 5b54251 commit f2dd447

3 files changed

Lines changed: 14 additions & 35 deletions

File tree

src/ffi/js/buffer.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::api::controller::{AsyncReceiver, AsyncSender};
22
use crate::api::{BufferUpdate, TextChange};
33
use crate::buffer::controller::BufferController;
44
use napi::threadsafe_function::{
5-
ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
5+
ThreadsafeFunction, ThreadsafeFunctionCallMode,
66
};
77
use napi_derive::napi;
88

@@ -14,16 +14,10 @@ impl BufferController {
1414
js_name = "callback",
1515
ts_args_type = "fun: (event: BufferController) => void"
1616
)]
17-
pub fn js_callback(&self, fun: napi::JsFunction) -> napi::Result<()> {
18-
let tsfn: ThreadsafeFunction<crate::buffer::controller::BufferController, Fatal> = fun
19-
.create_threadsafe_function(
20-
0,
21-
|ctx: ThreadSafeCallContext<crate::buffer::controller::BufferController>| {
22-
Ok(vec![ctx.value])
23-
},
24-
)?;
17+
pub fn js_callback(&self, fun: ThreadsafeFunction<crate::buffer::controller::BufferController>) -> napi::Result<()> {
18+
let tsfn: ThreadsafeFunction<crate::buffer::controller::BufferController> = fun;
2519
self.callback(move |controller: BufferController| {
26-
tsfn.call(controller.clone(), ThreadsafeFunctionCallMode::Blocking);
20+
tsfn.call(Ok(controller.clone()), ThreadsafeFunctionCallMode::Blocking);
2721
//check this with tracing also we could use Ok(event) to get the error
2822
// If it blocks the main thread too many time we have to change this
2923
});

src/ffi/js/cursor.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::api::controller::{AsyncReceiver, AsyncSender};
22
use crate::cursor::controller::CursorController;
3-
use napi::threadsafe_function::ErrorStrategy::Fatal;
4-
use napi::threadsafe_function::{
5-
ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
6-
};
3+
use napi::threadsafe_function::{ ThreadsafeFunction, ThreadsafeFunctionCallMode};
74
use napi_derive::napi;
85

96
#[napi]
@@ -14,16 +11,10 @@ impl CursorController {
1411
js_name = "callback",
1512
ts_args_type = "fun: (event: CursorController) => void"
1613
)]
17-
pub fn js_callback(&self, fun: napi::JsFunction) -> napi::Result<()> {
18-
let tsfn: ThreadsafeFunction<crate::cursor::controller::CursorController, Fatal> = fun
19-
.create_threadsafe_function(
20-
0,
21-
|ctx: ThreadSafeCallContext<crate::cursor::controller::CursorController>| {
22-
Ok(vec![ctx.value])
23-
},
24-
)?;
14+
pub fn js_callback(&self, fun: ThreadsafeFunction<crate::cursor::controller::CursorController>) -> napi::Result<()> {
15+
let tsfn: ThreadsafeFunction<crate::cursor::controller::CursorController> = fun;
2516
self.callback(move |controller: CursorController| {
26-
tsfn.call(controller.clone(), ThreadsafeFunctionCallMode::Blocking);
17+
tsfn.call(Ok(controller.clone()), ThreadsafeFunctionCallMode::Blocking);
2718
//check this with tracing also we could use Ok(event) to get the error
2819
// If it blocks the main thread too many time we have to change this
2920
});

src/ffi/js/workspace.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use crate::Workspace;
22
use crate::api::controller::AsyncReceiver;
33
use crate::buffer::controller::BufferController;
44
use crate::cursor::controller::CursorController;
5-
use napi::threadsafe_function::ErrorStrategy::Fatal;
6-
use napi::threadsafe_function::{
7-
ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
8-
};
5+
use napi::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode};
96
use napi_derive::napi;
107

118
use super::client::JsUser;
@@ -45,8 +42,8 @@ impl Workspace {
4542

4643
/// List all available buffers in this workspace
4744
#[napi(js_name = "searchBuffers")]
48-
pub fn js_search_buffers(&self, filter: Option<&str>) -> Vec<String> {
49-
self.search_buffers(filter)
45+
pub fn js_search_buffers(&self, filter: Option<String>) -> Vec<String> {
46+
self.search_buffers(filter.as_deref())
5047
}
5148

5249
/// List all user names currently in this workspace
@@ -114,13 +111,10 @@ impl Workspace {
114111
}
115112

116113
#[napi(js_name = "callback", ts_args_type = "fun: (event: Workspace) => void")]
117-
pub fn js_callback(&self, fun: napi::JsFunction) -> napi::Result<()> {
118-
let tsfn: ThreadsafeFunction<crate::Workspace, Fatal> = fun
119-
.create_threadsafe_function(0, |ctx: ThreadSafeCallContext<crate::Workspace>| {
120-
Ok(vec![ctx.value])
121-
})?;
114+
pub fn js_callback(&self, fun: ThreadsafeFunction<Workspace>) -> napi::Result<()> {
115+
let tsfn: ThreadsafeFunction<crate::Workspace> = fun;
122116
self.callback(move |controller: Workspace| {
123-
tsfn.call(controller.clone(), ThreadsafeFunctionCallMode::Blocking); //check this with tracing also we could use Ok(event) to get the error
117+
tsfn.call(Ok(controller.clone()), ThreadsafeFunctionCallMode::Blocking); //check this with tracing also we could use Ok(event) to get the error
124118
// If it blocks the main thread too many time we have to change this
125119
});
126120

0 commit comments

Comments
 (0)