Skip to content

Commit

Permalink
Fix transform on filter exception. (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandPheasant authored Nov 25, 2022
1 parent 59b3cac commit b44fdee
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 21 deletions.
36 changes: 23 additions & 13 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ jobs:
runs-on: windows-2022
outputs:
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
steps:
steps:
- name: Get Current Visual Studio Information
shell: bash
run: |
dotnet tool update -g dotnet-vs
echo "## About RELEASE ##"
vs where release
- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -33,12 +40,11 @@ jobs:
$process.StartInfo = $startInfo
$process.Start()
$process.WaitForExit()
- name: Install .NET 6
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
include-prerelease: true

- name: NBGV
id: nbgv
Expand All @@ -58,17 +64,21 @@ jobs:
- name: Build
run: msbuild /t:build,pack /maxcpucount /p:NoPackageAnalysis=true /verbosity:minimal /p:Configuration=${{ env.configuration }}
working-directory: src


#- name: Run Unit Tests and Generate Coverage
# uses: glennawatson/coverlet-msbuild@v1
# with:
# project-files: '**/*Tests*.csproj'
# no-build: true
# exclude-filter: '[${{env.productNamespacePrefix}}.*.Tests.*]*'
# include-filter: '[${{env.productNamespacePrefix}}*]*'
# output-format: cobertura
# output: '../../artifacts/'
# configuration: ${{ env.configuration }}

- name: Run Unit Tests and Generate Coverage
uses: glennawatson/coverlet-msbuild@v1
with:
project-files: '**/*Tests*.csproj'
no-build: true
exclude-filter: '[${{env.productNamespacePrefix}}.*.Tests.*]*'
include-filter: '[${{env.productNamespacePrefix}}*]*'
output-format: cobertura
output: '../../artifacts/'
configuration: ${{ env.configuration }}
run: dotnet test /p:CollectCoverage=true --no-build /p:Exclude=DynamicData.Tests /p:Include=DynamicData.* --configuration Release /p:CoverletOutput=..\..\artifacts\DynamicData.Tests.xml /p:CoverletOutputFormat=cobertura
working-directory: src

- name: Upload Code Coverage
shell: bash
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ jobs:
outputs:
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
steps:
- name: Get Current Visual Studio Information
shell: bash
run: |
dotnet tool update -g dotnet-vs
echo "## About RELEASE ##"
vs where release
- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -32,12 +39,11 @@ jobs:
$process.StartInfo = $startInfo
$process.Start()
$process.WaitForExit()
- name: Install .NET 6
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
include-prerelease: true

- name: NBGV
id: nbgv
Expand Down
21 changes: 21 additions & 0 deletions src/DynamicData.Tests/AutoRefreshFilter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DynamicData.Binding;
Expand All @@ -12,6 +13,26 @@ namespace DynamicData.Tests;

public class AutoRefreshFilter
{
[Fact]
public void Bind_Transform_and_FilterOnObservable()
{
var count = 3;
var list = new SourceList<string>();
list.AddRange(Enumerable.Range(1, count).Select(c => $"item {c}"));

var bindedList = new ObservableCollectionExtended<string>();

list.Connect()
.FilterOnObservable(_ => Observable.Return(true))
.Transform(str => str)
.Bind(bindedList)
.Subscribe(
_ => { },
ex => {Assert.Fail("There should be no error");}
);
}


[Fact]
public void Test()
{
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicData.Tests/DynamicData.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.console" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
Expand Down
11 changes: 7 additions & 4 deletions src/DynamicData/List/Internal/FilterOnObservable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,25 @@ public IObservable<IChangeSet<TObject>> Run()
.Publish();

// monitor each item observable and create change, carry the value of the observable property
IObservable<ObjWithFilterValue> itemHasChanged = shared.MergeMany(v => _filter(v.Obj).Select(prop => new ObjWithFilterValue(v.Obj, prop)));
var itemHasChanged = shared.MergeMany(v => _filter(v.Obj).Select(prop => new ObjWithFilterValue(v.Obj, prop)));

// create a change set, either buffered or one item at the time
IObservable<IEnumerable<ObjWithFilterValue>> itemsChanged = _buffer is null ?
var itemsChanged = _buffer is null ?
itemHasChanged.Select(t => new[] { t }) :
itemHasChanged.Buffer(_buffer.Value, _scheduler ?? Scheduler.Default).Where(list => list.Count > 0);

IObservable<IChangeSet<ObjWithFilterValue>> requiresRefresh = itemsChanged.Synchronize(locker).Select(
var requiresRefresh = itemsChanged.Synchronize(locker).Select(
items =>
{
// catch all the indices of items which have been refreshed
return IndexOfMany(allItems, items, v => v.Obj, (t, idx) => new Change<ObjWithFilterValue>(ListChangeReason.Refresh, t, idx));
}).Select(changes => new ChangeSet<ObjWithFilterValue>(changes));

// publish refreshes and underlying changes
var publisher = shared.Merge(requiresRefresh).Filter(v => v.Filter).Transform(v => v.Obj).SuppressRefresh() // suppress refreshes from filter, avoids excessive refresh messages for no-op filter updates
var publisher = shared.Merge(requiresRefresh).Filter(v => v.Filter)
.Transform(v => v.Obj)
.SuppressRefresh() // suppress refreshes from filter, avoids excessive refresh messages for no-op filter updates
.NotEmpty()
.SubscribeSafe(observer);

return new CompositeDisposable(publisher, shared.Connect());
Expand Down
11 changes: 10 additions & 1 deletion src/DynamicData/List/ObservableListEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,16 @@ public static IObservable<IChangeSet<T>> SubscribeMany<T>(this IObservable<IChan
/// <returns>An observable which emits the change set.</returns>
public static IObservable<IChangeSet<T>> SuppressRefresh<T>(this IObservable<IChangeSet<T>> source)
{
return source.WhereReasonsAreNot(ListChangeReason.Refresh);
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

return source.Select(changes =>
{
var filtered = changes.Where(c => c.Reason != ListChangeReason.Refresh);
return new ChangeSet<T>(filtered);
});
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/global.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"sdk": {
"version": "6.0",
"rollForward": "latestMinor",
"allowPrerelease": true
},
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "3.0.44"
}
Expand Down

0 comments on commit b44fdee

Please sign in to comment.