From cae5c76bedb504139f16fef3e581e9ee7f0fd32d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 12 Sep 2023 21:07:35 -0600 Subject: [PATCH] Checkpoint --- crates/storybook/src/sketch.rs | 54 ++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/crates/storybook/src/sketch.rs b/crates/storybook/src/sketch.rs index 13822ecf82..28bdde5cd2 100644 --- a/crates/storybook/src/sketch.rs +++ b/crates/storybook/src/sketch.rs @@ -115,7 +115,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { impl<'app, 'win> WindowContext<'app, 'win> { fn add_entity( &mut self, - build_entity: impl FnOnce(&mut ViewContext<'app, 'win, '_, T>) -> T, + build_entity: impl FnOnce(&mut ViewContext<'_, 'app, 'win, T>) -> T, ) -> Handle { let id = EntityId::new(&mut self.app_context().entity_count); let mut cx = ViewContext::mutable(self, id); @@ -155,16 +155,16 @@ impl<'app, 'win> WindowContext<'app, 'win> { } #[derive(Deref, DerefMut)] -pub struct ViewContext<'a, 'b, 'c, T> { +pub struct ViewContext<'parent, 'app, 'win, T> { #[deref] #[deref_mut] - window_cx: Reference<'c, WindowContext<'a, 'b>>, + window_cx: Reference<'parent, WindowContext<'app, 'win>>, entity_type: PhantomData, entity_id: EntityId, } -impl<'a, 'b, 'c, V> ViewContext<'a, 'b, 'c, V> { - fn mutable(window_cx: &'c mut WindowContext<'a, 'b>, entity_id: EntityId) -> Self { +impl<'cx, 'app: 'cx, 'win: 'cx, V> ViewContext<'cx, 'app, 'win, V> { + fn mutable(window_cx: &'cx mut WindowContext<'app, 'win>, entity_id: EntityId) -> Self { Self { window_cx: Reference::Mutable(window_cx), entity_id, @@ -172,7 +172,7 @@ impl<'a, 'b, 'c, V> ViewContext<'a, 'b, 'c, V> { } } - fn immutable(window_cx: &'c WindowContext<'a, 'b>, entity_id: EntityId) -> Self { + fn immutable(window_cx: &'cx WindowContext<'app, 'win>, entity_id: EntityId) -> Self { Self { window_cx: Reference::Immutable(window_cx), entity_id, @@ -213,18 +213,47 @@ pub struct Handle { entity_type: PhantomData, } -trait Context { - type EntityContext; +trait Context<'a, 'parent, 'app, 'win> { + type EntityContext; - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, Self::EntityContext) -> R, ) -> R; } -impl Handle { - fn update( +impl<'a, 'parent: 'a, 'app, 'win> Context<'a, 'parent, 'app, 'win> for AppContext { + type EntityContext = &'a mut ModelContext<'parent, T>; + + fn update_entity( + &mut self, + handle: &Handle, + update: impl FnOnce(&mut T, Self::EntityContext) -> R, + ) -> R { + todo!() + } +} + +impl<'a, 'parent, 'app, 'win> Context<'a, 'parent, 'app, 'win> for WindowContext<'app, 'win> +where + 'parent: 'a, + 'app: 'parent, + 'win: 'parent, +{ + type EntityContext = &'a mut ViewContext<'parent, 'app, 'win, T>; + + fn update_entity( + &mut self, + handle: &Handle, + update: impl FnOnce(&mut T, Self::EntityContext) -> R, + ) -> R { + todo!() + } +} + +impl Handle { + fn update<'a, 'parent, 'app, 'win, C: Context<'a, 'parent, 'app, 'win>, R>( &self, cx: &mut C, update: impl FnOnce(&mut T, C::EntityContext) -> R, @@ -358,7 +387,8 @@ pub fn view( render: impl 'static + Fn(&mut ChildState, &mut ViewContext) -> AnyElement, ) -> View { View { - render: todo!(), // Rc::new(move |cx| state.update(cx, |state, cx| render(state, cx))), + // render: Rc::new(move |cx| state.update(cx, |state, cx| render(state, cx))), + render: todo!(), } }