From 5dbc933af5933df8bee4bee2a999bf86e1b640c5 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 25 Sep 2022 09:25:42 +0200 Subject: [PATCH] Context: cleanup - avoid storing a copy of children The new changed() signature allows accessing old_props, so there is no more need to store an additional copy of children. --- packages/yew/src/context.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/yew/src/context.rs b/packages/yew/src/context.rs index 3e92c828ded..74514002b79 100644 --- a/packages/yew/src/context.rs +++ b/packages/yew/src/context.rs @@ -24,7 +24,6 @@ pub struct ContextProviderProps { #[derive(Debug)] pub struct ContextProvider { context: T, - children: Children, consumers: RefCell>>, } @@ -85,20 +84,15 @@ impl Component for ContextProvider { fn create(ctx: &Context) -> Self { let props = ctx.props(); Self { - children: props.children.clone(), context: props.context.clone(), consumers: RefCell::new(Slab::new()), } } - fn changed(&mut self, ctx: &Context, _old_props: &Self::Properties) -> bool { + fn changed(&mut self, ctx: &Context, old_props: &Self::Properties) -> bool { let props = ctx.props(); - let should_render = if self.children == props.children { - false - } else { - self.children = props.children.clone(); - true - }; + + let should_render = old_props.children != props.children; if self.context != props.context { self.context = props.context.clone(); @@ -108,7 +102,7 @@ impl Component for ContextProvider { should_render } - fn view(&self, _ctx: &Context) -> Html { - html! { <>{ self.children.clone() } } + fn view(&self, ctx: &Context) -> Html { + html! { <>{ ctx.props().children.clone() } } } }