Skip to content

Commit 7fe2a8d

Browse files
authored
Merge pull request #1056 from fabulous-dev/refactor-component
Consolidate Component API with existing code
2 parents fe3548c + 56387be commit 7fe2a8d

22 files changed

+515
-856
lines changed

CHANGELOG.md

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

1010
_No unreleased changes_
1111

12+
## [2.5.0-pre3] - 2024-01-16
13+
14+
### Changed
15+
- Consolidation of the new Component API and the existing ViewAdapter by @TimLariviere (https://github.com/fabulous-dev/Fabulous/pull/1056)
16+
17+
## [2.5.0-pre2] - 2023-11-22
18+
19+
### Changed
20+
- Couple of changes to the new Component API
21+
1222
## [2.5.0-pre1] - 2023-11-22
1323

1424
### Added
@@ -55,8 +65,10 @@ _No unreleased changes_
5565
### Changed
5666
- 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)
5767

58-
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.5.0-pre1...HEAD
59-
[2.5.0-preview.1]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre1
68+
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.5.0-pre3...HEAD
69+
[2.5.0-pre3]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre3
70+
[2.5.0-pre2]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre2
71+
[2.5.0-pre1]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre1
6072
[2.4.0]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.4.0
6173
[2.3.2]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.3.2
6274
[2.3.1]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.3.1

src/Fabulous.Benchmarks/Benchmarks.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Fabulous.Tests.Benchmarks
22

33
open BenchmarkDotNet.Attributes
4-
open BenchmarkDotNet.Jobs
54

65
open BenchmarkDotNet.Running
76
open Fabulous.Tests.APISketchTests.TestUI_Widgets
@@ -95,7 +94,7 @@ module DiffingAttributes =
9594

9695
let instance = Run.Instance program
9796

98-
let _tree = (instance.Start())
97+
let _tree = instance.Start()
9998

10099
for i in 1..100 do
101100
instance.ProcessMessage(IncBy i)
@@ -171,15 +170,15 @@ module DiffingSmallScalars =
171170

172171
let instance = Run.Instance program
173172

174-
let _tree = (instance.Start())
173+
let _tree = instance.Start()
175174

176175
for i in 1..100 do
177176
instance.ProcessMessage(IncBy 1UL)
178177

179178

180179

181180
[<EntryPoint>]
182-
let main argv =
181+
let main _argv =
183182
// BenchmarkRunner.Run<NestedTreeCreation.Benchmarks>()
184183
// |> ignore
185184
//

src/Fabulous.Tests/APISketchTests/APISketchTests.fs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open Fabulous.StackAllocatedCollections
44
open Fabulous.Tests.APISketchTests.Platform
55
open NUnit.Framework
66

7-
open Platform
87
open TestUI_Widgets
98
open Fabulous
109

@@ -75,7 +74,7 @@ module ButtonTests =
7574

7675
let update msg model =
7776
match msg with
78-
| Increment -> { model with count = model.count + 1 }
77+
| Increment -> { count = model.count + 1 }
7978

8079

8180
let view model =
@@ -137,30 +136,30 @@ module SimpleStackTests =
137136
instance.ProcessMessage(AddNew(1, "yo"))
138137
Assert.AreEqual(1, stack.Children.Count)
139138

140-
let label = stack.Children.[0] :?> TestLabel :> IText
139+
let label = stack.Children[0] :?> TestLabel :> IText
141140

142141
Assert.AreEqual(label.Text, "yo")
143142

144143
// add second in front
145144
instance.ProcessMessage(AddNew(2, "yo2"))
146145
Assert.AreEqual(2, stack.Children.Count)
147146

148-
let label = stack.Children.[0] :?> TestLabel :> IText
147+
let label = stack.Children[0] :?> TestLabel :> IText
149148

150149
Assert.AreEqual(label.Text, "yo2")
151150

152151
// modify the initial one
153152
instance.ProcessMessage(ChangeText(1, "just 1"))
154153

155-
let label = stack.Children.[1] :?> TestLabel :> IText
154+
let label = stack.Children[1] :?> TestLabel :> IText
156155

157156
Assert.AreEqual(label.Text, "just 1")
158157

159158
// delete the one in front
160159
instance.ProcessMessage(Delete 2)
161160
Assert.AreEqual(stack.Children.Count, 1)
162161

163-
let label = stack.Children.[0] :?> TestLabel :> IText
162+
let label = stack.Children[0] :?> TestLabel :> IText
164163

165164
Assert.AreEqual(label.Text, "just 1")
166165

@@ -549,9 +548,7 @@ module SmallScalars =
549548

550549
let update msg model =
551550
match msg with
552-
| Inc value ->
553-
{ model with
554-
value = model.value + value }
551+
| Inc value -> { value = model.value + value }
555552

