diff --git a/rd-net/Lifetimes/Collections/Viewable/ReactiveEx.cs b/rd-net/Lifetimes/Collections/Viewable/ReactiveEx.cs index 8cf209c4c..2f7843432 100644 --- a/rd-net/Lifetimes/Collections/Viewable/ReactiveEx.cs +++ b/rd-net/Lifetimes/Collections/Viewable/ReactiveEx.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using JetBrains.Core; using JetBrains.Lifetimes; @@ -378,7 +377,7 @@ public MappedProperty(IViewableProperty source, Func map) Change = new MappedSink(source.Change, myMap); } - public void Advise(Lifetime lifetime, Action handler) => Change.Advise(lifetime, handler); + public void Advise(Lifetime lifetime, Action handler) => mySource.Advise(lifetime, v => handler(myMap(v))); public ISource Change { get; } @@ -430,4 +429,4 @@ public static Task NextValueAsync(this ISource source, Lifetime lifetim } #endif } -} \ No newline at end of file +} diff --git a/rd-net/Test.Lifetimes/Collections/Viewable/ViewablePropertyTest.cs b/rd-net/Test.Lifetimes/Collections/Viewable/ViewablePropertyTest.cs new file mode 100644 index 000000000..b3479d29b --- /dev/null +++ b/rd-net/Test.Lifetimes/Collections/Viewable/ViewablePropertyTest.cs @@ -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(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); + }); + } +}