WIP new api

This commit is contained in:
Evan Almloff committed 2022-04-08 21:17:37 -05:00
1 parent 3dd18b21b3
commit 92f48169e9
7 files changed
+422 -1

No files matched your search

+2
View File
@@ -10,10 +10,12 @@ homepage = "https://dioxuslabs.com"
dioxus-core = { path = "../core", version = "^0.2.0" }
dioxus-html = { path = "../html", version = "^0.2.0" }
dioxus-core-macro = { path = "../core-macro", version = "^0.2.0" }
dioxus-native-core-macro = { path = "../native-core-macro", version = "^0.2.0" }
stretch2 = { git = "https://github.com/DioxusLabs/stretch" }
smallvec = "1.6"
fxhash = "0.2"
anymap = "0.12.1"
[dev-dependencies]
rand = "0.8.5"
+1
View File
@@ -1,2 +1,3 @@
pub mod layout_attributes;
pub mod real_dom;
pub mod real_dom_new_api;
@@ -0,0 +1,58 @@
use std::any::TypeId;
use anymap::AnyMap;
use dioxus_core::{Attribute, VElement};
#[repr(transparent)]
pub struct NodeRef<'a>(&'a VElement<'a>);
impl<'a> NodeRef<'a> {
pub fn new(velement: &'a VElement<'a>) -> Self {
Self(velement)
}
pub fn tag(&self) -> &'a str {
self.0.tag
}
pub fn namespace(&self) -> Option<&'a str> {
self.0.namespace
}
pub fn attributes(&self) -> &'a [Attribute<'a>] {
self.0.attributes
}
}
pub trait ChildDepState: PartialEq {
type Ctx;
type DepState: ChildDepState;
fn reduce(&mut self, node: NodeRef, children: Vec<&Self::DepState>, ctx: &Self::Ctx);
}
pub trait ParentDepState: PartialEq {
type Ctx;
type DepState: ParentDepState;
fn reduce(&mut self, node: NodeRef, parent: &Self::DepState, ctx: &Self::Ctx);
}
pub trait NodeDepState: PartialEq {
type Ctx;
fn reduce(&mut self, node: NodeRef, ctx: &Self::Ctx);
}
pub trait State {
fn update_node_dep_state(&mut self, ty: TypeId, node: NodeRef, ctx: &AnyMap);
fn child_dep_types(&self) -> Vec<TypeId>;
fn update_parent_dep_state(&mut self, ty: TypeId, node: NodeRef, parent: &Self, ctx: &AnyMap);
fn parent_dep_types(&self) -> Vec<TypeId>;
fn update_child_dep_state(
&mut self,
ty: TypeId,
node: NodeRef,
children: Vec<&Self>,
ctx: &AnyMap,
);
fn node_dep_types(&self) -> Vec<TypeId>;
}
+62
View File
@@ -0,0 +1,62 @@
use dioxus_native_core::real_dom_new_api::*;
use dioxus_native_core_macro::*;
#[derive(State)]
struct Z {
// depends on just attributes and no context
#[node_dep_state()]
x: A,
// depends on attributes, the B component of children and i32 context
#[child_dep_state(i32, B)]
y: B,
// depends on attributes, the C component of it's parent and a u8 context
#[parent_dep_state(u8, C)]
z: C,
}
// struct Z {
// x: A,
// y: B,
// z: C,
// }
use dioxus_native_core::real_dom_new_api::NodeDepState;
#[derive(PartialEq)]
struct A;
impl NodeDepState for A {
type Ctx = ();
fn reduce(&mut self, _: NodeRef, _: &()) {
todo!()
}
}
#[derive(PartialEq)]
struct B;
impl ChildDepState for B {
type Ctx = i32;
type DepState = Self;
fn reduce(
&mut self,
_: dioxus_native_core::real_dom_new_api::NodeRef,
_: Vec<&Self::DepState>,
_: &i32,
) {
todo!()
}
}
#[derive(PartialEq)]
struct C;
impl ParentDepState for C {
type Ctx = u8;
type DepState = Self;
fn reduce(
&mut self,
_: dioxus_native_core::real_dom_new_api::NodeRef,
_: &Self::DepState,
_: &u8,
) {
todo!()
}
}