@@ -43,11 +43,11 @@ import qualified GHCJS.DOM as DOM
43import qualified GHCJS.DOM.Types as DOM
43import qualified GHCJS.DOM.Types as DOM
44import qualified GHCJS.DOM.History as DOM
44import qualified GHCJS.DOM.History as DOM
45import qualified GHCJS.DOM.Window as DOM
45import qualified GHCJS.DOM.Window as DOM
46−import Language.Javascript.JSaddle (JSM, jsNull)
46+import Language.Javascript.JSaddle (MonadJSM, JSM, jsNull)
47import GHCJS.DOM (currentDocument)
47import GHCJS.DOM (currentDocument)
48import GHCJS.DOM.Document (getHead)
48import GHCJS.DOM.Document (getHead)
49−import GHCJS.DOM.Node (removeChild_)
49+import GHCJS.DOM.Node (Node, removeChild_)
50−import GHCJS.DOM.NodeList (item, getLength)
50+import GHCJS.DOM.NodeList (IsNodeList, item, getLength)
51import GHCJS.DOM.ParentNode (querySelectorAll)
51import GHCJS.DOM.ParentNode (querySelectorAll)
52import Obelisk.Frontend.Cookie
52import Obelisk.Frontend.Cookie
53import Obelisk.Route.Frontend
53import Obelisk.Route.Frontend
@@ -105,13 +105,20 @@ removeHTMLConfigs :: JSM ()
105removeHTMLConfigs = void $ runMaybeT $ do
105removeHTMLConfigs = void $ runMaybeT $ do
106 doc <- MaybeT currentDocument
106 doc <- MaybeT currentDocument
107 hd <- MaybeT $ getHead doc
107 hd <- MaybeT $ getHead doc
108− es <- collToList =<< querySelectorAll hd ("[data-obelisk-executable-config-inject-key]" :: Text)
108+ es <- nodeListNodes =<< querySelectorAll hd ("[data-obelisk-executable-config-inject-key]" :: Text)
109 for_ es $ removeChild_ hd
109 for_ es $ removeChild_ hd
111− collToList es = do
111+-- | Collect all nodes in the node list.
113+-- TODO: this and the version in exe-config/ghcjs/lookup should be
114+-- upstreamed to jsaddle.
115+nodeListNodes :: (IsNodeList l, MonadJSM m) => l -> m [Node]
116+nodeListNodes es = do
112− len <- getLength es
117+ len <- getLength es
113− lst <- traverse (item es) $ take (fromIntegral len) $ [0..] -- fun with unsigned types ...
118+ -- Warning! len is unsigned. If the NodeList is empty, we must avoid
119+ -- accidentally traversing over [0..maxBound::Word]
120+ nodes <- traverse (item es) $ if len == 0 then [] else [0..len-1]
114− pure $ catMaybes lst
121+ pure $ catMaybes nodes
116setInitialRoute :: Bool -> JSM ()
123setInitialRoute :: Bool -> JSM ()
117setInitialRoute useHash = do
124setInitialRoute useHash = do