556553
let view model =
557554
InlineNumericBag(model.value, model.value + 1UL, float(model.value + 2UL))
@@ -690,7 +687,7 @@ module Issue104 =
690687
module Issue1044 =
691688
[<Test>]
692689
let ``Multiple Widgets + for loops in builder causes crash`` () =
693-
let view model =
690+
let view _model =
694691
Stack() {
695692
Label($"Foo") // It also crashes only with the multiple for loops
696693
Label($"bar") // It also crashes only with the multiple for loops
@@ -717,7 +714,7 @@ module Issue1044 =
717714

718715
[<Test>]
719716
let ``Multiple for loops in builder causes crash`` () =
720-
let view model =
717+
let view _model =
721718
Stack() {
722719
for i = 0 to 10 do
723720
Label($"T{i}")
@@ -815,7 +812,7 @@ module ViewHelpers =
815812

816813
let childView = Button("Child button", ChildClick).automationId("childButton")
817814

818-
let parentView model =
815+
let parentView _model =
819816
Stack() {
820817
Button("Parent button", ParentClick).automationId("parentButton")
821818

@@ -846,7 +843,7 @@ module ViewHelpers =
846843
let ``Adding property modifiers to widget converted with View.map is valid`` () =
847844
let childView = Button("Child button", ChildClick).automationId("childButton")
848845

849-
let parentView model =
846+
let parentView _model =
850847
Stack() { (View.map ChildMessage childView).textColor("blue") }
851848

852849
let init () = true
@@ -867,7 +864,7 @@ module ViewHelpers =
867864

868865
let childView = Button("Child button", ChildClick).automationId("childButton")
869866

870-
let parentView model =
867+
let parentView _model =
871868
Stack() { (View.map ChildMessage childView).tap(ParentTap) }
872869

873870
let init () = true
@@ -899,7 +896,7 @@ module ViewHelpers =
899896
(View.map ChildMessage childView).tap(ParentTap)
900897
}
901898

902-
let grandParentView model =
899+
let grandParentView _model =
903900
Stack() {
904901
Button("Grand Parent button", GrandParentClick)
905902
.automationId("grandParentButton")
@@ -951,7 +948,7 @@ module ViewHelpers =
951948

952949
let parentView = (View.map ChildMessage childView).tap(ParentTap)
953950

954-
let grandParentView model =
951+
let grandParentView _model =
955952
(View.map ParentMessage parentView).tap2(GrandParentTap)
956953

957954
let init () = true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Fabulous.Tests.APISketchTests
2+
3+
module TestUI_Component =
4+
5+
open Fabulous
6+
open Platform
7+
8+
module Component =
9+
let ComponentProperty = "ComponentProperty"
10+
11+
let getComponent (target: obj) =
12+
(target :?> TestViewElement).PropertyBag.Item ComponentProperty

src/Fabulous.Tests/APISketchTests/TestUI.Platform.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ module Platform =
4747
interface IText with
4848
member x.Text
4949
with get () = text
50-
and set (value) =
50+
and set value =
5151
if x.record then
5252
x.changeList <- List.append x.changeList [ TextSet value ]
5353

5454
text <- value
5555

5656
member x.TextColor
5757
with get () = textColor
58-
and set (value) =
58+
and set value =
5959
if x.record then
6060
x.changeList <- List.append x.changeList [ ColorSet value ]
6161

src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module TestUI_Widgets =
1010
open Platform
1111
open TestUI_Attributes
1212
open TestUI_ViewNode
13+
open TestUI_Component
1314

1415

1516
//----WidgetsBuilderCE---
@@ -29,7 +30,7 @@ module TestUI_Widgets =
2930
TargetType = typeof<'T>
3031
CreateView =
3132
fun (widget, context, parentNode) ->
32-
let name = typeof<'T>.Name
33+
// let name = typeof<'T>.Name
3334
// printfn $"Creating view for {name}"
3435

3536
let view = new 'T()
@@ -211,7 +212,8 @@ module TestUI_Widgets =
211212
Logger =
212213
{ Log = fun _ -> ()
213214
MinLogLevel = LogLevel.Fatal }
214-
Dispatch = fun msg -> unbox<'msg> msg |> x.ProcessMessage }
215+
Dispatch = fun msg -> unbox<'msg> msg |> x.ProcessMessage
216+
GetComponent = Component.getComponent }
215217

216218
member x.ProcessMessage(msg: 'msg) =
217219
match state with
@@ -237,7 +239,7 @@ module TestUI_Widgets =
237239
()
238240

239241
member x.Start(arg: 'arg) =
240-
let model = (program.Init(arg))
242+
let model = program.Init(arg)
241243
let widget = program.View(model).Compile()
242244
let widgetDef = WidgetDefinitionStore.get widget.Key
243245

src/Fabulous.Tests/ArrayTests.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace Fabulous.Tests
33
open System
44
open Fabulous.StackAllocatedCollections
55
open NUnit.Framework
6-
open Fabulous
76

87
[<TestFixture>]
98
type ``Array tests``() =

src/Fabulous.Tests/Fabulous.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<ItemGroup>
88
<Compile Include="APISketchTests\TestUI.Platform.fs" />
99
<Compile Include="APISketchTests\TestUI.ViewNode.fs" />
10+
<Compile Include="APISketchTests\TestUI.Component.fs" />
1011
<Compile Include="APISketchTests\TestUI.ViewUpdaters.fs" />
1112
<Compile Include="APISketchTests\TestUI.Attributes.fs" />
1213
<Compile Include="APISketchTests\TestUI.Widgets.fs" />

src/Fabulous.Tests/ViewTests.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace Fabulous.Tests
33
open Fabulous
44
open Fabulous.StackAllocatedCollections.StackList
55
open NUnit.Framework
6-
open FsCheck.NUnit
76

87
type ITestControl =
98
interface

0 commit comments

Comments
 (0)