|
@@ -2,10 +2,10 @@ use dioxus_core::{Component, Element, LazyNodes, Scope, VNode};
|
|
use dioxus_hooks::*;
|
|
use dioxus_hooks::*;
|
|
use error::Error;
|
|
use error::Error;
|
|
use interperter::build;
|
|
use interperter::build;
|
|
|
|
+use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
use std::collections::HashMap;
|
|
use std::panic::Location;
|
|
use std::panic::Location;
|
|
-use std::rc::Rc;
|
|
|
|
-use std::sync::{RwLock, RwLockReadGuard};
|
|
|
|
|
|
+use std::sync::{Arc, RwLock, RwLockReadGuard};
|
|
use syn::parse_str;
|
|
use syn::parse_str;
|
|
|
|
|
|
mod attributes;
|
|
mod attributes;
|
|
@@ -14,25 +14,13 @@ mod elements;
|
|
mod error;
|
|
mod error;
|
|
mod interperter;
|
|
mod interperter;
|
|
|
|
|
|
-#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
|
|
|
|
|
+#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct CodeLocation {
|
|
pub struct CodeLocation {
|
|
pub file: String,
|
|
pub file: String,
|
|
pub line: u32,
|
|
pub line: u32,
|
|
pub column: u32,
|
|
pub column: u32,
|
|
}
|
|
}
|
|
|
|
|
|
-pub fn with_hot_reload(cx: Scope<Component>) -> Element {
|
|
|
|
- use_state(&cx, || {
|
|
|
|
- if cx.consume_context::<RsxTextIndex>().is_none() {
|
|
|
|
- let index = RsxTextIndex::default();
|
|
|
|
- cx.provide_context(index);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- cx.render(LazyNodes::new(|node_factory| {
|
|
|
|
- node_factory.component(*cx.props, (), None, "app")
|
|
|
|
- }))
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
pub fn interpert_rsx<'a, 'b>(
|
|
pub fn interpert_rsx<'a, 'b>(
|
|
factory: dioxus_core::NodeFactory<'a>,
|
|
factory: dioxus_core::NodeFactory<'a>,
|
|
text: &str,
|
|
text: &str,
|
|
@@ -55,17 +43,32 @@ pub fn get_line_num() -> CodeLocation {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-#[derive(Debug, Default, Clone)]
|
|
|
|
-pub struct RsxTextIndex {
|
|
|
|
- hm: Rc<RwLock<HashMap<CodeLocation, String>>>,
|
|
|
|
|
|
+#[derive(Debug, Clone)]
|
|
|
|
+pub struct RsxContext {
|
|
|
|
+ data: Arc<RwLock<RsxData>>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl RsxTextIndex {
|
|
|
|
|
|
+pub struct RsxData {
|
|
|
|
+ pub hm: HashMap<CodeLocation, String>,
|
|
|
|
+ error_handle: Box<dyn FnMut(Error)>,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl std::fmt::Debug for RsxData {
|
|
|
|
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
+ f.debug_struct("RsxData").field("hm", &self.hm).finish()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl RsxContext {
|
|
pub fn insert(&self, loc: CodeLocation, text: String) {
|
|
pub fn insert(&self, loc: CodeLocation, text: String) {
|
|
- self.hm.write().unwrap().insert(loc, text);
|
|
|
|
|
|
+ self.data.write().unwrap().hm.insert(loc, text);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn read(&self) -> RwLockReadGuard<RsxData> {
|
|
|
|
+ self.data.read().unwrap()
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn read(&self) -> RwLockReadGuard<HashMap<CodeLocation, String>> {
|
|
|
|
- self.hm.read().unwrap()
|
|
|
|
|
|
+ pub fn report_error(&self, error: Error) {
|
|
|
|
+ (self.data.write().unwrap().error_handle)(error)
|
|
}
|
|
}
|
|
}
|
|
}
|