Skip to content

Commit

Permalink
Move attributes to dedicated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Nov 14, 2024
1 parent 8ecc4d6 commit e78dcd5
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 112 deletions.
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.15",
"version": "6.3.16",
"commands": [
"fantomas"
],
Expand Down
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-pre10] - 2024-11-14

### Changed
- Moved attribute definition functions specific to Mvu/Component into dedicated modules by @TimLariviere

## [3.0.0-pre9] - 2024-11-08

### Fixed
Expand Down Expand Up @@ -162,7 +167,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-pre9...HEAD
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre10...HEAD
[3.0.0-pre10]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre10
[3.0.0-pre9]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre9
[3.0.0-pre8]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre8
[3.0.0-pre7]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre7
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.2" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

Expand Down
26 changes: 14 additions & 12 deletions Fabulous.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand All @@ -11,17 +11,19 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fabulous.Benchmarks", "src\
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fabulous.Tests", "src\Fabulous.Tests\Fabulous.Tests.fsproj", "{31A18443-E05B-47F1-812E-4FEECCCA06DB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Files", "_Solution Files", "{20E44B0C-FA62-4DE4-8017-95AAE3B178CE}"
ProjectSection(SolutionItems) = preProject
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
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Files", "_Solution Files", "{20E44B0C-FA62-4DE4-8017-95AAE3B178CE}"
ProjectSection(SolutionItems) = preProject
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
Directory.Packages.props = Directory.Packages.props
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
1 change: 0 additions & 1 deletion src/Fabulous.Tests/Fabulous.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<Compile Include="CmdTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="FsCheck.NUnit" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
Expand Down
191 changes: 95 additions & 96 deletions src/Fabulous/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -280,99 +280,98 @@ module Attributes =

{ Key = key; Name = name }

/// Define an attribute for EventHandler
let inline defineEventNoArg name ([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler, EventArgs>) : SimpleScalarAttributeDefinition<MsgValue> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: MsgValue voption) node ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome(MsgValue msg) ->
let event = getEvent node.Target
let handler = event.Subscribe(fun _ -> Dispatcher.dispatch node msg)
node.SetHandler(name, handler))
)

|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

/// Define an attribute for EventHandler<'T>
let inline defineEvent<'args>
name
([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler<'args>, 'args>)
: SimpleScalarAttributeDefinition<'args -> MsgValue> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: ('args -> MsgValue) voption) (node: IViewNode) ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome fn ->
let event = getEvent node.Target

let handler =
event.Subscribe(fun args ->
let (MsgValue r) = fn args
Dispatcher.dispatch node r)

node.SetHandler(name, handler))
)
|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

let inline defineEventNoArgNoDispatch
name
([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler, EventArgs>)
: SimpleScalarAttributeDefinition<unit -> unit> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: (unit -> unit) voption) node ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome(fn) ->
let event = getEvent node.Target
node.SetHandler(name, event.Subscribe(fun _ -> fn())))
)

|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

let inline defineEventNoDispatch<'args>
name
([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler<'args>, 'args>)
: SimpleScalarAttributeDefinition<'args -> unit> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: ('args -> unit) voption) node ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome(fn) ->
let event = getEvent node.Target
node.SetHandler(name, event.Subscribe(fun args -> fn args)))
)

|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }
module Mvu =
/// Define an attribute for EventHandler
let inline defineEventNoArg name ([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler, EventArgs>) : SimpleScalarAttributeDefinition<MsgValue> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: MsgValue voption) node ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome(MsgValue msg) ->
let event = getEvent node.Target
let handler = event.Subscribe(fun _ -> Dispatcher.dispatch node msg)
node.SetHandler(name, handler))
)

|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

/// Define an attribute for EventHandler<'T>
let inline defineEvent<'args>
name
([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler<'args>, 'args>)
: SimpleScalarAttributeDefinition<'args -> MsgValue> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: ('args -> MsgValue) voption) (node: IViewNode) ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome fn ->
let event = getEvent node.Target

let handler =
event.Subscribe(fun args ->
let (MsgValue r) = fn args
Dispatcher.dispatch node r)

node.SetHandler(name, handler))
)
|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

module Component =
let inline defineEventNoArg name ([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler, EventArgs>) : SimpleScalarAttributeDefinition<unit -> unit> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: (unit -> unit) voption) node ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome(fn) ->
let event = getEvent node.Target
node.SetHandler(name, event.Subscribe(fun _ -> fn())))
)

|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

let inline defineEvent<'args>
name
([<InlineIfLambda>] getEvent: obj -> IEvent<EventHandler<'args>, 'args>)
: SimpleScalarAttributeDefinition<'args -> unit> =
let key =
SimpleScalarAttributeDefinition.CreateAttributeData(
ScalarAttributeComparers.noCompare,
(fun _ (newValueOpt: ('args -> unit) voption) node ->
match node.TryGetHandler(name) with
| ValueNone -> ()
| ValueSome handler -> handler.Dispose()

match newValueOpt with
| ValueNone -> node.RemoveHandler(name)
| ValueSome(fn) ->
let event = getEvent node.Target
node.SetHandler(name, event.Subscribe(fun args -> fn args)))
)

|> AttributeDefinitionStore.registerScalar

{ Key = key; Name = name }

0 comments on commit e78dcd5

Please sign in to comment.