Skip to content

Commit

Permalink
(#357) MappedProperty: should produce the current value on Advise
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jul 1, 2023
1 parent 31e18a0 commit cf48796
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 2 additions & 3 deletions rd-net/Lifetimes/Collections/Viewable/ReactiveEx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using JetBrains.Core;
using JetBrains.Lifetimes;
Expand Down Expand Up @@ -375,7 +374,7 @@ public MappedProperty(IViewableProperty<T> source, Func<T, R> map)
{
mySource = source;
myMap = map;
Change = new MappedSink<T, R>(source.Change, myMap);
Change = new MappedSink<T, R>(source, myMap);
}

public void Advise(Lifetime lifetime, Action<R> handler) => Change.Advise(lifetime, handler);
Expand Down Expand Up @@ -430,4 +429,4 @@ public static Task<T> NextValueAsync<T>(this ISource<T> source, Lifetime lifetim
}
#endif
}
}
}
30 changes: 30 additions & 0 deletions rd-net/Test.Lifetimes/Collections/Viewable/ViewablePropertyTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using JetBrains.Collections.Viewable;
using JetBrains.Lifetimes;
using NUnit.Framework;

namespace Test.Lifetimes.Collections.Viewable;

public class ViewablePropertyTest
{
[TestCase]
public void TestAdvise()
{
var prop = new ViewableProperty<int>(123);
Lifetime.Using(lt =>
{
int? value = null;
prop.Advise(lt, x => value = x);
Assert.AreEqual(123, value);
});
Lifetime.Using(lt =>
{
int? value = null;
var mapped = prop.Select(x => x + 1);
mapped.Advise(lt, x => value = x);
Assert.AreEqual(124, value);
prop.Value = 125;
Assert.AreEqual(126, value);
});
}
}

0 comments on commit cf48796

Please sign in to comment.