Feat: move out scope into its own file
This commit is contained in:
1 parent
e939373616
commit
c9d95dd1dc
15 files changed
+447
-482
No files matched your search
@@ -1,102 +1,9 @@
|
||||
#![allow(unused, non_upper_case_globals)]
|
||||
use bumpalo::Bump;
|
||||
use dioxus_core::nodebuilder::*;
|
||||
use dioxus_core::prelude::VNode;
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core::{nodebuilder::*, virtual_dom::Properties};
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use std::{collections::HashMap, future::Future, marker::PhantomData};
|
||||
|
||||
fn main() {}
|
||||
|
||||
// struct VC<P, F = fn(Context<P>) -> VNode> {
|
||||
// f: F,
|
||||
// _a: std::marker::PhantomData<(P, F)>, // cell: OnceCell<T>,
|
||||
// // init: Cell<Option<F>>
|
||||
// }
|
||||
// impl<P, F> VC<P, F> {
|
||||
// const fn new(init: F) -> VC<P, F> {
|
||||
// Self {
|
||||
// _a: std::marker::PhantomData {},
|
||||
// f: init,
|
||||
// }
|
||||
// }
|
||||
// fn builder() -> P {
|
||||
// // P::new()
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Build a new functional component
|
||||
// static SomeComp: VC<()> = VC::new(|ctx| {
|
||||
// // This is a component, apparently
|
||||
// // still not useful because we can't have bounds
|
||||
|
||||
// ctx.view(html! {
|
||||
// <div>
|
||||
|
||||
// </div>
|
||||
// })
|
||||
// });
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
static BILL: Lazy<fn(Context<()>) -> String> = Lazy::new(|| {
|
||||
//
|
||||
|c| "BLAH".to_string()
|
||||
});
|
||||
|
||||
// struct FUNC<F = fn() -> T> {}
|
||||
|
||||
struct SomeBuilder {}
|
||||
|
||||
// struct DummyRenderer {
|
||||
// alloc: Bump,
|
||||
// }
|
||||
|
||||
// impl DummyRenderer {
|
||||
// // "Renders" a domtree by logging its children and outputs
|
||||
// fn render() {}
|
||||
|
||||
// // Takes a domtree, an initial value, a new value, and produces the diff list
|
||||
// fn produce_diffs() {}
|
||||
// }
|
||||
|
||||
// struct Props<'a> {
|
||||
// name: &'a str,
|
||||
// }
|
||||
|
||||
// /// This component does "xyz things"
|
||||
// /// This is sample documentation
|
||||
// static Component: FC<Props> = |ctx| {
|
||||
// // This block mimics that output of the html! macro
|
||||
|
||||
// DomTree::new(move |bump| {
|
||||
// // parse into RSX structures
|
||||
// // regurgetate as rust types
|
||||
|
||||
// // <div> "Child 1" "Child 2"</div>
|
||||
// div(bump)
|
||||
// .attr("class", "edit")
|
||||
// .child(text("Child 1"))
|
||||
// .child(text("Child 2"))
|
||||
// .finish()
|
||||
// })
|
||||
// };
|
||||
|
||||
// /*
|
||||
// source
|
||||
// |> c1 -> VNode
|
||||
// |> c2 -> VNode
|
||||
// |> c3 -> VNode
|
||||
// |> c4 -> VNode
|
||||
// */
|
||||
@@ -1,7 +1,7 @@
|
||||
#![allow(unused, non_upper_case_globals, non_snake_case)]
|
||||
use bumpalo::Bump;
|
||||
use dioxus_core::nodebuilder::*;
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core::{nodebuilder::*, virtual_dom::Properties};
|
||||
use std::{collections::HashMap, future::Future, marker::PhantomData};
|
||||
|
||||
fn main() {
|
||||
@@ -9,7 +9,7 @@ fn main() {
|
||||
component,
|
||||
Props {
|
||||
blah: false,
|
||||
text: "blah",
|
||||
text: "blah".into(),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -45,11 +45,12 @@ fn main() {
|
||||
|
||||
// ~~~ Text shared between components via props can be done with lifetimes! ~~~
|
||||
// Super duper efficient :)
|
||||
struct Props<'src> {
|
||||
struct Props {
|
||||
blah: bool,
|
||||
text: &'src str,
|
||||
text: String,
|
||||
// text: &'src str,
|
||||
}
|
||||
impl<'src> Properties for Props<'src> {
|
||||
impl Properties for Props {
|
||||
fn new() -> Self {
|
||||
todo!()
|
||||
}
|
||||
@@ -88,7 +89,7 @@ fn BuilderComp<'a>(ctx: &'a Context<'a, Props>) -> VNode<'a> {
|
||||
div(bump)
|
||||
.attr("class", "edit")
|
||||
.child(text("Hello"))
|
||||
.child(text(ctx.props.text))
|
||||
.child(text(ctx.props.text.as_ref()))
|
||||
.finish()
|
||||
})
|
||||
}
|
||||
@@ -99,23 +100,7 @@ fn EffcComp(ctx: &Context, name: &str) -> VNode {
|
||||
// However, both of these are "lazy" - they need to be evaluated (aka, "viewed")
|
||||
// We can "view" them with Context for ultimate speed while inside components
|
||||
// use "phase" style allocation;
|
||||
/*
|
||||
nodes...
|
||||
text...
|
||||
attrs...
|
||||
<div> // node0
|
||||
<div> </div> // node1
|
||||
{// support some expression} // node 2
|
||||
</div>
|
||||
let node0;
|
||||
let node1;
|
||||
let node2 = evaluate{}.into();
|
||||
let g= |bump| {1};
|
||||
g(bump).into()
|
||||
|
||||
*/
|
||||
|
||||
// should we automatically view the output or leave it?
|
||||
ctx.view(html! {
|
||||
<div>
|
||||
// your template goes here
|
||||
@@ -129,6 +114,8 @@ fn FullySuspended<'a>(ctx: &'a Context<Props>) -> VNode<'a> {
|
||||
let i: i32 = 0;
|
||||
|
||||
// full suspended works great with just returning VNodes!
|
||||
// Feel free to capture the html! macro directly
|
||||
// Anything returned here is automatically viewed
|
||||
let tex = match i {
|
||||
1 => html! { <div> </div> },
|
||||
2 => html! { <div> </div> },
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use bumpalo::Bump;
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_core::{
|
||||
prelude::{html, Context, VElement, VNode, FC},
|
||||
virtual_dom::{Properties, Scope},
|
||||
prelude::{html, Context, Properties, VElement, VNode, FC},
|
||||
scope::Scope,
|
||||
};
|
||||
use std::{
|
||||
any::Any,
|
||||
|
||||
@@ -5,17 +5,15 @@
|
||||
//! render it again
|
||||
//! consume the diffs and write that to a renderer
|
||||
|
||||
use dioxus_core::{
|
||||
prelude::*,
|
||||
virtual_dom::{Properties, Scope},
|
||||
};
|
||||
use dioxus_core::{prelude::*, scope::Scope};
|
||||
|
||||
fn main() {
|
||||
let mut scope = Scope::new(Example);
|
||||
let ctx = scope.create_context::<Props>();
|
||||
fn main() -> Result<(), ()> {
|
||||
let p1 = Props { name: "bob".into() };
|
||||
|
||||
let p2 = Props { name: "bob".into() };
|
||||
let mut vdom = VirtualDom::new_with_props(Example, p1);
|
||||
vdom.progress()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct Props {
|
||||
|
||||
Reference in new issue
Block a user