Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary ValueOptions #1095

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fantomas": {
"version": "6.3.16",
"version": "7.0.0",
"commands": [
"fantomas"
],
Expand Down
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[*.fs]
max_line_length=160
fsharp_space_before_lowercase_invocation = false
fsharp_space_before_lowercase_invocation = false
fsharp_max_dot_get_expression_width = 60
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 9.x
- name: Restore
run: dotnet restore ${SLN_FILE}
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 9.x
- name: Check code formatting
run: |
dotnet tool restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 9.x
- name: Restore
run: dotnet restore ${SLN_FILE}
- name: Build
Expand Down
9 changes: 5 additions & 4 deletions Fabulous.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Files", "_Solutio
README.md = README.md
CHANGELOG.md = CHANGELOG.md
LICENSE.md = LICENSE.md
.gitignore = .gitignore
pull_request.yml = .github/workflows/pull_request.yml
build.yml = .github/workflows/build.yml
release.yml = .github/workflows/release.yml
.gitignore = .gitignore
pull_request.yml = .github/workflows/pull_request.yml
build.yml = .github/workflows/build.yml
release.yml = .github/workflows/release.yml
.editorconfig = .editorconfig
Directory.Packages.props = Directory.Packages.props
Directory.Build.props = Directory.Build.props
EndProjectSection
Expand Down
5 changes: 0 additions & 5 deletions global.json

This file was deleted.

8 changes: 2 additions & 6 deletions src/Fabulous.Benchmarks/Benchmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,9 @@ module DiffingAttributes =

let rec viewInner depth counter =
Stack() {
Label($"label1:{counter} {depth}")
.textColor("red")
.automationId($"label1:{depth}")
Label($"label1:{counter} {depth}").textColor("red").automationId($"label1:{depth}")

Label($"label2:{counter} {depth}")
.textColor("green")
.automationId($"label2:{depth}")
Label($"label2:{counter} {depth}").textColor("green").automationId($"label2:{depth}")

Button($"btn: {depth}", IncBy 2)

Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.Benchmarks/Fabulous.Benchmarks.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
10 changes: 3 additions & 7 deletions src/Fabulous.Tests/APISketchTests/APISketchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ module SmallScalars =
| Inc value -> { value = model.value + value }

let view model =
InlineNumericBag(model.value, model.value + 1UL, float(model.value + 2UL))
.automationId("numbers")
InlineNumericBag(model.value, model.value + 1UL, float(model.value + 2UL)).automationId("numbers")

let init () = { value = 0UL }

Expand Down Expand Up @@ -898,12 +897,9 @@ module ViewHelpers =

let grandParentView _model =
Stack() {
Button("Grand Parent button", GrandParentClick)
.automationId("grandParentButton")
Button("Grand Parent button", GrandParentClick).automationId("grandParentButton")

(View.map ParentMessage parentView)
.automationId("parentStack")
.tapContainer(GrandParentTap)
(View.map ParentMessage parentView).automationId("parentStack").tapContainer(GrandParentTap)
}


Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.Tests/Fabulous.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous/Array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module Array =
let inline sortInPlace<'T, 'V when 'V: comparison> ([<InlineIfLambda>] getKey: 'T -> 'V) (attrs: 'T[]) : 'T[] =
let N = attrs.GetLength(0)

for i in [ 1 .. N - 1 ] do
for i in 1 .. N - 1 do
TimLariviere marked this conversation as resolved.
Show resolved Hide resolved
for j = i downto 1 do
let key = getKey attrs[j]
let prevKey = getKey attrs[j - 1]
Expand Down
9 changes: 3 additions & 6 deletions src/Fabulous/AttributeDefinitions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ module AttributeHelpers =
open ScalarAttributeDefinitions

