Skip to content

MutationObserver

Types

mutationObserverCallback

type mutationObserverCallback = (
array<mutationRecord>,
t,
) => unit

mutationObserverInit

type mutationObserverInit = {
mutable childList?: bool,
mutable attributes?: bool,
mutable characterData?: bool,
mutable subtree?: bool,
mutable attributeOldValue?: bool,
mutable characterDataOldValue?: bool,
mutable attributeFilter?: array<string>,
}

Record fields

childList
option<bool>
attributes
option<bool>
characterData
option<bool>
subtree
option<bool>
attributeOldValue
option<bool>
characterDataOldValue
option<bool>
attributeFilter
option<array<string>>

mutationRecord

Represents an individual DOM mutation. See MutationRecord on MDN

type mutationRecord = {
type_: string,
target: WebAPI.DOMTree.node,
addedNodes: WebAPI.DOM.nodeList<WebAPI.DOMTree.node>,
removedNodes: WebAPI.DOM.nodeList<WebAPI.DOMTree.node>,
previousSibling: Null.t<WebAPI.DOMTree.node>,
nextSibling: Null.t<WebAPI.DOMTree.node>,
attributeName: Null.t<string>,
attributeNamespace: Null.t<string>,
oldValue: Null.t<string>,
}

Record fields

type_
string

Returns "attributes" if it was an attribute mutation. "characterData" if it was a mutation to a CharacterData node. And "childList" if it was a mutation to the tree of nodes. Read more on MDN

target

Returns the node the mutation affected, depending on the type. For "attributes", it is the element whose attribute changed. For "characterData", it is the CharacterData node. For "childList", it is the node whose children changed. Read more on MDN

addedNodes

Return the nodes added and removed respectively. Read more on MDN

removedNodes

Return the nodes added and removed respectively. Read more on MDN

previousSibling

Return the previous and next sibling respectively of the added or removed nodes, and null otherwise. Read more on MDN

nextSibling

Return the previous and next sibling respectively of the added or removed nodes, and null otherwise. Read more on MDN

attributeName
Null.t<string>

Returns the local name of the changed attribute, and null otherwise. Read more on MDN

attributeNamespace
Null.t<string>

Returns the namespace of the changed attribute, and null otherwise. Read more on MDN

oldValue
Null.t<string>

The return value depends on type. For "attributes", it is the value of the changed attribute before the change. For "characterData", it is the data of the changed node before the change. For "childList", it is null. Read more on MDN

Values

disconnect

let disconnect: t => unit

Parameters

t

Return type

unit

make

let make: mutationObserverCallback => t

Parameters

mutationObserverCallback

Return type

t

observe

let observe: (
t,
~target: WebAPI.DOMTree.node,
~options: mutationObserverInit=?,
) => unit

Parameters

tWebAPI.DOMTree.nodeoption<mutationObserverInit>

Return type

unit

takeRecords

let takeRecords: t => array<mutationRecord>

Parameters

t

Return type

array<mutationRecord>