diff --git a/src/R3/ReactiveProperty.cs b/src/R3/ReactiveProperty.cs index d6225535..60194be0 100644 --- a/src/R3/ReactiveProperty.cs +++ b/src/R3/ReactiveProperty.cs @@ -111,9 +111,11 @@ void OnNextCore(T value) if (completeState.IsCompleted) return; var node = Volatile.Read(ref root); + var last = node?.Previous; while (node != null) { node.Observer.OnNext(value); + if (node == last) return; node = node.Next; } } @@ -125,9 +127,11 @@ public void OnErrorResume(Exception error) OnReceiveError(error); var node = Volatile.Read(ref root); + var last = node?.Previous; while (node != null) { node.Observer.OnErrorResume(error); + if (node == last) return; node = node.Next; } } @@ -146,9 +150,11 @@ public void OnCompleted(Result result) } var node = Volatile.Read(ref root); + var last = node?.Previous; while (node != null) { node.Observer.OnCompleted(result); + if (node == last) return; node = node.Next; } } diff --git a/tests/R3.Tests/ReactivePropertyTest.cs b/tests/R3.Tests/ReactivePropertyTest.cs index b857b0d9..d1c00659 100644 --- a/tests/R3.Tests/ReactivePropertyTest.cs +++ b/tests/R3.Tests/ReactivePropertyTest.cs @@ -1,4 +1,5 @@ using R3.Collections; +using System.Collections.Generic; namespace R3.Tests; @@ -232,4 +233,28 @@ public void NodeDisposeCheck() list5.AssertEqual([1, 10, 20]); } } + + [Fact] + public void RecursiveSubscribe() + { + var rp = new ReactiveProperty(0); + + List> recList = new(); + + var list = rp.Do(x => + { + recList.Add(rp.ToLiveList()); + }) + .ToLiveList(); + + list.AssertEqual([0]); + recList[0].AssertEqual([0]); + + rp.Value = 99; + list.AssertEqual([0, 99]); + recList[0].AssertEqual([0, 99]); + recList[1].AssertEqual([99]); + + + } }