Feat: massive changes to definition of components
This change switches back to the original `ctx<props>` syntax for commponents. This lets lifetime elision to remove the need to match exactly which lifetime (props or ctx) gets carried to the output. As such, `Props` is currently required to be static. It *is* possible to loosen this restriction, and will be done in the future, though only through adding metadata about the props through the Props derive macro. Implementing the IS_STATIC trait is unsafe, so the derive macro will do it through some heuristics. For now, this unlocks sharing vnodes from parents to children, enabling pass-thru components, fragments, portals, etc.
This commit is contained in:
1 parent
c1fd848f89
commit
508c560320
82 files changed
+692
-558
No files matched your search
@@ -16,22 +16,22 @@ fn test() {
|
||||
// let g: FC<ButtonProps> = CustomButton;
|
||||
}
|
||||
|
||||
trait Render {
|
||||
fn render(ctx: Context, props: &Self) -> DomTree;
|
||||
trait Render: Sized {
|
||||
fn render(ctx: Context<Self>) -> VNode;
|
||||
}
|
||||
// include as much as you might accept
|
||||
struct Button<'a> {
|
||||
onhover: Option<&'a dyn Fn()>,
|
||||
struct Button {
|
||||
onhover: Option<Box<dyn Fn()>>,
|
||||
}
|
||||
|
||||
impl Render for Button<'_> {
|
||||
fn render(ctx: Context, _props: &Self) -> DomTree {
|
||||
impl Render for Button {
|
||||
fn render(ctx: Context<Self>) -> VNode {
|
||||
let _onfocus = move |_evt: ()| log::debug!("Focused");
|
||||
|
||||
// todo!()
|
||||
ctx.render(rsx! {
|
||||
button {
|
||||
// ..props.attrs,
|
||||
// ..ctx.attrs,
|
||||
class: "abc123",
|
||||
// style: { a: 2, b: 3, c: 4 },
|
||||
onclick: move |_evt| {
|
||||
@@ -47,7 +47,7 @@ impl Render for Button<'_> {
|
||||
}
|
||||
|
||||
// #[fc]
|
||||
// fn Button(ctx: Context, onhover: Option<&dyn Fn()>) -> DomTree {}
|
||||
// fn Button(ctx: Context, onhover: Option<&dyn Fn()>) -> VNode {}
|
||||
|
||||
// h1 {
|
||||
// tag: "type", abc: 123, class: "big small wide short",
|
||||
|
||||
Reference in new issue
Block a user