on master help sign in
Merge branch 'develop' into an@test-private-public-thunk
3d2f0e6Elliot Cameron
README.md+4−3
@@ -23,14 +23,15 @@ Obelisk provides an easy way to develop and deploy your [Reflex](https://github.
231. Set up nix caches
231. Set up nix caches
24 1. If you are running NixOS, add this to `/etc/nixos/configuration.nix`:
24 1. If you are running NixOS, add this to `/etc/nixos/configuration.nix`:
25 ```
25 ```
26− nix.binaryCaches = [ "https://cache.nixos.org/" "https://nixcache.reflex-frp.org" ];
26+ nix.binaryCaches = [ "https://nixcache.reflex-frp.org" ];
27 nix.binaryCachePublicKeys = [ "ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=" ];
27 nix.binaryCachePublicKeys = [ "ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=" ];
28 ```
28 ```
29 and rebuild your NixOS configuration (e.g. `sudo nixos-rebuild switch`).
29 and rebuild your NixOS configuration (e.g. `sudo nixos-rebuild switch`).
30 1. If you are using another operating system or linux distribution, ensure that these lines are present in your Nix configuration file (`/etc/nix/nix.conf` on most systems; [see full list](https://nixos.org/nix/manual/#sec-conf-file)):
30 1. If you are using another operating system or linux distribution, ensure that these lines are present in your Nix configuration file (`/etc/nix/nix.conf` on most systems; [see full list](https://nixos.org/nix/manual/#sec-conf-file)):
31 ```
31 ```
32− substituters = https://cache.nixos.org https://nixcache.reflex-frp.org
32+ binary-caches = https://cache.nixos.org https://nixcache.reflex-frp.org
33− trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
33+ binary-cache-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
34+ binary-caches-parallel-connections = 40
34 ```
35 ```
35 * other Linux: enable sandboxing (see these [issue172](https://github.com/obsidiansystems/obelisk/issues/172#issuecomment-411507818) or [issue6](https://github.com/obsidiansystems/obelisk/issues/6) if you run into build problems)
36 * other Linux: enable sandboxing (see these [issue172](https://github.com/obsidiansystems/obelisk/issues/172#issuecomment-411507818) or [issue6](https://github.com/obsidiansystems/obelisk/issues/6) if you run into build problems)
36 ```
37 ```
skeleton/frontend/frontend.cabal+1
@@ -9,6 +9,7 @@ library
9 , common
9 , common
10 , obelisk-frontend
10 , obelisk-frontend
11 , obelisk-route
11 , obelisk-route
12+ , jsaddle
12 , reflex-dom
13 , reflex-dom
13 , obelisk-executable-config-lookup
14 , obelisk-executable-config-lookup
14 , obelisk-generated-static
15 , obelisk-generated-static
skeleton/frontend/src/Frontend.hs+12
@@ -4,8 +4,10 @@
4
4
5module Frontend where
5module Frontend where
6
6
7+import Control.Monad
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)
9
11
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
19
21
20
22
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
34+
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)
40+
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"