Skip to content

Commit

Permalink
Merge pull request #1075 from fabulous-dev/fix-key-lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Apr 13, 2024
2 parents 34895ab + f68f539 commit 062f9e8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/Fabulous/Component.fs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ type Component(treeContext: ViewTreeContext, body: ComponentBody, context: Compo
treeContext.SyncAction(this.RenderInternal)

module Component =
let Data =
Attributes.defineSimpleScalar<ComponentData> "Component_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ())

let WidgetKey =
let key = WidgetDefinitionStore.getNextKey()

Expand All @@ -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"

Expand All @@ -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"

Expand All @@ -381,9 +390,6 @@ module Component =
WidgetDefinitionStore.set key definition
key

let Data =
Attributes.defineSimpleScalar<ComponentData> "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<binding> * context: ComponentContext -> struct (int<binding> * WidgetBuilder<unit, 'marker>)
Expand Down
16 changes: 11 additions & 5 deletions src/Fabulous/MvuComponent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type MvuComponentData =
Arg: obj }

module MvuComponent =
let Data =
Attributes.defineSimpleScalar<MvuComponentData> "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ())

let WidgetKey =
let key = WidgetDefinitionStore.getNextKey()

Expand All @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -87,9 +96,6 @@ module MvuComponent =
WidgetDefinitionStore.set key definition
key

let Data =
Attributes.defineSimpleScalar<MvuComponentData> "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ())

let canReuseMvuComponent (prev: Widget) (curr: Widget) =
let prevData =
match prev.ScalarAttributes with
Expand Down

0 comments on commit 062f9e8

Please sign in to comment.