Skip to content

Instantly share code, notes, and snippets.

@imalsogreg
Created December 2, 2016 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imalsogreg/465a481e357192c08bc17b6dab64959e to your computer and use it in GitHub Desktop.
Save imalsogreg/465a481e357192c08bc17b6dab64959e to your computer and use it in GitHub Desktop.
webRoute
:: (MonadWidget t m, WR.PathInfo a)
=> T.Text -- ^ The part of the URL not related to SPA routing, starting with '/'
-> Event t a
-> m (Dynamic t (Either T.Text a))
webRoute pathBase aUpdates = do
route' encoder decoder aUpdates
where
-- x = WR.fromPathInfo :: _
encoder u a = u & U.pathL .~ T.encodeUtf8 (pathBase <> WR.toPathInfo a)
decoder u = first T.pack . WR.fromPathInfo =<<
note (pathBase <> " is a Bad prefix for " <> T.decodeUtf8 (U.serializeURIRef' u))
(BS.stripPrefix (T.encodeUtf8 pathBase) (u ^. U.pathL))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment