Skip to content

[BUG] DelayChangeNotifications does not delay PropertyChanged events #2382

@WalkerCodeRanger

Description

@WalkerCodeRanger

Describe the bug
The ReactiveObject.DelayChangeNotifications() method does not delay the firing of PropertyChanged events. (Please note ReactiveObject.SuppressChangeNotifications() does suppress them.)

Steps To Reproduce
The following C# console app demonstrates the bug. All assertions are expected to pass, but 2 of 3 fail.

using System.Diagnostics;
using ReactiveUI;

class Example : ReactiveObject
{
    private int _value;

    public int Value
    {
        get => _value;
        set => this.RaiseAndSetIfChanged(ref _value, value);
    }
}

class Program
{
    static void Main(string[] args)
    {
        var obj = new Example();
        var changeEvents = 0;
        obj.PropertyChanged += (s, e) => changeEvents++;
        using (obj.DelayChangeNotifications())
        {
            obj.Value = 1;
            obj.Value = 2;
            Debug.Assert(changeEvents == 0, "Property change raised during delay");
        }
        Debug.Assert(changeEvents < 2, "Property change not deduped");
        Debug.Assert(changeEvents != 0, "Property change not raised");
    }
}

Expected behavior
Similar to how ReactiveObject.SuppressChangeNotifications() affects property changed events and ReactiveObject.DelayChangeNotifications() delays and removes duplicate change events from the ReactiveObject.Changed observable. I expect:

  1. No property changing and changed events will be raised between the call of ReactiveObject.SuppressChangeNotifications() and the disposing of the returned IDisposable.
  2. When the IDisposable is disposed of, any delayed changing and changed events will be raised
  3. Changing and changed events that are delayed will be deduplicated so that if a property is changed more than once during the delayed time, only one property change event will be raised for it.

Environment

  • OS: Windows Pro
  • Version 10.0.18363
  • Device: Dell Vostro 7590
  • ReactiveUI: v11.3.1
  • .NET Framework: v4.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions