@@ -4,8 +4,10 @@
5module Frontend where
5module Frontend where
7import qualified Data.Text as T
8import qualified Data.Text as T
8import qualified Data.Text.Encoding as T
9import qualified Data.Text.Encoding as T
10+import Language.Javascript.JSaddle (eval, liftJSM)
10import Obelisk.Frontend
12import Obelisk.Frontend
11import Obelisk.Configs
13import Obelisk.Configs
@@ -18,6 +20,9 @@ import Common.Api
18import Common.Route
20import Common.Route
23+-- This runs in a monad that can be run on the client or the server.
24+-- To run code in a pure client or pure server context, use one of the
25+-- `prerender` functions.
21frontend :: Frontend (R FrontendRoute)
26frontend :: Frontend (R FrontendRoute)
22frontend = Frontend
27frontend = Frontend
23 { _frontend_head = do
28 { _frontend_head = do
@@ -26,6 +31,13 @@ frontend = Frontend
26 , _frontend_body = do
31 , _frontend_body = do
27 el "h1" $ text "Welcome to Obelisk!"
32 el "h1" $ text "Welcome to Obelisk!"
28 el "p" $ text $ T.pack commonStuff
33 el "p" $ text $ T.pack commonStuff
35+ -- `prerender` and `prerender_` let you choose a widget to run on the server
36+ -- during prerendering and a different widget to run on the client with
37+ -- JavaScript. The following will generate a `blank` widget on the server and
38+ -- print "Hello, World!" on the client.
39+ prerender_ blank $ liftJSM $ void $ eval ("console.log('Hello, World!')" :: T.Text)
29 elAttr "img" ("src" =: static @"obelisk.jpg") blank
41 elAttr "img" ("src" =: static @"obelisk.jpg") blank
30 el "div" $ do
42 el "div" $ do
31 exampleConfig <- getConfig "common/example"
43 exampleConfig <- getConfig "common/example"