Skip to content

Commit

Permalink
Refactor and fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jan 20, 2024
1 parent e0e5fa5 commit 055a75d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions crates/concoct/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! to create an efficient tree of components. Updates to state re-render
//! your application top-down, starting at the state's parent component.
//!
//! ```no_run
//! ```ignore
//! use concoct::{View, ViewBuilder};
//! use concoct::hook::use_state;
//! use concoct_web::html;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub(crate) use tree::Node;
pub use tree::Tree;

mod vdom;
pub use self::vdom::{virtual_dom, VirtualDom};
pub use self::vdom::VirtualDom;

mod view_builder;
pub use self::view_builder::ViewBuilder;
Expand All @@ -49,7 +49,7 @@ pub use self::view::View;

/// Run a view in a new virtual dom.
pub async fn run(view: impl ViewBuilder) {
let mut vdom = virtual_dom(view);
let mut vdom = VirtualDom::new(view.into_tree());
vdom.build();

loop {
Expand Down
17 changes: 8 additions & 9 deletions crates/concoct/src/vdom.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use crate::{Runtime, Tree, View};
use crate::{Runtime, Tree};
use std::{
task::{Poll, Waker},
time::{Duration, Instant},
};

/// Create a new virtual dom from a view.
pub fn virtual_dom(view: impl View) -> VirtualDom<impl Tree> {
VirtualDom {
cx: Runtime::default(),
tree: view.into_tree(),
}
}

/// A virtual dom that renders a view on any backend.
pub struct VirtualDom<T> {
cx: Runtime,
tree: T,
}

impl<T> VirtualDom<T> {
pub fn new(tree: T) -> Self {
VirtualDom {
cx: Runtime::default(),
tree,
}
}

/// Build the initial virtual dom.
pub fn build(&mut self)
where
Expand Down

0 comments on commit 055a75d

Please sign in to comment.