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

Feature/adaptiview bind collections #62

Merged
merged 2 commits into from
Jun 5, 2024
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
46 changes: 31 additions & 15 deletions Fun.Blazor.Tests/AdaptiveTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ let ``html adaptive tests`` () =
let store1 = cval 1
let store2 = cval 1

let comp =
adaptiview () {
let! s1 = store1
let! s2 = store2
html.text $"s1={s1};s2={s2}"
}
let comp = adaptiview () {
let! s1 = store1
let! s2 = store2
html.text $"s1={s1};s2={s2}"
}

let result = context.RenderNode comp

Expand All @@ -49,22 +48,39 @@ let ``html adaptive tests`` () =
result.MarkupMatches("s1=8;s2=9")


[<Fact>]
let ``html adaptive bind collections tests`` () =
let context = createTestContext ()

let comp = adaptiview () {
let! s1 = AList.ofList [ 4; 3 ]
let! s2 = ASet.ofList [ 2; 1 ]
for x in s1 do
html.text x
for x in Seq.sort s2 do
html.text x
}

let result = context.RenderNode comp

result.MarkupMatches("4312")


[<Fact>]
let ``html adaptive complex condition tests`` () =
let context = createTestContext ()

let store1 = cval 1
let store2 = cval 1

let comp =
adaptiview () {
let! s1 = store1
let! s2 = store2
region { if s1 >= 2 then div { $"s1={s1}" } }
if s2 >= 2 then div { $"s2={s2}" }
for i in 3..4 do
div { i }
}
let comp = adaptiview () {
let! s1 = store1
let! s2 = store2
region { if s1 >= 2 then div { $"s1={s1}" } }
if s2 >= 2 then div { $"s2={s2}" }
for i in 3..4 do
div { i }
}

let result = context.RenderNode comp

Expand Down
5 changes: 5 additions & 0 deletions Fun.Blazor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

## [4.0.12] - 2024-06-05

- Update packages
- Support bind alist, aset in adaptiview

## [4.0.11] - 2024-04-06

- Expose KeyValues for i18n
Expand Down
4 changes: 4 additions & 0 deletions Fun.Blazor/DslAdaptiview.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ type AdaptiviewBuilder
state <- AVal.map2 (fun x y -> x >=> y) state (fn item)
state

member inline _.Bind(value: alist<_>, fn: _ -> aval<_>) : aval<_> = AList.toAVal value |> AVal.bind fn

member inline _.Bind(value: aset<_>, fn: _ -> aval<_>) : aval<_> = ASet.toAVal value |> AVal.bind fn


type IAdaptiveValue<'T> with

Expand Down
6 changes: 3 additions & 3 deletions Fun.Blazor/Fun.Blazor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.0" />
<PackageReference Include="FSharp.Data.Adaptive" Version="1.2.14" />
<PackageReference Include="Fun.Css" Version="0.3.*" />
<PackageReference Include="Fun.Result" Version="2.0.9" />
<PackageReference Include="FSharp.Data.Adaptive" Version="1.2.15" />
<PackageReference Include="Fun.Css" Version="1.0.0" />
<PackageReference Include="Fun.Result" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.*" />
</ItemGroup>

Expand Down
Loading