set multiple rsx calls at once to prevent duplicated errors
This commit is contained in:
1 parent
b761bdb767
commit
75e13749ea
3 files changed
+21
-6
No files matched your search
@@ -54,7 +54,7 @@ impl DesktopController {
|
||||
#[cfg(feature = "hot_reload")]
|
||||
{
|
||||
use dioxus_rsx_interpreter::{
|
||||
error::Error, ErrorHandler, SetRsxMessage, RSX_CONTEXT,
|
||||
error::Error, ErrorHandler, SetManyRsxMessage, RSX_CONTEXT,
|
||||
};
|
||||
use interprocess::local_socket::{LocalSocketListener, LocalSocketStream};
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
@@ -120,9 +120,9 @@ impl DesktopController {
|
||||
let mut buf = String::new();
|
||||
match conn.read_line(&mut buf) {
|
||||
Ok(_) => {
|
||||
let message: SetRsxMessage =
|
||||
let msgs: SetManyRsxMessage =
|
||||
serde_json::from_str(&buf).unwrap();
|
||||
RSX_CONTEXT.insert(message.location, message.new_text);
|
||||
RSX_CONTEXT.extend(msgs);
|
||||
}
|
||||
Err(err) => {
|
||||
if err.kind() != std::io::ErrorKind::WouldBlock {
|
||||
|
||||
@@ -125,6 +125,17 @@ impl RsxContext {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the text for many rsx calls
|
||||
pub fn extend(&self, msg: SetManyRsxMessage) {
|
||||
let mut write = self.data.write().unwrap();
|
||||
for rsx in msg.0 {
|
||||
write.hm.insert(rsx.location, rsx.new_text);
|
||||
}
|
||||
if let Some(channel) = &mut write.scheduler_channel {
|
||||
channel.unbounded_send(SchedulerMsg::DirtyAll).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn read(&self) -> RwLockReadGuard<RsxData> {
|
||||
self.data.read().unwrap()
|
||||
}
|
||||
@@ -157,3 +168,7 @@ pub struct SetRsxMessage {
|
||||
pub location: CodeLocation,
|
||||
pub new_text: String,
|
||||
}
|
||||
|
||||
/// Set many rsx texts at once to avoid duplicate errors
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct SetManyRsxMessage(pub Vec<SetRsxMessage>);
|
||||
@@ -220,7 +220,7 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
|
||||
#[cfg(feature = "hot_reload")]
|
||||
{
|
||||
use dioxus_rsx_interpreter::error::Error;
|
||||
use dioxus_rsx_interpreter::{ErrorHandler, SetRsxMessage, RSX_CONTEXT};
|
||||
use dioxus_rsx_interpreter::{ErrorHandler, SetManyRsxMessage, RSX_CONTEXT};
|
||||
use futures_channel::mpsc::unbounded;
|
||||
use futures_channel::mpsc::UnboundedSender;
|
||||
use futures_util::StreamExt;
|
||||
@@ -246,8 +246,8 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
|
||||
// change the rsx when new data is received
|
||||
let cl = Closure::wrap(Box::new(|e: MessageEvent| {
|
||||
if let Ok(text) = e.data().dyn_into::<js_sys::JsString>() {
|
||||
let msg: SetRsxMessage = serde_json::from_str(&format!("{text}")).unwrap();
|
||||
RSX_CONTEXT.insert(msg.location, msg.new_text);
|
||||
let msgs: SetManyRsxMessage = serde_json::from_str(&format!("{text}")).unwrap();
|
||||
RSX_CONTEXT.extend(msgs);
|
||||
}
|
||||
}) as Box<dyn FnMut(MessageEvent)>);
|
||||
|
||||
|
||||
Reference in new issue
Block a user