This commit is contained in:
2025-11-20 23:15:31 +01:00
parent 4d2f0d7b9d
commit b57fffe9b7
6 changed files with 111 additions and 261 deletions
+27
View File
@@ -0,0 +1,27 @@
use std::sync::Arc;
use crate::Node;
pub type Component = Arc<dyn Fn(&mut Context) -> Vec<Node>>;
pub struct Context {
component: Component,
nodes: Vec<Node>,
}
impl Context {
pub fn new<F: Fn(&mut Context) -> Vec<Node> + 'static>(component: F) -> Self {
Self {
component: Arc::new(component),
nodes: Vec::new(),
}
}
pub fn refresh(&mut self) {
self.nodes = (self.component.clone())(self);
}
pub fn get_nodes(&self) -> Vec<Node> {
self.nodes.clone()
}
}