-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMutationRecord.java
More file actions
65 lines (57 loc) · 1.83 KB
/
MutationRecord.java
File metadata and controls
65 lines (57 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package snap.webapi;
import java.util.stream.Stream;
/**
* This class is a wrapper for Web API MutationRecord (https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord).
*/
public class MutationRecord extends JSProxy {
/**
* Constructor.
*/
public MutationRecord(Object jsObj)
{
super(jsObj);
}
/**
* Returns a string representing the type of mutation.
*/
public String getType() { return getMemberString("type"); }
/**
* Returns the MutationObserver Option representing the type of mutation.
*/
public MutationObserver.Option getOption()
{
String type = getType();
return MutationObserver.Option.valueOf(type);
}
/**
* Returns the name of the changed attribute as a string, or null.
*/
public String getAttributeName()
{
return getMemberString("attributeName");
}
/**
* Returns the namespace of the changed attribute as a string, or null.
*/
public String getAttributeNamespace()
{
return getMemberString("attributeNamespace");
}
/**
* Returns the nodes added by a mutation. Will be an empty NodeList if no nodes were added.
*/
public Node[] getAddedNodes()
{
Object addedNodesJS = getMember("addedNodes");
return NodeList.getNodeArrayForNodeList(addedNodesJS);
}
/**
* Returns an array of nodes for given array of MutationRecords.
*/
public static MutationRecord[] getMutationRecordArrayForArrayJS(Object mutationRecordArrayJS)
{
Array<String> mutationRecordsArray = new Array<>(mutationRecordArrayJS);
Object[] mutationRecordsJS = mutationRecordsArray.toArray(Object.class);
return Stream.of(mutationRecordsJS).map(mutRec -> new MutationRecord(mutRec)).toArray(size -> new MutationRecord[size]);
}
}