summaryrefslogtreecommitdiff
path: root/src/Utils.purs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.purs')
-rw-r--r--src/Utils.purs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Utils.purs b/src/Utils.purs
index 8c530ef..e4fd125 100644
--- a/src/Utils.purs
+++ b/src/Utils.purs
@@ -32,11 +32,15 @@ maybeToArray :: forall a. Maybe a -> Array a
maybeToArray (Just x) = [x]
maybeToArray Nothing = []
-byId :: forall m. MonadEffect m => String -> m DOM.Element
-byId i = do
+maybeById :: forall m. MonadEffect m => String -> m (Maybe DOM.Element)
+maybeById i = do
w <- liftEffect HTML.window
d <- liftEffect $ HTML.Doc.toDocument <$> HTML.Win.document w
- liftEffect (DOM.NEP.getElementById i (DOM.Doc.toNonElementParentNode d)) >>= case _ of
+ liftEffect (DOM.NEP.getElementById i (DOM.Doc.toNonElementParentNode d))
+
+byId :: forall m. MonadEffect m => String -> m DOM.Element
+byId i = do
+ maybeById i >>= case _ of
Nothing -> liftEffect $ throw $ "could not find element with id: " <> i
Just e -> pure e