MutationRecord
Represents a recording of DOM changes.
using AngleSharp.Extensions;
namespace AngleSharp.Dom
{
internal sealed class MutationRecord : IMutationRecord
{
private static readonly string CharacterDataType = "characterData";
private static readonly string AttributesType = "attributes";
private static readonly string ChildListType = "childList";
public bool IsAttribute => Type.Is(AttributesType);
public bool IsCharacterData => Type.Is(CharacterDataType);
public bool IsChildList => Type.Is(ChildListType);
public string Type { get; set; }
public INode Target { get; set; }
public INodeList Added { get; set; }
public INodeList Removed { get; set; }
public INode PreviousSibling { get; set; }
public INode NextSibling { get; set; }
public string AttributeName { get; set; }
public string AttributeNamespace { get; set; }
public string PreviousValue { get; set; }
private MutationRecord()
{
}
public static MutationRecord CharacterData(INode target, string previousValue = null)
{
return new MutationRecord {
Type = CharacterDataType,
Target = target,
PreviousValue = previousValue
};
}
public static MutationRecord ChildList(INode target, INodeList addedNodes = null, INodeList removedNodes = null, INode previousSibling = null, INode nextSibling = null)
{
return new MutationRecord {
Type = ChildListType,
Target = target,
Added = addedNodes,
Removed = removedNodes,
PreviousSibling = previousSibling,
NextSibling = nextSibling
};
}
public static MutationRecord Attributes(INode target, string attributeName = null, string attributeNamespace = null, string previousValue = null)
{
return new MutationRecord {
Type = AttributesType,
Target = target,
AttributeName = attributeName,
AttributeNamespace = attributeNamespace,
PreviousValue = previousValue
};
}
public MutationRecord Copy(bool clearPreviousValue)
{
return new MutationRecord {
Type = Type,
Target = Target,
PreviousSibling = PreviousSibling,
NextSibling = NextSibling,
AttributeName = AttributeName,
AttributeNamespace = AttributeNamespace,
PreviousValue = (clearPreviousValue ? null : PreviousValue),
Added = Added,
Removed = Removed
};
}
}
}