AngleSharp by Florian Rappl

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

.NET API 1,189,376 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 Document _document; private bool _queued; public IEnumerable<MutationObserver> Observers => _observers; public MutationHost(Document document) { _observers = new List<MutationObserver>(); _queued = false; _document = document; } 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 = _document.Options.GetService<IEventService>(); if (!_queued && service != null) { _queued = true; service.Enqueue(new Task(DispatchCallback)); } } private void DispatchCallback() { MutationObserver[] array = _observers.ToArray(); IEventService service = _document.Options.GetService<IEventService>(); _queued = false; if (service != null) { MutationObserver[] array2 = array; foreach (MutationObserver object in array2) { service.Execute(object.Trigger); } } } } }