From e6b1c48fec83243bc6273b1f8413a77b9dcee214 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 12 Apr 2024 19:44:43 +0100 Subject: [PATCH 1/3] WIP --- src/Fabulous/Component.fs | 10 ++++++---- src/Fabulous/MvuComponent.fs | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Fabulous/Component.fs b/src/Fabulous/Component.fs index 72a035910..965200c24 100644 --- a/src/Fabulous/Component.fs +++ b/src/Fabulous/Component.fs @@ -336,6 +336,9 @@ type Component(treeContext: ViewTreeContext, body: ComponentBody, context: Compo treeContext.SyncAction(this.RenderInternal) module Component = + let Data = + Attributes.defineSimpleScalar "Component_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ()) + let WidgetKey = let key = WidgetDefinitionStore.getNextKey() @@ -349,7 +352,9 @@ module Component = | ValueNone -> failwith "Component widget must have a body" | ValueSome attrs -> let data = - match Array.tryHead attrs with + let scalarAttrsOpt = + attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + match scalarAttrsOpt with | Some attr -> attr.Value :?> ComponentData | None -> failwith "Component widget must have a body" @@ -381,9 +386,6 @@ module Component = WidgetDefinitionStore.set key definition key - let Data = - Attributes.defineSimpleScalar "Component_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ()) - /// Delegate used by the ComponentBuilder to compose a component body /// It will be aggressively inlined by the compiler leaving no overhead, only a pure function that returns a WidgetBuilder type ComponentBodyBuilder<'marker> = delegate of bindings: int * context: ComponentContext -> struct (int * WidgetBuilder) diff --git a/src/Fabulous/MvuComponent.fs b/src/Fabulous/MvuComponent.fs index 39b9d3886..ec1e114eb 100644 --- a/src/Fabulous/MvuComponent.fs +++ b/src/Fabulous/MvuComponent.fs @@ -10,6 +10,9 @@ type MvuComponentData = Arg: obj } module MvuComponent = + let Data = + Attributes.defineSimpleScalar "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ()) + let WidgetKey = let key = WidgetDefinitionStore.getNextKey() @@ -59,7 +62,10 @@ module MvuComponent = | ValueNone -> failwith "Component widget must have a body" | ValueSome attrs -> let data = - match Array.tryHead attrs with + let scalarAttrsOpt = + attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + + match scalarAttrsOpt with | Some attr -> attr.Value :?> MvuComponentData | None -> failwith "Component widget must have a body" @@ -87,9 +93,6 @@ module MvuComponent = WidgetDefinitionStore.set key definition key - let Data = - Attributes.defineSimpleScalar "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ()) - let canReuseMvuComponent (prev: Widget) (curr: Widget) = let prevData = match prev.ScalarAttributes with From 63ceeb0a21aaf8322af3fd267d80839b82eec40a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 12 Apr 2024 20:58:44 +0100 Subject: [PATCH 2/3] Find the component data key in the attribute keys --- src/Fabulous/Component.fs | 6 +++++- src/Fabulous/MvuComponent.fs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Fabulous/Component.fs b/src/Fabulous/Component.fs index 965200c24..e16382c71 100644 --- a/src/Fabulous/Component.fs +++ b/src/Fabulous/Component.fs @@ -354,6 +354,7 @@ module Component = let data = let scalarAttrsOpt = attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + match scalarAttrsOpt with | Some attr -> attr.Value :?> ComponentData | None -> failwith "Component widget must have a body" @@ -371,7 +372,10 @@ module Component = | ValueNone -> failwith "Component widget must have a body" | ValueSome attrs -> let data = - match Array.tryHead attrs with + let scalarAttrsOpt = + attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + + match scalarAttrsOpt with | Some attr -> attr.Value :?> ComponentData | None -> failwith "Component widget must have a body" diff --git a/src/Fabulous/MvuComponent.fs b/src/Fabulous/MvuComponent.fs index ec1e114eb..a54c8d741 100644 --- a/src/Fabulous/MvuComponent.fs +++ b/src/Fabulous/MvuComponent.fs @@ -26,7 +26,10 @@ module MvuComponent = | ValueNone -> failwith "Component widget must have a body" | ValueSome attrs -> let data = - match Array.tryHead attrs with + let scalarAttrsOpt = + attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + + match scalarAttrsOpt with | Some attr -> attr.Value :?> MvuComponentData | None -> failwith "Component widget must have a body" From f68f539fdfeef84443e8e3cb12c9bf486c04abc7 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 12 Apr 2024 21:17:49 +0100 Subject: [PATCH 3/3] Update release notes --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af106f13..c3c28afa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _No unreleased changes_ +## [3.0.0-pre3] - 2024-04-12 + +### Changed +- Find the component data key in the attribute keys (https://github.com/fabulous-dev/Fabulous/pull/1075) + ## [3.0.0-pre2] - 2024-03-025 ### Added @@ -120,7 +125,8 @@ _No unreleased changes_ ### Changed - Fabulous.XamarinForms & Fabulous.MauiControls have been moved been out of the Fabulous repository. Find them in their own repositories: [https://github.com/fabulous-dev/Fabulous.XamarinForms](https://github.com/fabulous-dev/Fabulous.XamarinForms) / [https://github.com/fabulous-dev/Fabulous.MauiControls](https://github.com/fabulous-dev/Fabulous.MauiControls) -[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre2...HEAD +[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre3...HEAD +[3.0.0-pre3]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre3 [3.0.0-pre2]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre2 [3.0.0-pre1]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre1 [2.5.0-pre11]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre11