on master help sign in
wip
commit64336bc6661d24056caaa6f2efca7d7e5fbaa1a6 authorTom Smalley <tfsmalley@gmail.com> dateFri 2 Nov 2018, 19:24 (8 years ago) parent3ec4f82
8 files changed+63−27
default.nix+9−2 dep/reflex-dom/default.nix+7 dep/reflex-dom/github.json+7 lib/frontend/src/Obelisk/Frontend.hs+20−21 skeleton/default.nix−4 skeleton/frontend/src/Frontend.hs+4 skeleton/obrun+3 skeleton/run+13
default.nix+9−2
@@ -283,7 +283,7 @@ in rec {
283283 combinedPackages = predefinedPackages // packages;
284284 projectOverrides = self: super: {
285285 ${staticName} = haskellLib.dontHaddock (self.callCabal2nix staticName processedStatic.haskellManifest {});
286− ${backendName} = haskellLib.addBuildDepend super.${backendName} self.obelisk-run;
286+# ${backendName} = haskellLib.addBuildDepend super.${backendName} self.obelisk-run;
287287 };
288288 totalOverrides = lib.composeExtensions projectOverrides overrides;
289289 inherit (lib.strings) hasPrefix;
@@ -300,10 +300,17 @@ in rec {
300300 commonName
301301 frontendName
302302 ]);
303− ghc = (lib.filter (x: lib.hasAttr x combinedPackages) [
303+ ghc = ([
304304 backendName
305305 commonName
306306 frontendName
307+ "obelisk-route"
308+ "obelisk-frontend"
309+ "obelisk-backend"
310+ "obelisk-executable-config"
311+ "obelisk-run"
312+ "reflex-dom-core"
313+ "reflex-dom"
307314 ]);
308315 ghcjs = lib.filter (x: lib.hasAttr x combinedPackages) [
309316 frontendName
dep/reflex-dom/default.nixnew file+7
@@ -0,0 +1,7 @@
1+# DO NOT HAND-EDIT THIS FILE
2+import ((import <nixpkgs> {}).fetchFromGitHub (
3+ let json = builtins.fromJSON (builtins.readFile ./github.json);
4+ in { inherit (json) owner repo rev sha256;
5+ private = json.private or false;
6+ }
7+))
dep/reflex-dom/github.jsonnew file+7
@@ -0,0 +1,7 @@
1+{
2+ "owner": "reflex-frp",
3+ "repo": "reflex-dom",
4+ "branch": "ts-hydration",
5+ "rev": "a945be75317ff0b8577cb011145cdf16861c6817",
6+ "sha256": "1baq0sgiqlkr5mdp22q637k4h6lbslp30198d3wh0rd1m8k1k4mn"
7+}
lib/frontend/src/Obelisk/Frontend.hs+20−21
@@ -83,13 +83,15 @@ type DomCoreWidget x = PostBuildT DomTimeline (WithJSContextSingleton x (Perform
8383--TODO: Rename
8484{-# INLINABLE attachWidget''' #-}
8585attachWidget'''
86− :: (EventChannel -> PerformEventT DomTimeline DomHost (IORef (Maybe (EventTrigger DomTimeline ()))))
86+ :: IORef Bool
87+ -> (EventChannel -> PerformEventT DomTimeline DomHost (IORef (Maybe (EventTrigger DomTimeline ()))))
8788 -> IO ()
88−attachWidget''' w = runDomHost $ do
89+attachWidget''' hydration w = runDomHost $ do
8990 events <- liftIO newChan
9091 (postBuildTriggerRef, fc@(FireCommand fire)) <- hostPerformEventT $ w events
9192 mPostBuildTrigger <- readRef postBuildTriggerRef
9293 forM_ mPostBuildTrigger $ \postBuildTrigger -> fire [postBuildTrigger :=> Identity ()] $ return ()
94+ liftIO $ writeIORef hydration False
9395 liftIO $ processAsyncEvents events fc
9496
9597--TODO: This is a collection of random stuff; we should make it make some more sense and then upstream to reflex-dom-core
@@ -101,33 +103,30 @@ runWithHeadAndBody
101103 -> JSM ()
102104runWithHeadAndBody app = withJSContextSingletonMono $ \jsSing -> do
103105 globalDoc <- currentDocumentUnchecked
104− headFragment <- createDocumentFragment globalDoc
105− bodyFragment <- createDocumentFragment globalDoc
106+ headElement <- getHeadUnchecked globalDoc
107+ bodyElement <- getBodyUnchecked globalDoc
106108 unreadyChildren <- liftIO $ newIORef 0
107− let commit = do
108− headElement <- getHeadUnchecked globalDoc
109− bodyElement <- getBodyUnchecked globalDoc
110− void $ inAnimationFrame' $ \_ -> do
111− replaceElementContents headElement headFragment
112− replaceElementContents bodyElement bodyFragment
113− liftIO $ attachWidget''' $ \events -> flip runWithJSContextSingleton jsSing $ do
109+ hydration <- liftIO $ newIORef True
110+ liftIO $ attachWidget''' hydration $ \events -> flip runWithJSContextSingleton jsSing $ do
114111 (postBuild, postBuildTriggerRef) <- newEventWithTriggerRef
115− let appendImmediateDom :: DOM.DocumentFragment -> Widget' () c -> FloatingWidget () c
116− appendImmediateDom df w = do
112+ let appendImmediateDom :: DOM.Node -> Widget' () c -> FloatingWidget () c
113+ appendImmediateDom n w = do
114+ hydrationNode <- liftIO $ newIORef Nothing
117115 events' <- TriggerEvent.askEvents
118116 lift $ do
119− doc <- getOwnerDocumentUnchecked df
120117 let builderEnv = ImmediateDomBuilderEnv
121− { _immediateDomBuilderEnv_document = doc
122− , _immediateDomBuilderEnv_parent = toNode df
118+ { _immediateDomBuilderEnv_document = globalDoc
119+ , _immediateDomBuilderEnv_parent = toNode n
123120 , _immediateDomBuilderEnv_unreadyChildren = unreadyChildren
124− , _immediateDomBuilderEnv_commitAction = commit
121+ , _immediateDomBuilderEnv_commitAction = pure ()
122+ , _immediateDomBuilderEnv_hydrating = hydration
123+ , _immediateDomBuilderEnv_hydrationNode = hydrationNode
125124 }
126125 runImmediateDomBuilderT w builderEnv events'
127− flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (appendImmediateDom headFragment) (appendImmediateDom bodyFragment)
128− liftIO (readIORef unreadyChildren) >>= \case
129− 0 -> DOM.liftJSM commit
130− _ -> return ()
126+ flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (appendImmediateDom $ toNode headElement) (appendImmediateDom $ toNode bodyElement)
127+-- liftIO (readIORef unreadyChildren) >>= \case
128+-- 0 -> DOM.liftJSM commit
129+-- _ -> return ()
131130 return postBuildTriggerRef
132131
133132runFrontend :: forall backendRoute route. Encoder Identity Identity (R (Sum backendRoute (ObeliskRoute route))) PageName -> Frontend (R route) -> JSM ()
skeleton/default.nix−4
@@ -3,8 +3,4 @@
33}:
44with import ./.obelisk/impl { inherit system iosSdkVersion; };
55project ./. ({ ... }: {
6− android.applicationId = "systems.obsidian.obelisk.examples.minimal";
7− android.displayName = "Obelisk Minimal Example";
8− ios.bundleIdentifier = "systems.obsidian.obelisk.examples.minimal";
9− ios.bundleName = "Obelisk Minimal Example";
106})
skeleton/frontend/src/Frontend.hs+4
@@ -20,4 +20,8 @@ frontend = Frontend
2020 text "Welcome to Obelisk!"
2121 el "p" $ text $ T.pack commonStuff
2222 elAttr "img" ("src" =: static @"obelisk.jpg") blank
23+ e <- button "click"
24+ el "p" $ display =<< count e
25+ pb <- getPostBuild
26+ widgetHold_ (el "div" $ text "first") $ ffor pb $ \() -> el "div" $ text "second"
2327 }
skeleton/obrunnew file+3
@@ -0,0 +1,3 @@
1+:l Obelisk.Run Backend Frontend
2+import Obelisk.Run
3+
skeleton/runnew file+13
@@ -0,0 +1,13 @@
1+#!/usr/bin/env bash
2+ghci -I../dep/reflex-dom/reflex-dom-core/dist/build/autogen \
3+-i../dep/reflex-dom/reflex-dom/src:../dep/reflex-dom/reflex-dom-core/src:../dep/reflex-dom/reflex-dom-core/src-ghc:./.obelisk/impl/lib/executable-config/inject/src:./.obelisk/impl/lib/executable-config/lookup/src:./.obelisk/impl/lib/route/src:./.obelisk/impl/lib/frontend/src:./.obelisk/impl/lib/backend/src:./.obelisk/impl/lib/run/src:./frontend/src:./backend/src:./common/src:. \
4+-dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir \
5+dist/build -stubdir dist/build -idist/build -isrc -isrc-ghc \
6+-idist../dep/reflex-dom/reflex-dom-core/build/autogen \
7+-idist../dep/reflex-dom/reflex-dom-core/build/global-autogen \
8+-Idist../dep/reflex-dom/reflex-dom-core/build/autogen \
9+-Idist../dep/reflex-dom/reflex-dom-core/build/global-autogen \
10+-Idist../dep/reflex-dom/reflex-dom-core/build -optP-DUSE_TEMPLATE_HASKELL \
11+-ignore-dot-ghci \
12+-ghci-script obrun
13+ "$@"