This repository was archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
MutationObserver API #139
Merged
natefaubion
merged 2 commits into
purescript-deprecated:master
from
natefaubion:mutation-observer
Jan 28, 2018
Merged
MutationObserver API #139
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
exports.mutationObserver = function (cb) { | ||
return function () { | ||
return new MutationObserver(function (mr, mo) { | ||
return cb(mr)(mo)(); | ||
}); | ||
}; | ||
}; | ||
|
||
exports._observe = function (node) { | ||
return function (config) { | ||
return function (mo) { | ||
return function () { | ||
return mo.observe(node, config); | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
exports.disconnect = function (mo) { | ||
return function () { | ||
return mo.disconnect(); | ||
}; | ||
}; | ||
|
||
exports.takeRecords = function (mo) { | ||
return function () { | ||
return mo.takeRecords(); | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module DOM.Node.MutationObserver | ||
( MutationObserver | ||
, MutationObserverInitFields | ||
, mutationObserver | ||
, observe | ||
, disconnect | ||
, takeRecords | ||
) where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff (Eff, kind Effect) | ||
import DOM (DOM) | ||
import DOM.Node.MutationRecord (MutationRecord) | ||
import DOM.Node.Types (Node) | ||
|
||
foreign import data MutationObserver :: Type | ||
|
||
type MutationObserverInitFields = | ||
( childList :: Boolean | ||
, attributes :: Boolean | ||
, characterData :: Boolean | ||
, subtree :: Boolean | ||
, attributeOldValue :: Boolean | ||
, characterDataOldValue :: Boolean | ||
, attributeFilter :: Array String | ||
) | ||
|
||
foreign import mutationObserver | ||
:: forall eff | ||
. (MutationRecord -> MutationObserver -> Eff (dom :: DOM | eff) Unit) | ||
-> Eff (dom :: DOM | eff) MutationObserver | ||
|
||
foreign import _observe :: forall eff r. Node -> Record r -> MutationObserver -> Eff (dom :: DOM | eff) Unit | ||
|
||
observe | ||
:: forall eff r rx | ||
. Union r rx MutationObserverInitFields | ||
=> Node | ||
-> Record r | ||
-> MutationObserver | ||
-> Eff (dom :: DOM | eff) Unit | ||
observe = _observe | ||
|
||
foreign import disconnect :: forall eff. MutationObserver -> Eff (dom :: DOM | eff) Unit | ||
|
||
foreign import takeRecords :: forall eff. MutationObserver -> Eff (dom :: DOM | eff) (Array MutationRecord) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use strict"; | ||
|
||
exports.typeString = function (mr) { | ||
return function () { | ||
return mr.type; | ||
}; | ||
}; | ||
|
||
exports.target = function (mr) { | ||
return function () { | ||
return mr.target; | ||
}; | ||
}; | ||
|
||
exports.addedNodes = function (mr) { | ||
return function () { | ||
return mr.addedNodes; | ||
}; | ||
}; | ||
|
||
exports.removedNodes = function (mr) { | ||
return function () { | ||
return mr.removedNodes; | ||
}; | ||
}; | ||
|
||
exports._nextSibling = function (mr) { | ||
return function () { | ||
return mr.nextSibling; | ||
}; | ||
}; | ||
|
||
exports._previousSibling = function (mr) { | ||
return function () { | ||
return mr.previousSibling; | ||
}; | ||
}; | ||
|
||
exports._attributeName = function (mr) { | ||
return function () { | ||
return mr.attributeName; | ||
}; | ||
}; | ||
|
||
exports._attributeNamespace = function (mr) { | ||
return function () { | ||
return mr.attributeNamespace; | ||
}; | ||
}; | ||
|
||
exports._oldValue = function (mr) { | ||
return function () { | ||
return mr.oldValue; | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module DOM.Node.MutationRecord | ||
( MutationRecord | ||
, MutationRecordType(..) | ||
, typeString | ||
, type_ | ||
, target | ||
, addedNodes | ||
, removedNodes | ||
, nextSibling | ||
, previousSibling | ||
, attributeName | ||
, attributeNamespace | ||
, oldValue | ||
) where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff (Eff) | ||
import DOM (DOM) | ||
import DOM.Node.Types (Node, NodeList) | ||
import Data.Maybe (Maybe) | ||
import Data.Nullable (Nullable, toMaybe) | ||
|
||
foreign import data MutationRecord :: Type | ||
|
||
data MutationRecordType | ||
= MutationRecordAttributes | ||
| MutationRecordCharacterData | ||
| MutationRecordChildList | ||
|
||
foreign import typeString :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) String | ||
|
||
type_ :: forall eff. Partial => MutationRecord -> Eff (dom :: DOM | eff) MutationRecordType | ||
type_ = map stringToType <<< typeString | ||
where | ||
stringToType = case _ of | ||
"attributes" -> MutationRecordAttributes | ||
"characterData" -> MutationRecordCharacterData | ||
"childList" -> MutationRecordChildList | ||
|
||
foreign import target :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) Node | ||
|
||
foreign import addedNodes :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) NodeList | ||
|
||
foreign import removedNodes :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) NodeList | ||
|
||
foreign import _nextSibling :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Nullable Node) | ||
|
||
nextSibling :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Maybe Node) | ||
nextSibling = map toMaybe <<< _nextSibling | ||
|
||
foreign import _previousSibling :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Nullable Node) | ||
|
||
previousSibling :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Maybe Node) | ||
previousSibling = map toMaybe <<< _previousSibling | ||
|
||
foreign import _attributeName :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Nullable String) | ||
|
||
attributeName :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Maybe String) | ||
attributeName = map toMaybe <<< _attributeName | ||
|
||
foreign import _attributeNamespace :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Nullable String) | ||
|
||
attributeNamespace :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Maybe String) | ||
attributeNamespace = map toMaybe <<< _attributeNamespace | ||
|
||
foreign import _oldValue :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Nullable String) | ||
|
||
oldValue :: forall eff. MutationRecord -> Eff (dom :: DOM | eff) (Maybe String) | ||
oldValue = map toMaybe <<< _oldValue |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might throw "An invalid or illegal string was specified"
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit