ReactiveUI icon indicating copy to clipboard operation
ReactiveUI copied to clipboard

[BUG] WhenAnyValue does not fire event after SuppressChangeNotifications section when the value before this section.

Open Ruslan-B opened this issue 8 years ago • 0 comments

Do you want to request a feature or report a bug? It is a bug.

What is the current behavior? WhenAnyValue does not fire event after property was changed in SuppressChangeNotifications section and set to the same value (before SuppressChangeNotifications).

What is the expected behavior? The event thrown.

What is the motivation / use case for changing the behavior? In case viewmodel where prepared before it is shown as for example previous state was restored. If the user picks previous value the viewmodel does not execute the logic connect with this change.

Which versions of ReactiveUI, and which platform / OS are affected by this issue? Did this work in previous versions of ReativeUI? Please also test with the latest stable and snapshot (http://docs.reactiveui.net/en/contributing/snapshot/index.html) versions. ReactiveUI 7.4.0 from nuget.

Other information (e.g. stacktraces, related issues, suggestions how to fix) It looks like internal DistinctUntilChanged filters out the same value.

Minimal demo:

    class Program
    {
        static void Main(string[] args)
        {
            var vm = new TestViewModel();
            vm.PropertyChanged += (s, e) => Console.WriteLine($@"property change: {vm.Value}");
            vm.WhenAnyValue(x => x.Value).Subscribe(v => Console.WriteLine($@"observing: {v}"));
             vm.Value = 1;
            vm.Value = 2;
            Console.WriteLine(@"suppress change begin");
            using (vm.SuppressChangeNotifications())
            { 
                vm.Value = 3;
            }
            Console.WriteLine(@"suppress change end");
            vm.Value = 2;
            vm.Value = 3;
        }

        public class TestViewModel : ReactiveObject
        {
            private int m_value;

            public int Value
            {
                get { return m_value; }
                set
                {
                    Console.WriteLine($@"set to: {value}");
                    this.RaiseAndSetIfChanged(ref m_value, value);
                }
            }
        }
    }

Current behavior:

observing: 0
set to: 1
property change: 1
observing: 1
set to: 2
property change: 2
observing: 2
//suppress change begin
set to: 3
//suppress change end
set to: 2
property change: 2
// there is no observation from vm.WhenAnyValue(x => x.Value)
set to: 3
property change: 3
observing: 3

Expected behavior;

observing: 0
set to: 1
property change: 1
observing: 1
set to: 2
property change: 2
observing: 2
//suppress change begin
set to: 3
//suppress change end
set to: 2
property change: 2
observing: 2
set to: 3
property change: 3
observing: 3

Ruslan-B avatar Jun 01 '17 08:06 Ruslan-B