Testing
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user