let tryFindSimpleScalarAttribute (definition: SimpleScalarAttributeDefinition<'T>) (widget: Widget) =
match widget.ScalarAttributes with
| ValueNone -> ValueNone
| ValueSome attrs ->
match attrs |> Array.tryFind(fun attr -> attr.Key = definition.Key) with
| None -> ValueNone
| Some attr -> ValueSome(unbox<'T> attr.Value)
match widget.ScalarAttributes |> Array.tryFind(fun attr -> attr.Key = definition.Key) with
| None -> ValueNone
| Some attr -> ValueSome(unbox<'T> attr.Value)
70 changes: 41 additions & 29 deletions src/Fabulous/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Fabulous.StackAllocatedCollections
open Fabulous.StackAllocatedCollections.StackList
open Microsoft.FSharp.Core

type AttributesBundle = (struct (StackList<ScalarAttribute> * WidgetAttribute[] voption * WidgetCollectionAttribute[] voption * EnvironmentAttribute[] voption))
TimLariviere marked this conversation as resolved.
Show resolved Hide resolved
type AttributesBundle = (struct (StackList<ScalarAttribute> * WidgetAttribute[] * WidgetCollectionAttribute[] * EnvironmentAttribute[]))

[<Struct; NoComparison; NoEquality>]
type WidgetBuilder<'msg, 'marker when 'msg: equality> =
Expand All @@ -17,25 +17,25 @@ type WidgetBuilder<'msg, 'marker when 'msg: equality> =

new(key: WidgetKey) =
{ Key = key
Attributes = AttributesBundle(StackList.empty(), ValueNone, ValueNone, ValueNone) }
Attributes = AttributesBundle(StackList.empty(), [||], [||], [||]) }

new(key: WidgetKey, attributes: AttributesBundle) = { Key = key; Attributes = attributes }

new(key: WidgetKey, scalar: ScalarAttribute) =
{ Key = key
Attributes = AttributesBundle(StackList.one scalar, ValueNone, ValueNone, ValueNone) }
Attributes = AttributesBundle(StackList.one scalar, [||], [||], [||]) }

new(key: WidgetKey, scalarA: ScalarAttribute, scalarB: ScalarAttribute) =
{ Key = key
Attributes = AttributesBundle(StackList.two(scalarA, scalarB), ValueNone, ValueNone, ValueNone) }
Attributes = AttributesBundle(StackList.two(scalarA, scalarB), [||], [||], [||]) }

new(key: WidgetKey, scalar1: ScalarAttribute, scalar2: ScalarAttribute, scalar3: ScalarAttribute) =
{ Key = key
Attributes = AttributesBundle(StackList.three(scalar1, scalar2, scalar3), ValueNone, ValueNone, ValueNone) }
Attributes = AttributesBundle(StackList.three(scalar1, scalar2, scalar3), [||], [||], [||]) }

new(key: WidgetKey, widget: WidgetAttribute) =
{ Key = key
Attributes = AttributesBundle(StackList.empty(), ValueSome [| widget |], ValueNone, ValueNone) }
Attributes = AttributesBundle(StackList.empty(), [| widget |], [||], [||]) }

[<EditorBrowsable(EditorBrowsableState.Never)>]
member x.Compile() : Widget =
Expand All @@ -48,14 +48,26 @@ type WidgetBuilder<'msg, 'marker when 'msg: equality> =
#endif
ScalarAttributes =
match StackList.length &scalarAttributes with
| 0us -> ValueNone
| _ -> ValueSome(Array.sortInPlace _.Key (StackList.toArray &scalarAttributes))

WidgetAttributes = ValueOption.map (Array.sortInPlace(_.Key)) widgetAttributes

WidgetCollectionAttributes = widgetCollectionAttributes |> ValueOption.map(Array.sortInPlace(_.Key))

EnvironmentAttributes = environmentAttributes |> ValueOption.map(Array.sortInPlace(_.Key)) }
| 0us -> [||]
| _ -> Array.sortInPlace _.Key (StackList.toArray &scalarAttributes)

WidgetAttributes =
if widgetAttributes.Length > 1 then
Array.sortInPlace _.Key widgetAttributes
else
widgetAttributes

WidgetCollectionAttributes =
if widgetCollectionAttributes.Length > 1 then
Array.sortInPlace _.Key widgetCollectionAttributes
else
widgetCollectionAttributes

EnvironmentAttributes =
if environmentAttributes.Length > 1 then
Array.sortInPlace _.Key environmentAttributes
else
environmentAttributes }

