Skip to content

Commit

Permalink
Merge pull request #1071 from fabulous-dev/improve-memo-reuse
Browse files Browse the repository at this point in the history
Include Memo.KeyData in CanReuseMemo
  • Loading branch information
TimLariviere committed Mar 4, 2024
2 parents 45ac759 + 98fcda8 commit 2bae3c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 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_

## [2.4.2] - 2024-03-04

### Changed
- Include Memo.KeyData in CanReuseMemo by @TimLariviere (https://github.com/fabulous-dev/Fabulous/pull/1071)

## [2.4.1] - 2024-01-29

### Added
Expand Down Expand Up @@ -55,7 +60,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/2.4.1...HEAD
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.4.2...HEAD
[2.4.2]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.4.2
[2.4.1]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.4.1
[2.4.0]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.4.0
[2.3.2]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.3.2
Expand Down
7 changes: 4 additions & 3 deletions src/Fabulous.Tests/APISketchTests/APISketchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ module MemoTests =
instance.ProcessMessage(SetMemoPart 99)

// rerendered because of memo key changed
let memoLabel = find<TestLabel> tree "memo" :> IText
Assert.AreEqual(2, renderCount)
Assert.AreEqual("99", memoLabel.Text)

Expand Down Expand Up @@ -534,11 +535,11 @@ module MemoTests =

let labelAgain = find<TestLabel> tree "label"

// same instance
Assert.AreSame(label, labelAgain)
// not same instance
Assert.AreNotSame(label, labelAgain)

// just changes text but kept the same color
Assert.AreEqual([ TextSet "one"; ColorSet "blue"; TextSet "two" ], label.changeList)
Assert.AreEqual([ TextSet "two"; ColorSet "blue" ], labelAgain.changeList)



Expand Down
6 changes: 5 additions & 1 deletion src/Fabulous/Memo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ module Memo =
| _ -> failwith "Memo widget cannot have extra attributes"

let internal canReuseMemoizedWidget prev next =
(getMemoData prev).MarkerType = (getMemoData next).MarkerType
let prevMemoData = getMemoData prev
let currMemoData = getMemoData next

prevMemoData.MarkerType = currMemoData.MarkerType
&& prevMemoData.KeyData = currMemoData.KeyData

let internal MemoAttribute: SimpleScalarAttributeDefinition<MemoData> =
{ Key = MemoAttributeKey
Expand Down

0 comments on commit 2bae3c3

Please sign in to comment.