Skip to content

Commit

Permalink
Refactor into new files
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jan 20, 2024
1 parent aa13648 commit 571a3f3
Show file tree
Hide file tree
Showing 13 changed files with 443 additions and 414 deletions.
10 changes: 5 additions & 5 deletions crates/concoct-web/src/html.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::WebContext;
use concoct::{
body::Child,
view::Child,
hook::{use_context, use_on_drop, use_provider, use_ref},
Body, View,
View, ViewBuilder,
};
use std::{borrow::Cow, cell::RefCell, rc::Rc};
use web_sys::{
Expand All @@ -13,7 +13,7 @@ use web_sys::{
macro_rules! make_tag_fns {
($($name:tt),*) => {
$(
pub fn $name<C: Body>(child: C) -> Html<C> {
pub fn $name<C: View>(child: C) -> Html<C> {
Html::new(stringify!($name), child)
}
)*
Expand Down Expand Up @@ -108,8 +108,8 @@ impl<C> Html<C> {
);
}

impl<C: Body> View for Html<C> {
fn body(&self) -> impl Body {
impl<C: View> ViewBuilder for Html<C> {
fn build(&self) -> impl View {
let data = use_ref(|| RefCell::new(Data::default()));
let mut data_ref = data.borrow_mut();

Expand Down
8 changes: 4 additions & 4 deletions crates/concoct-web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use concoct::{
hook::{use_context, use_on_drop, use_provider, use_ref},
Body, TextViewContext, View,
View, TextViewContext, ViewBuilder,
};
use std::{cell::RefCell, rc::Rc};
use web_sys::{Document, Node, Text, Window};
Expand All @@ -17,8 +17,8 @@ pub struct WebRoot<B> {
pub body: Rc<B>,
}

impl<B: View> View for WebRoot<B> {
fn body(&self) -> impl Body {
impl<B: ViewBuilder> ViewBuilder for WebRoot<B> {
fn build(&self) -> impl View {
let window = web_sys::window().unwrap();
let document = window.document().unwrap();
let body = document.body().unwrap();
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<B: View> View for WebRoot<B> {
}
}

pub async fn run(view: impl View) {
pub async fn run(view: impl ViewBuilder) {
concoct::run(WebRoot {
body: Rc::new(view),
})
Expand Down
87 changes: 0 additions & 87 deletions crates/concoct/src/body.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/concoct/src/hook/use_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::use_ref;
use crate::Context;
use std::{cell::RefCell, rc::Rc};
use std::cell::RefCell;

/// Hook to create render state.
///
Expand Down
Loading

0 comments on commit 571a3f3

Please sign in to comment.