From 58bcc4404e0083276576299217fe6e3187d0ef14 Mon Sep 17 00:00:00 2001 From: Nick Senger Date: Wed, 11 Jan 2023 07:45:36 -0800 Subject: feat: provide `&Dependency` to `Lazy` widget `View` --- lazy/src/lazy.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lazy/src/lazy.rs') diff --git a/lazy/src/lazy.rs b/lazy/src/lazy.rs index 16709f8d..933def96 100644 --- a/lazy/src/lazy.rs +++ b/lazy/src/lazy.rs @@ -16,7 +16,7 @@ use std::rc::Rc; #[allow(missing_debug_implementations)] pub struct Lazy<'a, Message, Renderer, Dependency, View> { dependency: Dependency, - view: Box View + 'a>, + view: Box View + 'a>, element: RefCell< Option>>>>, >, @@ -28,7 +28,10 @@ where Dependency: Hash + 'a, View: Into>, { - pub fn new(dependency: Dependency, view: impl Fn() -> View + 'a) -> Self { + pub fn new( + dependency: Dependency, + view: impl Fn(&Dependency) -> View + 'a, + ) -> Self { Self { dependency, view: Box::new(view), @@ -88,7 +91,8 @@ where self.dependency.hash(&mut hasher); let hash = hasher.finish(); - let element = Rc::new(RefCell::new(Some((self.view)().into()))); + let element = + Rc::new(RefCell::new(Some((self.view)(&self.dependency).into()))); (*self.element.borrow_mut()) = Some(element.clone()); @@ -109,7 +113,7 @@ where if current.hash != new_hash { current.hash = new_hash; - let element = (self.view)().into(); + let element = (self.view)(&self.dependency).into(); current.element = Rc::new(RefCell::new(Some(element))); (*self.element.borrow_mut()) = Some(current.element.clone()); -- cgit