wip: remove portals completely
This commit is contained in:
1 parent
8daf7a6ed8
commit
2fd56e7619
17 files changed
+259
-404
No files matched your search
@@ -10,7 +10,7 @@ fn test_borrowed_state() {
|
||||
let _ = VirtualDom::new(Parent);
|
||||
}
|
||||
|
||||
fn Parent(cx: Scope, _props: &()) -> Element {
|
||||
fn Parent(cx: Scope<()>) -> Element {
|
||||
let value = cx.use_hook(|_| String::new(), |f| &*f);
|
||||
|
||||
cx.render(rsx! {
|
||||
@@ -28,11 +28,11 @@ struct ChildProps<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn Child(cx: Scope, props: &ChildProps) -> Element {
|
||||
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 { "it's nested" }
|
||||
Child2 { name: props.name }
|
||||
Child2 { name: cx.props.name }
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -42,8 +42,8 @@ struct Grandchild<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn Child2(cx: Scope, props: &Grandchild) -> Element {
|
||||
fn Child2<'a>(cx: Scope<'a, Grandchild<'a>>) -> Element {
|
||||
cx.render(rsx! {
|
||||
div { "Hello {props.name}!" }
|
||||
div { "Hello {cx.props.name}!" }
|
||||
})
|
||||
}
|
||||
@@ -21,7 +21,7 @@ fn new_dom<P: 'static + Send>(app: Component<P>, props: P) -> VirtualDom {
|
||||
|
||||
#[test]
|
||||
fn test_original_diff() {
|
||||
static APP: Component<()> = |cx, props| {
|
||||
static APP: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
div {
|
||||
@@ -57,7 +57,7 @@ fn test_original_diff() {
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
static APP: Component<()> = |cx, props| {
|
||||
static APP: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
div {
|
||||
@@ -120,7 +120,7 @@ fn create() {
|
||||
|
||||
#[test]
|
||||
fn create_list() {
|
||||
static APP: Component<()> = |cx, props| {
|
||||
static APP: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
{(0..3).map(|f| rsx!{ div {
|
||||
"hello"
|
||||
@@ -169,7 +169,7 @@ fn create_list() {
|
||||
|
||||
#[test]
|
||||
fn create_simple() {
|
||||
static APP: Component<()> = |cx, props| {
|
||||
static APP: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
div {}
|
||||
@@ -207,7 +207,7 @@ fn create_simple() {
|
||||
}
|
||||
#[test]
|
||||
fn create_components() {
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
Child { "abc1" }
|
||||
Child { "abc2" }
|
||||
@@ -215,15 +215,16 @@ fn create_components() {
|
||||
})
|
||||
};
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct ChildProps {
|
||||
children: Element,
|
||||
#[derive(Props)]
|
||||
struct ChildProps<'a> {
|
||||
children: Element<'a>,
|
||||
}
|
||||
|
||||
fn Child(cx: Scope, props: &ChildProps) -> Element {
|
||||
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
||||
todo!();
|
||||
cx.render(rsx! {
|
||||
h1 {}
|
||||
div { {&props.children} }
|
||||
// div { {&cx.props.children} }
|
||||
p {}
|
||||
})
|
||||
}
|
||||
@@ -273,7 +274,7 @@ fn create_components() {
|
||||
}
|
||||
#[test]
|
||||
fn anchors() {
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
{true.then(|| rsx!{ div { "hello" } })}
|
||||
{false.then(|| rsx!{ div { "goodbye" } })}
|
||||
|
||||
@@ -15,7 +15,7 @@ mod test_logging;
|
||||
fn new_dom() -> VirtualDom {
|
||||
const IS_LOGGING_ENABLED: bool = false;
|
||||
test_logging::set_up_logging(IS_LOGGING_ENABLED);
|
||||
VirtualDom::new(|cx, props| todo!())
|
||||
VirtualDom::new(|cx| todo!())
|
||||
}
|
||||
|
||||
use DomEdit::*;
|
||||
|
||||
@@ -22,8 +22,8 @@ fn manual_diffing() {
|
||||
value: Shared<&'static str>,
|
||||
}
|
||||
|
||||
static App: Component<AppProps> = |cx, props| {
|
||||
let val = props.value.lock().unwrap();
|
||||
static App: Component<AppProps> = |cx| {
|
||||
let val = cx.props.value.lock().unwrap();
|
||||
cx.render(rsx! { div { "{val}" } })
|
||||
};
|
||||
|
||||
@@ -46,8 +46,8 @@ fn manual_diffing() {
|
||||
|
||||
#[test]
|
||||
fn events_generate() {
|
||||
static App: Component<()> = |cx, _| {
|
||||
let mut count = use_state(cx, || 0);
|
||||
static App: Component<()> = |cx| {
|
||||
let mut count = use_state(&cx, || 0);
|
||||
|
||||
let inner = match *count {
|
||||
0 => {
|
||||
@@ -105,8 +105,8 @@ fn events_generate() {
|
||||
|
||||
#[test]
|
||||
fn components_generate() {
|
||||
static App: Component<()> = |cx, _| {
|
||||
let mut render_phase = use_state(cx, || 0);
|
||||
static App: Component<()> = |cx| {
|
||||
let mut render_phase = use_state(&cx, || 0);
|
||||
render_phase += 1;
|
||||
|
||||
cx.render(match *render_phase {
|
||||
@@ -122,7 +122,7 @@ fn components_generate() {
|
||||
})
|
||||
};
|
||||
|
||||
static Child: Component<()> = |cx, _| {
|
||||
static Child: Component<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
h1 {}
|
||||
})
|
||||
@@ -222,8 +222,8 @@ fn components_generate() {
|
||||
#[test]
|
||||
fn component_swap() {
|
||||
// simple_logger::init();
|
||||
static App: Component<()> = |cx, _| {
|
||||
let mut render_phase = use_state(cx, || 0);
|
||||
static App: Component<()> = |cx| {
|
||||
let mut render_phase = use_state(&cx, || 0);
|
||||
render_phase += 1;
|
||||
|
||||
cx.render(match *render_phase {
|
||||
@@ -261,7 +261,7 @@ fn component_swap() {
|
||||
})
|
||||
};
|
||||
|
||||
static NavBar: Component<()> = |cx, _| {
|
||||
static NavBar: Component<()> = |cx| {
|
||||
println!("running navbar");
|
||||
cx.render(rsx! {
|
||||
h1 {
|
||||
@@ -271,7 +271,7 @@ fn component_swap() {
|
||||
})
|
||||
};
|
||||
|
||||
static NavLink: Component<()> = |cx, _| {
|
||||
static NavLink: Component<()> = |cx| {
|
||||
println!("running navlink");
|
||||
cx.render(rsx! {
|
||||
h1 {
|
||||
@@ -280,7 +280,7 @@ fn component_swap() {
|
||||
})
|
||||
};
|
||||
|
||||
static Dashboard: Component<()> = |cx, _| {
|
||||
static Dashboard: Component<()> = |cx| {
|
||||
println!("running dashboard");
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
@@ -289,7 +289,7 @@ fn component_swap() {
|
||||
})
|
||||
};
|
||||
|
||||
static Results: Component<()> = |cx, _| {
|
||||
static Results: Component<()> = |cx| {
|
||||
println!("running results");
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -13,12 +13,12 @@ mod test_logging;
|
||||
fn shared_state_test() {
|
||||
struct MySharedState(&'static str);
|
||||
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.provide_state(MySharedState("world!"));
|
||||
cx.render(rsx!(Child {}))
|
||||
};
|
||||
|
||||
static Child: Component<()> = |cx, props| {
|
||||
static Child: Component<()> = |cx| {
|
||||
let shared = cx.consume_state::<MySharedState>()?;
|
||||
cx.render(rsx!("Hello, {shared.0}"))
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ use DomEdit::*;
|
||||
|
||||
#[test]
|
||||
fn app_runs() {
|
||||
static App: Component<()> = |cx, props| rsx!(cx, div{"hello"} );
|
||||
static App: Component<()> = |cx| rsx!(cx, div{"hello"} );
|
||||
|
||||
let mut vdom = VirtualDom::new(App);
|
||||
let edits = vdom.rebuild();
|
||||
@@ -27,7 +27,7 @@ fn app_runs() {
|
||||
|
||||
#[test]
|
||||
fn fragments_work() {
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
div{"hello"}
|
||||
div{"goodbye"}
|
||||
@@ -41,7 +41,7 @@ fn fragments_work() {
|
||||
|
||||
#[test]
|
||||
fn lists_work() {
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
{(0..6).map(|f| rsx!(span{ "{f}" }))}
|
||||
@@ -54,7 +54,7 @@ fn lists_work() {
|
||||
|
||||
#[test]
|
||||
fn conditional_rendering() {
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
{true.then(|| rsx!(span{ "a" }))}
|
||||
@@ -87,13 +87,13 @@ fn conditional_rendering() {
|
||||
|
||||
#[test]
|
||||
fn child_components() {
|
||||
static App: Component<()> = |cx, props| {
|
||||
static App: Component<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
{true.then(|| rsx!(Child { }))}
|
||||
{false.then(|| rsx!(Child { }))}
|
||||
))
|
||||
};
|
||||
static Child: Component<()> = |cx, props| {
|
||||
static Child: Component<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
h1 {"goodbye"}
|
||||
|
||||
Reference in new issue
Block a user