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 diff --git a/src/Fabulous/Component.fs b/src/Fabulous/Component.fs index 72a035910..e16382c71 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,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" @@ -366,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" @@ -381,9 +390,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..a54c8d741 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() @@ -23,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" @@ -59,7 +65,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 +96,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