on master help sign in
Merge branch 'develop' into an@test-private-public-thunk
commit3d2f0e6ad5780c4e6f12dd8efb02d159562e8224 authorElliot Cameron <3noch@users.noreply.github.com> dateTue 14 Jan 2020, 14:34 (7 years ago) parented93989e767736
3 files changed+17−3
README.md+4−3 skeleton/frontend/frontend.cabal+1 skeleton/frontend/src/Frontend.hs+12
README.md+4−3
@@ -23,14 +23,15 @@ Obelisk provides an easy way to develop and deploy your [Reflex](https://github.
23231. Set up nix caches
2424 1. If you are running NixOS, add this to `/etc/nixos/configuration.nix`:
2525 ```
26− nix.binaryCaches = [ "https://cache.nixos.org/" "https://nixcache.reflex-frp.org" ];
26+ nix.binaryCaches = [ "https://nixcache.reflex-frp.org" ];
2727 nix.binaryCachePublicKeys = [ "ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=" ];
2828 ```
2929 and rebuild your NixOS configuration (e.g. `sudo nixos-rebuild switch`).
3030 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)):
3131 ```
32− substituters = https://cache.nixos.org https://nixcache.reflex-frp.org
33− trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
32+ binary-caches = https://cache.nixos.org https://nixcache.reflex-frp.org
33+ binary-cache-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
34+ binary-caches-parallel-connections = 40
3435 ```
3536 * 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)
3637 ```
skeleton/frontend/frontend.cabal+1
@@ -9,6 +9,7 @@ library
99 , common
1010 , obelisk-frontend
1111 , obelisk-route
12+ , jsaddle
1213 , reflex-dom
1314 , obelisk-executable-config-lookup
1415 , obelisk-generated-static
skeleton/frontend/src/Frontend.hs+12
@@ -4,8 +4,10 @@
44
55module Frontend where
66
7+import Control.Monad
78import qualified Data.Text as T
89import qualified Data.Text.Encoding as T
10+import Language.Javascript.JSaddle (eval, liftJSM)
911
1012import Obelisk.Frontend
1113import Obelisk.Configs
@@ -18,6 +20,9 @@ import Common.Api
1820import Common.Route
1921
2022
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.
2126frontend :: Frontend (R FrontendRoute)
2227frontend = Frontend
2328 { _frontend_head = do
@@ -26,6 +31,13 @@ frontend = Frontend
2631 , _frontend_body = do
2732 el "h1" $ text "Welcome to Obelisk!"
2833 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+
2941 elAttr "img" ("src" =: static @"obelisk.jpg") blank
3042 el "div" $ do
3143 exampleConfig <- getConfig "common/example"