本文整理汇总了C#中AngleSharp.Dom.MutationObserver.TriggerWith方法的典型用法代码示例。如果您正苦于以下问题:C# MutationObserver.TriggerWith方法的具体用法?C# MutationObserver.TriggerWith怎么用?C# MutationObserver.TriggerWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AngleSharp.Dom.MutationObserver
的用法示例。
在下文中一共展示了MutationObserver.TriggerWith方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectMutationObserverAttributesTriggerManually
public void ConnectMutationObserverAttributesTriggerManually()
{
var called = false;
var attrName = "something";
var attrValue = "test";
var observer = new MutationObserver((mut, obs) =>
{
called = true;
Assert.AreEqual(1, mut.Length);
Assert.AreEqual(attrName, mut[0].AttributeName);
Assert.IsNull(mut[0].PreviousValue);
});
var document = Html("");
observer.Connect(document.Body, new MutationObserverInit
{
IsObservingAttributes = true
});
document.Body.SetAttribute(attrName, attrValue);
observer.TriggerWith(observer.Flush().ToArray());
Assert.IsTrue(called);
}
示例2: ConnectMutationObserverChildNodesTriggerManually
public void ConnectMutationObserverChildNodesTriggerManually()
{
var called = false;
var observer = new MutationObserver((mut, obs) =>
{
called = true;
Assert.AreEqual(1, mut.Length);
var record = mut[0];
Assert.IsNotNull(record.Added);
Assert.AreEqual(1, record.Added.Length);
});
var document = Html("");
observer.Connect(document.Body, childList: true);
document.Body.AppendChild(document.CreateElement("span"));
observer.TriggerWith(observer.Flush().ToArray());
Assert.IsTrue(called);
}
示例3: ConnectMutationObserverMultipleAttributesDescendentTriggerManually
public void ConnectMutationObserverMultipleAttributesDescendentTriggerManually()
{
var called1 = false;
var called2 = false;
var called3 = false;
var attrName = "something";
var attrValue = "test";
var document = Html("");
var observer1 = new MutationObserver((mut, obs) =>
{
called1 = true;
Assert.AreEqual(1, mut.Length);
});
observer1.Connect(document.DocumentElement, new MutationObserverInit
{
IsObservingAttributes = true,
IsObservingSubtree = true
});
var observer2 = new MutationObserver((mut, obs) =>
{
called2 = true;
Assert.AreEqual(0, mut.Length);
});
observer2.Connect(document.DocumentElement, new MutationObserverInit
{
IsObservingAttributes = true,
IsObservingSubtree = false
});
var observer3 = new MutationObserver((mut, obs) =>
{
called3 = true;
Assert.AreEqual(1, mut.Length);
});
observer3.Connect(document.Body, new MutationObserverInit
{
IsObservingAttributes = true
});
document.Body.SetAttribute(attrName, attrValue);
observer1.TriggerWith(observer1.Flush().ToArray());
observer2.TriggerWith(observer2.Flush().ToArray());
observer3.TriggerWith(observer3.Flush().ToArray());
Assert.IsTrue(called1);
Assert.IsTrue(called2);
Assert.IsTrue(called3);
}
示例4: ConnectMutationObserverTextNoDescendentsButCreatedTriggerManually
public void ConnectMutationObserverTextNoDescendentsButCreatedTriggerManually()
{
var called = false;
var text = "something";
var observer = new MutationObserver((mut, obs) =>
{
called = true;
Assert.AreEqual(1, mut.Length);
Assert.AreEqual(1, mut[0].Added.Length);
Assert.AreEqual(text, mut[0].Added[0].TextContent);
});
var document = Html("");
observer.Connect(document.Body, new MutationObserverInit
{
IsObservingSubtree = false,
IsObservingChildNodes = true
});
document.Body.TextContent = text;
observer.TriggerWith(observer.Flush().ToArray());
Assert.IsTrue(called);
}
示例5: ConnectMutationObserverTextNoDescendentsTriggerManually
public void ConnectMutationObserverTextNoDescendentsTriggerManually()
{
var called = false;
var text = "something";
var replaced = "different";
var observer = new MutationObserver((mut, obs) =>
{
called = true;
Assert.AreEqual(0, mut.Length);
});
var document = Html("");
observer.Connect(document.Body, new MutationObserverInit
{
IsObservingCharacterData = true,
IsObservingSubtree = false
});
document.Body.TextContent = text;
var textNode = document.Body.ChildNodes[0] as TextNode;
textNode.Replace(text.Length, 0, replaced);
observer.TriggerWith(observer.Flush().ToArray());
Assert.IsTrue(called);
}
示例6: ConnectMutationObserverTextWithDescendentsAndExaminingOldValueTriggerManually
public void ConnectMutationObserverTextWithDescendentsAndExaminingOldValueTriggerManually()
{
var called = false;
var text = "something";
var replaced = "different";
var observer = new MutationObserver((mut, obs) =>
{
called = true;
Assert.AreEqual(1, mut.Length);
Assert.AreEqual(text, mut[0].PreviousValue);
var tn = mut[0].Target as TextNode;
Assert.IsNotNull(tn);
Assert.AreEqual(text + replaced, tn.TextContent);
});
var document = Html("");
observer.Connect(document.Body, new MutationObserverInit
{
IsObservingCharacterData = true,
IsObservingSubtree = true,
IsExaminingOldCharacterData = true
});
document.Body.TextContent = text;
var textNode = document.Body.ChildNodes[0] as TextNode;
textNode.Replace(text.Length, 0, replaced);
observer.TriggerWith(observer.Flush().ToArray());
Assert.IsTrue(called);
}