Remove nested error handling and clean up some
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
<head>
|
<head>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="svgContainer" class="my-class"></div>
|
ticks:
|
||||||
|
<input type="number" id="ticks"/>
|
||||||
|
<div id="svg-container" class="my-class"></div>
|
||||||
</body>
|
</body>
|
||||||
<script src="index.js"></script>
|
<script src="index.js"></script>
|
||||||
</html>
|
</html>
|
||||||
@@ -19,14 +19,11 @@ import Web.DOM.Document (contentType
|
|||||||
)
|
)
|
||||||
import Web.DOM.DOMParser (makeDOMParser, parseSVGFromString)
|
import Web.DOM.DOMParser (makeDOMParser, parseSVGFromString)
|
||||||
import Web.DOM.Element (toNode) as Element
|
import Web.DOM.Element (toNode) as Element
|
||||||
import Web.DOM.HTMLCollection (length)
|
|
||||||
import Web.DOM.Node (appendChild, nodeName, setTextContent)
|
import Web.DOM.Node (appendChild, nodeName, setTextContent)
|
||||||
import Web.DOM.NonElementParentNode (getElementById)
|
import Web.DOM.NonElementParentNode (getElementById)
|
||||||
import Web.DOM.ParentNode (firstElementChild)
|
import Web.DOM.ParentNode (firstElementChild)
|
||||||
import Web.HTML (window)
|
import Web.HTML (window)
|
||||||
import Web.HTML.HTMLDocument (toDocument)
|
import Web.HTML.HTMLDocument (toDocument)
|
||||||
import Web.HTML.HTMLMetaElement (setContent)
|
|
||||||
import Web.HTML.HTMLDivElement (fromElement)
|
|
||||||
import Web.HTML.Window (document)
|
import Web.HTML.Window (document)
|
||||||
|
|
||||||
-- Consider DOM.Simple.Types
|
-- Consider DOM.Simple.Types
|
||||||
@@ -36,26 +33,24 @@ main = do
|
|||||||
w <- window
|
w <- window
|
||||||
d <- document w
|
d <- document w
|
||||||
let dd = toDocument d
|
let dd = toDocument d
|
||||||
dUrl <- url dd
|
|
||||||
let containerID = "svgContainer"
|
|
||||||
domParser <- makeDOMParser
|
domParser <- makeDOMParser
|
||||||
let mySVG = ternaryGraph 100.0 50.0 50.0 10
|
|
||||||
svgDoc <- parseSVGFromString mySVG domParser
|
let containerID = "svg-container"
|
||||||
maybeElement <- getElementById containerID $ toNonElementParentNode dd
|
maybeElement <- getElementById containerID $ toNonElementParentNode dd
|
||||||
case maybeElement of
|
node <- case maybeElement of
|
||||||
Nothing -> do
|
Nothing -> throw $ "Unable to find " <> containerID
|
||||||
throw $ "Unable to find " <> containerID
|
Just e -> pure $ Element.toNode e
|
||||||
Just e -> do
|
|
||||||
let node = Element.toNode e
|
let mySVG = ternaryGraph 100.0 50.0 50.0 10
|
||||||
case svgDoc of
|
svgDocMay <- parseSVGFromString mySVG domParser
|
||||||
|
svgDoc <- case svgDocMay of
|
||||||
Left error -> throw error
|
Left error -> throw error
|
||||||
Right doc -> do
|
Right doc -> pure doc
|
||||||
log $ nodeName (toNode doc)
|
|
||||||
elMay <- firstElementChild $ toParentNode doc
|
elMay <- firstElementChild $ toParentNode svgDoc
|
||||||
case elMay of
|
svgNode <- case elMay of
|
||||||
Nothing -> throw "oops"
|
Nothing -> throw "no child in svg doc"
|
||||||
Just el -> do
|
Just el -> pure $ Element.toNode el
|
||||||
let svgNode = Element.toNode el
|
|
||||||
log $ nodeName svgNode
|
|
||||||
newNode <- importNode svgNode true dd
|
newNode <- importNode svgNode true dd
|
||||||
appendChild newNode node
|
appendChild newNode node
|
||||||
|
|||||||
Reference in New Issue
Block a user