@@ -7,6 +7,7 @@
77{-# LANGUAGE RankNTypes #-}
88{-# LANGUAGE RecursiveDo #-}
99{-# LANGUAGE ScopedTypeVariables #-}
10+{-# LANGUAGE StandaloneDeriving #-}
1011{-# LANGUAGE TypeFamilies #-}
1112{-# LANGUAGE UndecidableInstances #-}
1213
@@ -142,7 +143,9 @@ instance PrimMonad m => PrimMonad (RouteT t segment m) where
142143--instance HasMountStatus t m => HasMountStatus t (RouteT segment r m) where
143144-- getMountStatus = lift getMountStatus
144145
145−
146+-- | Runs a monadic action (in 'RouteT') over the current URL as "interpreted"
147+-- by the given URL-parser. The action must return an 'Event' which can trigger
148+-- the route to change.
146149runRoute :: forall segment t m. (MonadWidget t m, Eq segment)
147150 => (forall a. URIRef a -> [segment])
148151 -> (forall a. URIRef a -> [segment] -> URIRef a)
@@ -170,7 +173,8 @@ runRoute toSegments fromSegments (RouteT f) = do
170173 let x = ffor uri $ \uri' -> fromSegments uri' <$> newSegments
171174 pure (switch (current x))
172175
173−
176+-- | A very simple version of 'runRoute' that parses only the URL fragment
177+-- and splits it over @/@. Each path segment is therefore nothing more than 'Text'.
174178runRouteWithPathInFragment
175179 :: forall t m. (MonadWidget t m)
176180 => RouteT t Text m (Event t [Text])
@@ -179,7 +183,8 @@ runRouteWithPathInFragment = runRoute
179183 (T.splitOn "/" . T.dropAround (=='/') . fragAsText)
180184 (\oldUrl -> setFrag oldUrl . T.intercalate "/")
181185
182−
186+-- | Introduces a new "layer" in the nested routing tree. The given function takes
187+-- the current layer's route segment and builds the DOM for that segment.
183188withRoute
184189 :: forall a segment t m. (DomBuilder t m, MonadFix m, PostBuild t m, MonadHold t m, HasRoute t segment m, Eq segment)
185190 => (Maybe segment -> m a)
@@ -218,18 +223,23 @@ withRoute f = do
218223
219224 switchPromptly never =<< dyn component
220225
221−
226+-- | All routing segments in the current URL.
222227allRouteSegments :: (MonadHold t m, MonadFix m, HasRoute t segment m, Eq segment) => m (Dynamic t [segment])
223228allRouteSegments = _routeContext_allSegments <$> routeContext
224229
230+-- | The routing segment at "this layer" in the tree. "This layer" is defined by how many
231+-- nested 'withRoute's exist above the caller of this function.
225232currentRouteSegment :: (Functor m, HasRoute t segment m) => m (Dynamic t (Maybe segment))
226233currentRouteSegment = _routeContext_currentSegment <$> routeContext
227234
235+-- | The next layer's segment in the tree. Like 'withRoute' this can be used to switch
236+-- over route segments, but it does not place a new layer in the tree.
228237nextRouteSegment :: (MonadHold t m, MonadFix m, HasRoute t segment m, Eq segment) => m (Dynamic t (Maybe segment))
229238nextRouteSegment = do
230239 ctx <- routeContext
231240 holdUniqDyn (listToMaybe <$> _routeContext_nextSegments ctx)
232241
242+-- | Route segments from parent layers.
233243parentRouteSegments :: (MonadHold t m, MonadFix m, HasRoute t segment m, Eq segment) => m (Dynamic t [segment])
234244parentRouteSegments = do
235245 ctx <- routeContext
@@ -237,6 +247,7 @@ parentRouteSegments = do
237247 allSegments <- _routeContext_allSegments ctx
238248 pure $ take (_routeContext_currentDepth ctx - 1) allSegments
239249
250+-- | A simple helper that produces a routing event on 'getPostBuild'.
240251redirectLocally :: (PostBuild t m) => [segment] -> m (Event t [segment])
241252redirectLocally segments = (segments <$) <$> getPostBuild
242253