[<EditorBrowsable(EditorBrowsableState.Never)>]
member inline x.AddScalar(attr: ScalarAttribute) =
Expand Down Expand Up @@ -103,14 +115,14 @@ type WidgetBuilder<'msg, 'marker when 'msg: equality> =

let res =
match attribs with
| ValueNone -> [| attr |]
| ValueSome attribs ->
| [||] -> [| attr |]
| attribs ->
let attribs2 = Array.zeroCreate(attribs.Length + 1)
Array.blit attribs 0 attribs2 0 attribs.Length
attribs2[attribs.Length] <- attr
attribs2

WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, ValueSome res, widgetCollectionAttributes, environmentAttributes))
WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, res, widgetCollectionAttributes, environmentAttributes))

[<EditorBrowsable(EditorBrowsableState.Never)>]
member x.AddWidgetCollection(attr: WidgetCollectionAttribute) =
Expand All @@ -121,14 +133,14 @@ type WidgetBuilder<'msg, 'marker when 'msg: equality> =

let res =
match attribs with
| ValueNone -> [| attr |]
| ValueSome attribs ->
| [||] -> [| attr |]
| attribs ->
let attribs2 = Array.zeroCreate(attribs.Length + 1)
Array.blit attribs 0 attribs2 0 attribs.Length
attribs2[attribs.Length] <- attr
attribs2

WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, widgetAttributes, ValueSome res, environmentAttributes))
WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, widgetAttributes, res, environmentAttributes))

[<EditorBrowsable(EditorBrowsableState.Never)>]
member inline x.AddEnvironment(key: EnvironmentAttributeKey, value: obj) =
Expand All @@ -146,14 +158,14 @@ type WidgetBuilder<'msg, 'marker when 'msg: equality> =

let res =
match attribs with
| ValueNone -> [| attr |]
| ValueSome attribs ->
| [||] -> [| attr |]
| attribs ->
let attribs2 = Array.zeroCreate(attribs.Length + 1)
Array.blit attribs 0 attribs2 0 attribs.Length
attribs2[attribs.Length] <- attr
attribs2

WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, widgetAttributes, widgetCollectionAttributes, ValueSome res))
WidgetBuilder<'msg, 'marker>(x.Key, struct (scalarAttributes, widgetAttributes, widgetCollectionAttributes, res))
end


Expand All @@ -170,12 +182,12 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker when 'msg: equality> =

new(widgetKey: WidgetKey, scalars: StackList<ScalarAttribute>, attr: WidgetCollectionAttributeDefinition) =
{ WidgetKey = widgetKey
Attributes = AttributesBundle(scalars, ValueNone, ValueNone, ValueNone)
Attributes = AttributesBundle(scalars, [||], [||], [||])
Attr = attr }

new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition) =
{ WidgetKey = widgetKey
Attributes = AttributesBundle(StackList.empty(), ValueNone, ValueNone, ValueNone)
Attributes = AttributesBundle(StackList.empty(), [||], [||], [||])
Attr = attr }

new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, attributes: AttributesBundle) =
Expand All @@ -185,12 +197,12 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker when 'msg: equality> =

new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalar: ScalarAttribute) =
{ WidgetKey = widgetKey
Attributes = AttributesBundle(StackList.one scalar, ValueNone, ValueNone, ValueNone)
Attributes = AttributesBundle(StackList.one scalar, [||], [||], [||])
Attr = attr }

new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalarA: ScalarAttribute, scalarB: ScalarAttribute) =
{ WidgetKey = widgetKey
Attributes = AttributesBundle(StackList.two(scalarA, scalarB), ValueNone, ValueNone, ValueNone)
Attributes = AttributesBundle(StackList.two(scalarA, scalarB), [||], [||], [||])
Attr = attr }

member inline x.Run(c: Content<'msg>) =
Expand All @@ -205,8 +217,8 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker when 'msg: equality> =

let widgetCollections =
match widgetCollections with
| ValueNone -> ValueSome([| widgetCollAttr |])
| ValueSome widgetCollectionAttributes -> ValueSome(Array.appendOne widgetCollAttr widgetCollectionAttributes)
| [||] -> [| widgetCollAttr |]
| widgetCollectionAttributes -> Array.appendOne widgetCollAttr widgetCollectionAttributes

WidgetBuilder<'msg, 'marker>(x.WidgetKey, AttributesBundle(scalars, widgets, widgetCollections, environments))

Expand Down
3 changes: 1 addition & 2 deletions src/Fabulous/Components/Binding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ type BindingExtensions =

let bindingValue = BindingValue<'T>(stateValue)

(continuation bindingValue)
.Invoke(envContext, treeContext, context, bindings + 1<binding>))
(continuation bindingValue).Invoke(envContext, treeContext, context, bindings + 1<binding>))
38 changes: 19 additions & 19 deletions src/Fabulous/Components/Component.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,40 @@ type Component
| ValueSome componentWidget ->
let componentScalars =
match componentWidget.ScalarAttributes with
| ValueNone -> ValueNone
| ValueSome attrs ->
| [||] -> [||]
| attrs ->
let filteredAttrs =
attrs |> Array.filter(fun scalarAttr -> scalarAttr.Key <> componentDataKey)

ValueSome(filteredAttrs) // skip the component data
filteredAttrs // skip the component data

let scalars =
match rootWidget.ScalarAttributes, componentScalars with
| ValueNone, ValueNone -> ValueNone
| ValueSome attrs, ValueNone
| ValueNone, ValueSome attrs -> ValueSome attrs
| ValueSome widgetAttrs, ValueSome componentAttrs -> ValueSome(Array.append componentAttrs widgetAttrs)
| [||], [||] -> [||]
| attrs, [||]
| [||], attrs -> attrs
| widgetAttrs, componentAttrs -> Array.append componentAttrs widgetAttrs

let widgets =
match rootWidget.WidgetAttributes, componentWidget.WidgetAttributes with
| ValueNone, ValueNone -> ValueNone
| ValueSome attrs, ValueNone
| ValueNone, ValueSome attrs -> ValueSome attrs
| ValueSome widgetAttrs, ValueSome componentAttrs -> ValueSome(Array.append componentAttrs widgetAttrs)
| [||], [||] -> [||]
| attrs, [||]
| [||], attrs -> attrs
| widgetAttrs, componentAttrs -> Array.append componentAttrs widgetAttrs

let widgetColls =
match rootWidget.WidgetCollectionAttributes, componentWidget.WidgetCollectionAttributes with
| ValueNone, ValueNone -> ValueNone
| ValueSome attrs, ValueNone
| ValueNone, ValueSome attrs -> ValueSome attrs
| ValueSome widgetAttrs, ValueSome componentAttrs -> ValueSome(Array.append componentAttrs widgetAttrs)
| [||], [||] -> [||]
| attrs, [||]
| [||], attrs -> attrs
| widgetAttrs, componentAttrs -> Array.append componentAttrs widgetAttrs

let environments =
match rootWidget.EnvironmentAttributes, componentWidget.EnvironmentAttributes with
| ValueNone, ValueNone -> ValueNone
| ValueSome attrs, ValueNone
| ValueNone, ValueSome attrs -> ValueSome attrs
| ValueSome widgetAttrs, ValueSome componentAttrs -> ValueSome(Array.append componentAttrs widgetAttrs)
| [||], [||] -> [||]
| attrs, [||]
| [||], attrs -> attrs
| widgetAttrs, componentAttrs -> Array.append componentAttrs widgetAttrs

struct (scalars, widgets, widgetColls, environments)

Expand Down
3 changes: 1 addition & 2 deletions src/Fabulous/Components/Mvu.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ type MvuExtensions =

treeContext, state

(continuation state)
.Invoke(envContext, treeContext, context, bindings + 1<binding>))
(continuation state).Invoke(envContext, treeContext, context, bindings + 1<binding>))
3 changes: 1 addition & 2 deletions src/Fabulous/Components/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ type StateExtensions =

let stateValue = StateValue<'T>(context, key, value)

(continuation stateValue)
.Invoke(envContext, treeContext, context, bindings + 1<binding>))
(continuation stateValue).Invoke(envContext, treeContext, context, bindings + 1<binding>))
Loading
Loading