Skip to content

Commit

Permalink
Merge pull request #1076 from fabulous-dev/fix-scalar-attributes-data…
Browse files Browse the repository at this point in the history
…-key-lookup

Fix ScalarAttributes data key lookup
  • Loading branch information
edgarfgp committed Apr 19, 2024
2 parents 062f9e8 + 6637de5 commit 8d423e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 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-pre4] - 2024-04-16

### Changed
- Find the component data key in ScalarAttributes by @edgarfgp (https://github.com/fabulous-dev/Fabulous/pull/1076)

## [3.0.0-pre3] - 2024-04-12

### Changed
Expand Down Expand Up @@ -125,7 +130,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-pre3...HEAD
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre4...HEAD
[3.0.0-pre4]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre4
[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
Expand Down
17 changes: 15 additions & 2 deletions src/Fabulous/MvuComponent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,25 @@ module MvuComponent =
let canReuseMvuComponent (prev: Widget) (curr: Widget) =
let prevData =
match prev.ScalarAttributes with
| ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData
| ValueSome attrs ->
let scalarAttrsOpt =
attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key)

match scalarAttrsOpt with
| None -> failwithf "Component widget must have a body"
| Some value -> value.Value :?> MvuComponentData

| _ -> failwith "Component widget must have a body"

let currData =
match curr.ScalarAttributes with
| ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData
| ValueSome attrs ->
let scalarAttrsOpt =
attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key)

match scalarAttrsOpt with
| None -> failwithf "Component widget must have a body"
| Some value -> value.Value :?> MvuComponentData
| _ -> failwith "Component widget must have a body"

// NOTE: Somehow using = here crashes the app and prevents debugging...
Expand Down

0 comments on commit 8d423e4

Please sign in to comment.