Skip to content

Commit 16a707a

Browse files
authored
Merge pull request #1069 from fabulous-dev/destroy-component-on-arg-change
Recreate component on arg change
2 parents 6eef147 + 4148e18 commit 16a707a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
_No unreleased changes_
1111

12+
## [2.5.0-pre11] - 2024-02-19
13+
14+
### Fixed
15+
- Recreate component on arg change by @TimLariviere (https://github.com/fabulous-dev/Fabulous/pull/1069)
16+
1217
## [2.5.0-pre10] - 2024-02-19
1318

1419
### Fixed
@@ -105,7 +110,8 @@ _No unreleased changes_
105110
### Changed
106111
- 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)
107112

108-
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.5.0-pre10...HEAD
113+
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.5.0-pre11...HEAD
114+
[2.5.0-pre11]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre11
109115
[2.5.0-pre10]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre10
110116
[2.5.0-pre9]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre9
111117
[2.5.0-pre8]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre8

src/Fabulous/MvuComponent.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Fabulous
22

3+
open System
34
open System.Runtime.CompilerServices
45

56
[<Struct; NoEquality; NoComparison>]
@@ -89,6 +90,20 @@ module MvuComponent =
8990
let Data =
9091
Attributes.defineSimpleScalar<MvuComponentData> "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ())
9192

93+
let canReuseMvuComponent (prev: Widget) (curr: Widget) =
94+
let prevData =
95+
match prev.ScalarAttributes with
96+
| ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData
97+
| _ -> failwith "Component widget must have a body"
98+
99+
let currData =
100+
match curr.ScalarAttributes with
101+
| ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData
102+
| _ -> failwith "Component widget must have a body"
103+
104+
// NOTE: Somehow using = here crashes the app and prevents debugging...
105+
Object.Equals(prevData.Arg, currData.Arg)
106+
92107
/// Delegate used by the MvuComponentBuilder to compose a component body
93108
/// It will be aggressively inlined by the compiler leaving no overhead, only a pure function that returns a WidgetBuilder
94109
type MvuComponentBodyBuilder<'msg, 'marker> =

src/Fabulous/View.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module ViewHelpers =
88
false
99
else if (prevKey = Memo.MemoWidgetKey) then
1010
Memo.canReuseMemoizedWidget prevWidget currWidget
11+
else if (prevKey = MvuComponent.WidgetKey) then
12+
MvuComponent.canReuseMvuComponent prevWidget currWidget
1113
else
1214
true
1315

0 commit comments

Comments
 (0)