on master help sign in
Working hydration
commitd16addc900a7c7e3d1c26d0c103a97eeeb91842f authorTom Smalley <tfsmalley@gmail.com> dateTue 20 Nov 2018, 16:01 (8 years ago) parent4d44ef3
5 files changed+81−82
default.nix+9−9 dep/reflex-dom/github.json+2−2 dep/reflex-platform/github.json+3−3 lib/frontend/src/Obelisk/Frontend.hs+10−9 skeleton/frontend/src/Frontend.hs+57−59
default.nix+9−9
@@ -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,17 +300,17 @@ in rec {
300300 commonName
301301 frontendName
302302 ]);
303− ghc = ([
303+ ghc = (lib.filter (x: lib.hasAttr x combinedPackages)[
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"
307+# "obelisk-route"
308+# "obelisk-frontend"
309+# "obelisk-backend"
310+# "obelisk-executable-config"
311+# "obelisk-run"
312+# "reflex-dom-core"
313+# "reflex-dom"
314314 ]);
315315 ghcjs = lib.filter (x: lib.hasAttr x combinedPackages) [
316316 frontendName
dep/reflex-dom/github.json+2−2
@@ -2,6 +2,6 @@
22 "owner": "reflex-frp",
33 "repo": "reflex-dom",
44 "branch": "ts-hydration",
5− "rev": "54e0b3fd63fe94fe8f4d244fad323dbb0d773606",
6− "sha256": "05hk54jb4ixzwnb73ll6ggq2cxxlb8vlj8xxknc82l931fqpiwyn"
5+ "rev": "785099bba0e93a42dc89a4d309519687466cea38",
6+ "sha256": "03wsnixx615ixvpnvfn057qap1ssiixwz22sqh6kfw54dbvnd4mp"
77}
dep/reflex-platform/github.json+3−3
@@ -1,7 +1,7 @@
11{
22 "owner": "reflex-frp",
33 "repo": "reflex-platform",
4− "branch": "develop",
5− "rev": "018576456043fe8372a0332c93245a4a620c1fb7",
6− "sha256": "0qhnyyf96iajz97pbqfsw2l1kkbr1yq3bvw3qhjk031vdrkv7b7y"
4+ "branch": "ts-hydration",
5+ "rev": "b672c2125403e3d47d1c0f59bca4d98b079c02d4",
6+ "sha256": "0yv8ix6yjk90d5rfv6smcb1smzkzfz09n1g0pdb37dfygmmw8nam"
77}
lib/frontend/src/Obelisk/Frontend.hs+10−9
@@ -30,6 +30,7 @@ import Control.Monad.Ref
3030import Control.Monad.Trans.Class
3131import Data.ByteString (ByteString)
3232import Data.Dependent.Sum (DSum (..))
33+import Data.Foldable (for_)
3334import Data.Functor.Sum
3435import Data.IORef
3536import Data.Monoid ((<>))
@@ -88,13 +89,12 @@ type DomCoreWidget x = PostBuildT DomTimeline (WithJSContextSingleton x (Perform
8889{-# INLINABLE attachWidget''' #-}
8990attachWidget'''
9091 :: Document
91− -> Node
9292 -> IORef HydrationMode
93− -> IORef [DOM DomTimeline (PostBuildT DomTimeline (WithJSContextSingleton () (PerformEventT DomTimeline DomHost)))]
93+ -> IORef [(Node, [DOM DomTimeline (PostBuildT DomTimeline (WithJSContextSingleton () (PerformEventT DomTimeline DomHost)))])]
9494 -> JSContextSingleton ()
9595 -> (EventChannel -> PerformEventT DomTimeline DomHost (IORef (Maybe (EventTrigger DomTimeline ()))))
9696 -> IO ()
97−attachWidget''' doc bodyNode hydrationMode hres jsSing w = do
97+attachWidget''' doc hydrationMode hres jsSing w = do
9898 events <- newChan
9999 runDomHost $ flip runTriggerEventT events $ mdo
100100 (syncEvent, fireSync) <- newTriggerEvent
@@ -106,12 +106,13 @@ attachWidget''' doc bodyNode hydrationMode hres jsSing w = do
106106 mPostBuildTrigger <- readRef postBuildTriggerRef
107107 lift $ forM_ mPostBuildTrigger $ \postBuildTrigger -> fire [postBuildTrigger :=> Identity ()] $ return ()
108108 liftIO $ fireSync ()
109− forest <- liftIO $ readIORef hres
109+ forests <- liftIO $ readIORef hres
110110 -- TODO: DomHost is SpiderHost Global only if we're not in profiling mode
111111 let delayedAction = do
112− liftIO $ putStrLn "-------------------------------------- Performing delayed actions"
113− void $ runWithJSContextSingleton (runPostBuildT (runHydrationRunnerT (runDOMForest forest) Nothing bodyNode events) never) jsSing
114− liftIO $ putStrLn "-------------------------------------- Performed delayed actions"
112+ for_ (reverse forests) $ \(rootNode, forest) -> do
113+ liftIO $ putStrLn "-------------------------------------- Performing delayed actions"
114+ void $ runWithJSContextSingleton (runPostBuildT (runHydrationRunnerT (runDOMForest forest) Nothing rootNode events) never) jsSing
115+ liftIO $ putStrLn "-------------------------------------- Performed delayed actions"
115116 liftIO $ writeIORef hydrationMode HydrationMode_Immediate
116117 liftIO $ processAsyncEvents events fc
117118
@@ -129,7 +130,7 @@ runWithHeadAndBody app = withJSContextSingletonMono $ \jsSing -> do
129130 unreadyChildren <- liftIO $ newIORef 0
130131 hydrationMode <- liftIO $ newIORef HydrationMode_Hydrating
131132 hydrationResult <- liftIO $ newIORef []
132− liftIO $ attachWidget''' globalDoc (toNode bodyElement) hydrationMode hydrationResult jsSing $ \events -> flip runWithJSContextSingleton jsSing $ do
133+ liftIO $ attachWidget''' globalDoc hydrationMode hydrationResult jsSing $ \events -> flip runWithJSContextSingleton jsSing $ do
133134 (postBuild, postBuildTriggerRef) <- newEventWithTriggerRef
134135 let hydrateDom :: DOM.Node -> Widget' () c -> FloatingWidget () c
135136 hydrateDom n w = do
@@ -146,7 +147,7 @@ runWithHeadAndBody app = withJSContextSingletonMono $ \jsSing -> do
146147 , _hydrationDomBuilderEnv_prerenderDepth = prerenderDepth
147148 }
148149 (a, res) <- runHydrationDomBuilderT w builderEnv events'
149− liftIO $ modifyIORef' hydrationResult $ \xs -> xs ++ res -- TODO
150+ liftIO $ modifyIORef' hydrationResult ((n, res) :)
150151 pure a
151152 flip runPostBuildT postBuild $ flip runTriggerEventT events $ app (hydrateDom $ toNode headElement) (hydrateDom $ toNode bodyElement)
152153-- liftIO (readIORef unreadyChildren) >>= \case
skeleton/frontend/src/Frontend.hs+57−59
@@ -39,9 +39,9 @@ tshow = T.pack . show
3939
4040frontend :: Frontend (R FrontendRoute)
4141frontend = Frontend
42− { _frontend_head = pure ()
43− -- TODO lib/Frontend needs fixing for this to work
44− -- el "title" $ text "Obelisk Minimal Example"
42+ { _frontend_head = do
43+ el "title" $ text "Obelisk Minimal Example"
44+ elAttr "meta" mempty blank
4545 , _frontend_body = do
4646 text "Welcome to Obelisk!"
4747 el "p" $ text $ T.pack commonStuff
@@ -50,38 +50,38 @@ frontend = Frontend
5050 performEvent $ liftIO . print <$> updated clicks
5151 el "p" $ text "Clicks: " >> el "span" (display clicks) -- TODO multiple text bug
5252
53+ pb <- getPostBuild
54+
5355 timer <- tickLossy 1 =<< liftIO getCurrentTime
5456 seconds <- count timer
5557 el "p" $ display seconds
5658 text "-----------------------------------------------"
5759
58−-- elAttr "article" ("style" =: "background: lightcoral") $ do
59−-- prerender
60−-- (prerender
61−-- (el "span" $ text "Server span")
62−-- (el "a" $ text "JS link"))
63−-- (el "a" $ text "JS link")
64−
65− pb <- getPostBuild
60+ elAttr "article" ("style" =: "background: lightcoral") $ do
61+ prerender
62+ (prerender
63+ (el "span" $ text "Server span")
64+ (el "a" $ text "JS link, inner"))
65+ (el "a" $ text "JS link")
6666
67− elAttr "article" ("style" =: "background: moccasin") $ do
68− widgetHold_ (el "div" $ text "first") $ ffor pb $ \() -> display seconds
67+-- elAttr "article" ("style" =: "background: moccasin") $ do
68+-- widgetHold_ (el "div" $ text "first") $ ffor pb $ \() -> display seconds
6969
7070-- elAttr "article" ("style" =: "background: lightgreen") $ do
7171-- widgetHold_ (do prerender (liftIO $ putStrLn "-------- server missiles") (liftIO $ putStrLn "-------- client missiles"); el "div" $ text "first") never
7272
73− elAttr "article" ("style" =: "background: paleturquoise") $ do
74− dyn_ $ ffor clicks $ \x -> case x `mod` 2 of
75− 0 -> el "span" $ text "Even"
76− 1 -> el "span" $ text "Odd"
77−
78− elAttr "article" ("style" =: "background: cornflowerblue") $ do
79− widgetHold (text "first") $ ffor (updated clicks) $ \x -> case x `mod` 2 of
80− 0 -> do
81− dyn_ $ ffor seconds $ \x -> case x `mod` 2 of
82− 0 -> el "span" $ text "Even"
83− 1 -> text "Odd"
84− 1 -> el "span" $ text "Odd inner"
73+-- elAttr "article" ("style" =: "background: paleturquoise") $ do
74+-- dyn_ $ ffor clicks $ \x -> case x `mod` 2 of
75+-- 0 -> el "span" $ text "Even"
76+-- 1 -> el "span" $ text "Odd"
77+--
78+-- elAttr "article" ("style" =: "background: cornflowerblue") $ do
79+-- widgetHold (text "first") $ ffor (updated clicks) $ \x -> case x `mod` 2 of
80+-- 0 -> do
81+-- dyn_ $ ffor seconds $ \x -> case x `mod` 2 of
82+-- 0 -> el "span" $ text "Even"
83+-- 1 -> text "Odd"
84+-- 1 -> el "span" $ text "Odd inner"
8585
8686 -- These will be squashed into a single text node by the static renderer
8787-- text "Test"
@@ -92,48 +92,46 @@ frontend = Frontend
9292
9393 --traverseDMapWithKeyWithAdjust' :: (forall a. k a -> v a -> m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> m (DMap k v', Event t (PatchDMap k v'))
9494-- elAttr "article" ("style" =: "background: thistle") $ do
95−-- (m', e') <- traverseDMapWithKeyWithAdjust (\k v -> has @Show k $ dkeyWidget k v) keyMap $ ffor (updated clicks) $ \_ -> case 0 of -- x -> case x `mod` 2 of
95+-- (m', e') <- traverseDMapWithKeyWithAdjust (\k v -> has @Show k $ dkeyWidget k v) keyMap $ ffor (updated clicks) $ \x -> case x `mod` 2 of
9696-- 0 -> PatchDMap $ DMap.singleton Key_Int (ComposeMaybe $ Just $ Identity 10)
9797-- 1 -> PatchDMap $ DMap.singleton Key_Bool (ComposeMaybe $ case x `mod` 3 of 0 -> Nothing; _ -> Just $ Identity True) <> DMap.singleton Key_Char (ComposeMaybe $ Just $ Identity (toEnum $ fromEnum 'A' + x))
98− pure ()
99−
100−
98+-- pure ()
99+--
100+--
101101-- elAttr "article" ("style" =: "background: thistle") $ do
102102-- (m', e') <- traverseDMapWithKeyWithAdjust (\k v -> has @Show k $ dkeyWidget k v) keyMap $
103103-- PatchDMap (DMap.singleton Key_Int (ComposeMaybe $ Just $ Identity 10)) <$ pb
104104-- pure ()
105−
106− {-
107− elAttr "article" ("style" =: "background: maroon") $ do
108− widgetHold (text "first") $ ffor pb $ \_ -> do
109− (m', e') <- traverseDMapWithKeyWithAdjust (\k v -> has @Show k $ dkeyWidget k v) keyMap $ ffor (updated clicks) $ \x -> case x `mod` 2 of
110− 0 -> PatchDMap $ DMap.singleton Key_Int (ComposeMaybe $ Just $ Identity x)
111− 1 -> PatchDMap $ DMap.singleton Key_Bool (ComposeMaybe $ case x `mod` 3 of 0 -> Nothing; _ -> Just $ Identity True) <> DMap.singleton Key_Char (ComposeMaybe $ Just $ Identity (toEnum $ fromEnum 'A' + x))
112− pure ()
113−
114− move <- button "Move"
115− ins <- button "Insert"
116− del <- button "Delete"
105+--
106+-- elAttr "article" ("style" =: "background: maroon") $ do
107+-- widgetHold (text "first") $ ffor pb $ \_ -> do
108+-- (m', e') <- traverseDMapWithKeyWithAdjust (\k v -> has @Show k $ dkeyWidget k v) keyMap $ ffor (updated clicks) $ \x -> case x `mod` 2 of
109+-- 0 -> PatchDMap $ DMap.singleton Key_Int (ComposeMaybe $ Just $ Identity x)
110+-- 1 -> PatchDMap $ DMap.singleton Key_Bool (ComposeMaybe $ case x `mod` 3 of 0 -> Nothing; _ -> Just $ Identity True) <> DMap.singleton Key_Char (ComposeMaybe $ Just $ Identity (toEnum $ fromEnum 'A' + x))
111+-- pure ()
112+--
113+-- move <- button "Move"
114+-- ins <- button "Insert"
115+-- del <- button "Delete"
117116
118117 --traverseDMapWithKeyWithAdjust' :: (forall a. k a -> v a -> m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> m (DMap k v', Event t (PatchDMap k v'))
119− elAttr "article" ("style" =: "background: yellow") $ do
120− (m', e') <- traverseDMapWithKeyWithAdjustWithMove (\k v -> has @Show k $ dkeyWidget k v) keyMap $ leftmost
121− -- TODO: move causes JSException here and in Immediate builder
122− [ ffor move $ \() -> moveDMapKey Key_Int2 Key_Int
123− , ffor ins $ \() -> insertDMapKey Key_Int (Identity 4)
124− , ffor del $ \() -> deleteDMapKey Key_Int
125− ]
126− pure ()
127−
128− elAttr "article" ("style" =: "background: cyan") $ do
129− (m', e') <- traverseIntMapWithKeyWithAdjust (\k v -> intkeyWidget k v) intMap $ leftmost
130− -- TODO: move causes JSException here and in Immediate builder
131− [ ffor move $ \() -> PatchIntMap $ IntMap.singleton 1 (Just 'Z')
132− , ffor ins $ \() -> PatchIntMap $ IntMap.singleton 5 (Just 'Z')
133− , ffor del $ \() -> PatchIntMap $ IntMap.singleton 3 Nothing
134− ]
135− pure ()
136− -}
118+-- elAttr "article" ("style" =: "background: yellow") $ do
119+-- (m', e') <- traverseDMapWithKeyWithAdjustWithMove (\k v -> has @Show k $ dkeyWidget k v) keyMap $ leftmost
120+-- -- TODO: move causes JSException here and in Immediate builder
121+-- [ ffor move $ \() -> moveDMapKey Key_Int2 Key_Int
122+-- , ffor ins $ \() -> insertDMapKey Key_Int (Identity 4)
123+-- , ffor del $ \() -> deleteDMapKey Key_Int
124+-- ]
125+-- pure ()
126+--
127+-- elAttr "article" ("style" =: "background: cyan") $ do
128+-- (m', e') <- traverseIntMapWithKeyWithAdjust (\k v -> intkeyWidget k v) intMap $ leftmost
129+-- -- TODO: move causes JSException here and in Immediate builder
130+-- [ ffor move $ \() -> PatchIntMap $ IntMap.singleton 1 (Just 'Z')
131+-- , ffor ins $ \() -> PatchIntMap $ IntMap.singleton 5 (Just 'Z')
132+-- , ffor del $ \() -> PatchIntMap $ IntMap.singleton 3 Nothing
133+-- ]
134+-- pure ()
137135
138136-- el "footer" $ text "Footer"
139137 pure ()