Skip to content

Commit

Permalink
Merge pull request #238 from obsidiansystems/flip-obeliskRouteSegment
Browse files Browse the repository at this point in the history
Swap the arguments of obeliskRouteSegment
  • Loading branch information
luigy authored Oct 10, 2018
2 parents 188a697 + dde0021 commit addb3ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 7 additions & 5 deletions lib/route/src/Obelisk/Route.hs
Original file line number Diff line number Diff line change
Expand Up @@ -705,16 +705,18 @@ obeliskRouteEncoder :: forall check parse appRoute.
)
=> (forall a. appRoute a -> SegmentResult check parse a)
-> Encoder check parse (R (ObeliskRoute appRoute)) PageName
obeliskRouteEncoder appRouteSegment = pathComponentEncoder (obeliskRouteSegment appRouteSegment)
obeliskRouteEncoder appRouteSegment = pathComponentEncoder $ \r ->
obeliskRouteSegment r appRouteSegment

-- | From a function which explains how app-specific frontend routes translate into segments, produce a function which does the
-- same for ObeliskRoute. This uses the given function for the 'ObeliskRoute_App' case, and 'resourceRouteSegment' for the
-- 'ObeliskRoute_Resource' case.
obeliskRouteSegment :: forall check parse appRoute.
obeliskRouteSegment :: forall check parse appRoute a.
(MonadError Text check, MonadError Text parse)
=> (forall a. appRoute a -> SegmentResult check parse a)
-> (forall a. ObeliskRoute appRoute a -> SegmentResult check parse a)
obeliskRouteSegment appRouteSegment = \case
=> ObeliskRoute appRoute a
-> (forall a. appRoute a -> SegmentResult check parse a)
-> SegmentResult check parse a
obeliskRouteSegment r appRouteSegment = case r of
ObeliskRoute_App appRoute -> appRouteSegment appRoute
ObeliskRoute_Resource resourceRoute -> resourceRouteSegment resourceRoute

Expand Down
14 changes: 5 additions & 9 deletions skeleton/common/src/Common/Route.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Prelude hiding (id, (.))
import Control.Category
-}

import Control.Monad.Except
import Data.Text (Text)
import Data.Functor.Identity
import Data.Functor.Sum
Expand All @@ -41,16 +40,13 @@ backendRouteEncoder = handleEncoder (const (InL BackendRoute_Missing :/ ())) $
pathComponentEncoder $ \case
InL backendRoute -> case backendRoute of
BackendRoute_Missing -> PathSegment "missing" $ unitEncoder mempty
InR obeliskRoute -> obeliskRouteSegment frontendRouteSegment obeliskRoute
InR obeliskRoute -> obeliskRouteSegment obeliskRoute $ \case
-- The encoder given to PathEnd determines how to parse query parameters,
-- in this example, we have none, so we insist on it.
FrontendRoute_Main -> PathEnd $ unitEncoder mempty

frontendRouteSegment :: (Applicative check, MonadError Text parse)
=> FrontendRoute a -> SegmentResult check parse a
frontendRouteSegment = \case
FrontendRoute_Main -> PathEnd $ unitEncoder mempty
-- The encoder given to PathEnd determines how to parse query parameters,
-- in this example, we have none, so we insist on it.

concat <$> mapM deriveRouteComponent
[ ''BackendRoute
, ''FrontendRoute
]
]

0 comments on commit addb3ea

Please sign in to comment.