Jonathan Kelley пре 4 година
родитељ
комит
6aaad1c9ef
3 измењених фајлова са 46 додато и 0 уклоњено
  1. 41 0
      packages/core/src/heuristics.rs
  2. 2 0
      packages/core/src/lib.rs
  3. 3 0
      packages/core/src/virtual_dom.rs

+ 41 - 0
packages/core/src/heuristics.rs

@@ -0,0 +1,41 @@
+use std::collections::HashMap;
+
+use crate::FC;
+
+pub(crate) struct HeuristicsEngine {
+    heuristics: HashMap<FcSlot, Heuristic>,
+}
+
+pub(crate) type FcSlot = *const ();
+
+pub(crate) struct Heuristic {
+    hooks: u32,
+    bump_size: u64,
+}
+
+impl HeuristicsEngine {
+    pub(crate) fn new() -> Self {
+        Self {
+            heuristics: HashMap::new(),
+        }
+    }
+
+    fn recommend<T>(&mut self, fc: FC<T>, heuristic: Heuristic) {
+        let g = fc as FcSlot;
+        let e = self.heuristics.entry(g);
+    }
+
+    fn get_recommendation<T>(&mut self, fc: FC<T>) -> &Heuristic {
+        let id = fc as FcSlot;
+
+        self.heuristics.entry(id).or_insert(Heuristic {
+            bump_size: 100,
+            hooks: 10,
+        })
+    }
+}
+
+#[test]
+fn types_work() {
+    let engine = HeuristicsEngine::new();
+}

+ 2 - 0
packages/core/src/lib.rs

@@ -34,6 +34,7 @@ pub(crate) mod innerlude {
     pub use crate::editor::*;
     pub use crate::error::*;
     pub use crate::events::*;
+    pub use crate::heuristics::*;
     pub use crate::hooklist::*;
     pub use crate::nodes::*;
     pub use crate::scope::*;
@@ -59,6 +60,7 @@ pub mod diff;
 pub mod editor;
 pub mod error;
 pub mod events;
+pub mod heuristics;
 pub mod hooklist;
 pub mod nodes;
 pub mod scope;

+ 3 - 0
packages/core/src/virtual_dom.rs

@@ -60,6 +60,8 @@ pub struct VirtualDom {
 
     pub tasks: TaskQueue,
 
+    heuristics: HeuristicsEngine,
+
     root_props: std::pin::Pin<Box<dyn std::any::Any>>,
 
     /// Type of the original props. This is stored as TypeId so VirtualDom does not need to be generic.
@@ -168,6 +170,7 @@ impl VirtualDom {
             components,
             root_props,
             tasks,
+            heuristics: HeuristicsEngine::new(),
             triggers: Default::default(),
             _root_prop_type: TypeId::of::<P>(),
         }