diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-07-01 21:30:59 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-07-01 21:50:08 +0200 |
| commit | 06263ef351281cb27b2cbdb46e2a39d57d084ae4 (patch) | |
| tree | 716c6d713590bad7c8ceeb950f8c2ffd7a884c63 /src/JavaScript/Node.hs | |
| parent | 2573b8a2cae5bf2f3f58aff4135876da7152081d (diff) | |
Add class for conversations with unread messages
Diffstat (limited to 'src/JavaScript/Node.hs')
| -rw-r--r-- | src/JavaScript/Node.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/JavaScript/Node.hs b/src/JavaScript/Node.hs new file mode 100644 index 0000000..c9ad8af --- /dev/null +++ b/src/JavaScript/Node.hs @@ -0,0 +1,38 @@ +module JavaScript.Node ( + Node, IsNode(..), + getTextContent, setTextContent, + appendChild, +) where + +import JavaScript.Event +import JavaScript.Val + + +newtype Node = Node JSVal + deriving (ToJSVal, FromJSVal) + +class IsNode a where + toNode :: a -> Node + +instance IsNode Node where + toNode = id + +instance IsEventTarget Node where + toEventTarget = fromJSValUnchecked . toJSVal + + +getTextContent :: IsNode n => n -> IO String +getTextContent n = fromJSString <$> js_get_textContent (toJSVal $ toNode n) +foreign import javascript unsafe "$1.textContent" + js_get_textContent :: JSVal -> IO JSString + +setTextContent :: IsNode n => String -> n -> IO () +setTextContent value n = js_set_textContent (toJSVal $ toNode n) (toJSString value) +foreign import javascript unsafe "$1.textContent = $2" + js_set_textContent :: JSVal -> JSString -> IO () + + +appendChild :: (IsNode c, IsNode p) => c -> p -> IO () +appendChild child parent = js_appendChild (toJSVal $ toNode parent) (toJSVal $ toNode child) +foreign import javascript unsafe "$1.appendChild($2)" + js_appendChild :: JSVal -> JSVal -> IO () |