Feat: major overhaul to diffing

This commit is contained in:
Jonathan Kelley committed 2021-05-15 12:03:08 -04:00
1 parent c809095124
commit 9810feebf5
37 files changed
+1470 -1129

No files matched your search

+3 -3
View File
@@ -7,7 +7,7 @@
fn main() {}
use std::borrow::Borrow;
use std::{borrow::Borrow, rc::Rc};
use dioxus_core::prelude::*;
@@ -36,7 +36,7 @@ fn app<'a>(ctx: Context<'a>, props: &Props) -> DomTree {
// create the props with nothing but the fc<T>
fc_to_builder(ChildItem)
.item(child)
.item_handler(set_val)
.item_handler(set_val.clone())
.build(),
None,
));
@@ -52,7 +52,7 @@ struct ChildProps<'a> {
item: &'a ListItem,
// Even pass down handlers!
item_handler: &'a dyn Fn(i32),
item_handler: Rc<dyn Fn(i32)>,
}
impl PartialEq for ChildProps<'_> {
-102
View File
@@ -1,102 +0,0 @@
// #![allow(unused, non_upper_case_globals)]
// use bumpalo::Bump;
// use dioxus_core::nodebuilder::*;
// use dioxus_core::prelude::VNode;
// use dioxus_core::prelude::*;
// use once_cell::sync::{Lazy, OnceCell};
use std::ops::Deref;
/*
A guard over underlying T that provides access in callbacks via "Copy"
*/
// #[derive(Clone)]
struct ContextGuard2<T> {
_val: std::marker::PhantomData<T>,
}
impl<T> Clone for ContextGuard2<T> {
// we aren't cloning the underlying data so clone isn't necessary
fn clone(&self) -> Self {
todo!()
}
}
impl<T> Copy for ContextGuard2<T> {}
impl<T> ContextGuard2<T> {
fn get<'a>(&'a self) -> ContextLock<'a, T> {
todo!()
}
}
struct ContextLock<'a, T> {
_val: std::marker::PhantomData<&'a T>,
}
impl<'a, T: 'a + 'static> Deref for ContextLock<'a, T> {
type Target = T;
fn deref<'b>(&'b self) -> &'b T {
todo!()
}
}
/*
The source of the data that gives out context guards
*/
struct Context<'a> {
_p: std::marker::PhantomData<&'a ()>,
}
impl<'a> Context<'a> {
fn use_context<'b, I, O: 'b>(&self, _f: fn(&'b I) -> O) -> ContextGuard2<O> {
todo!()
}
fn add_listener(&self, _f: impl Fn(()) + 'a) {
todo!()
}
fn render(self, _f: impl FnOnce(&'a String) + 'a) {}
// fn view(self, f: impl for<'b> FnOnce(&'a String) + 'a) {}
// fn view(self, f: impl for<'b> FnOnce(&'b String) + 'a) {}
}
struct Example {
value: String,
}
/*
Example compiling
*/
fn t<'a>(ctx: Context<'a>) {
let value = ctx.use_context(|b: &Example| &b.value);
// Works properly, value is moved by copy into the closure
let refed = value.get();
println!("Value is {}", refed.as_str());
let r2 = refed.as_str();
ctx.add_listener(move |_| {
// let val = value.get().as_str();
let _val2 = r2.as_bytes();
println!("v2 is {}", r2);
// println!("refed is {}", refed);
});
// let refed = value.deref();
// returns &String
// returns &String
// let refed = value.deref(); // returns &String
// let refed = value.deref(); // returns &String
// Why does this work? This closure should be static but is holding a reference to refed
// The context guard is meant to prevent any references moving into the closure
// if the references move they might become invalid due to mutlithreading issues
ctx.add_listener(move |_| {
// let val = value.as_str();
// let val2 = refed.as_bytes();
});
ctx.render(move |_b| {});
}
fn main() {}
-63
View File
@@ -1,63 +0,0 @@
// #[macro_use]
// use dioxus_core::ifmt;
// use fstrings::format_args_f;
fn main() {
let bump = bumpalo::Bump::new();
let _b = &bump;
let _world = "123";
// dioxus_core::ifmt!(in b; "Hello {world}";);
}
// let mut s = bumpalo::collections::String::new_in(b);
// fstrings::write_f!(s, "Hello {world}");
// dbg!(s);
// let p = {
// println!("hello, {}", &world);
// ()
// };
// let g = format_args!("hello {world}", world = world);
// let g = dioxus_core::ifmt!(in b, "Hello {world}");
// let g = ifmt!(in b, "hhello {world}");
// let g = ::core::fmt::Arguments::new_v1(
// &["hello "],
// &match (&world,) {
// (arg0,) => [::core::fmt::ArgumentV1::new(
// arg0,
// ::core::fmt::Display::fmt,
// )],
// },
// );
// fn main() {
// let bump = bumpalo::Bump::new();
// let b = &bump;
// let world = "123";
// let world = 123;
// let g = {
// use bumpalo::core_alloc::fmt::Write;
// use ::dioxus_core::prelude::bumpalo;
// use ::dioxus_core::prelude::format_args_f;
// let bump = b;
// let mut s = bumpalo::collections::String::new_in(bump);
// let _ = (&mut s).write_fmt(::core::fmt::Arguments::new_v1(
// &[""],
// &match (&::core::fmt::Arguments::new_v1(
// &["hhello "],
// &match (&world,) {
// (arg0,) => [::core::fmt::ArgumentV1::new(
// arg0,
// ::core::fmt::Display::fmt,
// )],
// },
// ),)
// {
// (arg0,) => [::core::fmt::ArgumentV1::new(
// arg0,
// ::core::fmt::Display::fmt,
// )],
// },
// ));
// s
// };
// }
+54
View File
@@ -0,0 +1,54 @@
use baller::Baller;
use dioxus_core::prelude::*;
fn main() {
let g = rsx! {
div {
crate::baller::Baller {}
baller::Baller {
}
Taller {
a: "asd"
}
baller::Baller {}
baller::Baller {}
Baller {}
div {
a: "asd",
a: "asd",
a: "asd",
a: "asd",
div {
"asdas",
"asdas",
"asdas",
"asdas",
div {
},
div {
},
}
}
}
};
}
mod baller {
use super::*;
pub struct BallerProps {}
pub fn Baller(ctx: Context, props: &()) -> DomTree {
todo!()
}
}
#[derive(Debug, PartialEq, Props)]
pub struct TallerProps {
a: &'static str,
}
pub fn Taller(ctx: Context, props: &TallerProps) -> DomTree {
todo!()
}