/
MutationRecord.purs
70 lines (51 loc) · 1.95 KB
/
MutationRecord.purs
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
66
67
68
69
70
module Web.DOM.MutationRecord
( MutationRecord
, MutationRecordType(..)
, typeString
, type_
, target
, addedNodes
, removedNodes
, nextSibling
, previousSibling
, attributeName
, attributeNamespace
, oldValue
) where
import Prelude
import Effect (Effect)
import Web.DOM.Node (Node)
import Web.DOM.NodeList (NodeList)
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe)
foreign import data MutationRecord :: Type
data MutationRecordType
= MutationRecordAttributes
| MutationRecordCharacterData
| MutationRecordChildList
foreign import typeString :: MutationRecord -> Effect String
type_ :: Partial => MutationRecord -> Effect MutationRecordType
type_ = map stringToType <<< typeString
where
stringToType = case _ of
"attributes" -> MutationRecordAttributes
"characterData" -> MutationRecordCharacterData
"childList" -> MutationRecordChildList
foreign import target :: MutationRecord -> Effect Node
foreign import addedNodes :: MutationRecord -> Effect NodeList
foreign import removedNodes :: MutationRecord -> Effect NodeList
foreign import _nextSibling :: MutationRecord -> Effect (Nullable Node)
nextSibling :: MutationRecord -> Effect (Maybe Node)
nextSibling = map toMaybe <<< _nextSibling
foreign import _previousSibling :: MutationRecord -> Effect (Nullable Node)
previousSibling :: MutationRecord -> Effect (Maybe Node)
previousSibling = map toMaybe <<< _previousSibling
foreign import _attributeName :: MutationRecord -> Effect (Nullable String)
attributeName :: MutationRecord -> Effect (Maybe String)
attributeName = map toMaybe <<< _attributeName
foreign import _attributeNamespace :: MutationRecord -> Effect (Nullable String)
attributeNamespace :: MutationRecord -> Effect (Maybe String)
attributeNamespace = map toMaybe <<< _attributeNamespace
foreign import _oldValue :: MutationRecord -> Effect (Nullable String)
oldValue :: MutationRecord -> Effect (Maybe String)
oldValue = map toMaybe <<< _oldValue