AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.8.8" />

.NET API 1,176,064 bytes

 MutationHost

sealed class MutationHost
Couples the mutation events to mutation observers and the event loop.
using AngleSharp.Extensions; using AngleSharp.Services; using System.Collections.Generic; using System.Threading.Tasks; namespace AngleSharp.Dom { internal sealed class MutationHost { private readonly List<MutationObserver> _observers; private readonly IConfiguration _configuration; private bool _queued; public IEnumerable<MutationObserver> Observers => _observers; public MutationHost(IConfiguration configuration) { _observers = new List<MutationObserver>(); _queued = false; _configuration = configuration; } public void Register(MutationObserver observer) { if (!_observers.Contains(observer)) _observers.Add(observer); } public void Unregister(MutationObserver observer) { if (_observers.Contains(observer)) _observers.Remove(observer); } public void ScheduleCallback() { IEventService service = _configuration.GetService<IEventService>(); if (!_queued && service != null) { _queued = true; service.Enqueue(new Task(DispatchCallback)); } } private void DispatchCallback() { MutationObserver[] array = _observers.ToArray(); IEventService service = _configuration.GetService<IEventService>(); _queued = false; if (service != null) { MutationObserver[] array2 = array; foreach (MutationObserver object in array2) { service.Execute(object.Trigger); } } } } }