Skip to content

Commit

Permalink
Initial implementation of hydrateWidget
Browse files Browse the repository at this point in the history
Co-Authored-By: Serhii Khoma <srghma@gmail.com>
  • Loading branch information
purefunctor and srghma committed Jun 15, 2024
1 parent 589a429 commit f214200
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Halogen/VDom/DOM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Halogen.VDom.DOM
, hydrateVDom
, hydrateText
, hydrateElem
, hydrateKeyed
, hydrateWidget
) where

import Prelude
Expand All @@ -31,7 +33,6 @@ import Halogen.VDom.Machine (Machine, Step, Step'(..), extract, halt, mkStep, st
import Halogen.VDom.Machine as Machine
import Halogen.VDom.Types (ElemName(..), Namespace(..), VDom(..), runGraft)
import Halogen.VDom.Util as Util
import Unsafe.Coerce (unsafeCoerce)
import Web.DOM.Document (Document) as DOM
import Web.DOM.Element (Element) as DOM
import Web.DOM.Element as DOMElement
Expand Down Expand Up @@ -116,7 +117,7 @@ hydrateVDom hydrationSpec@(VDomHydrationSpec { vdomSpec }) = hydrate
Text s -> EFn.runEffectFn5 hydrateText currentNode hydrationSpec hydrate build s
Elem ns n a ch -> EFn.runEffectFn8 hydrateElem currentNode hydrationSpec hydrate build ns n a ch
Keyed ns n a ch -> EFn.runEffectFn8 hydrateKeyed currentNode hydrationSpec hydrate build ns n a ch
Widget _ -> unsafeCoerce unit
Widget w -> EFn.runEffectFn5 hydrateWidget currentNode hydrationSpec hydrate build w
Grafted g -> EFn.runEffectFn1 (hydrate currentNode) (runGraft g)

type TextState a w =
Expand Down Expand Up @@ -447,6 +448,15 @@ buildWidget = EFn.mkEffectFn3 \(VDomSpec spec) build w → do
mkStep $ Step n { build, widget: res } patchWidget haltWidget
pure res'

hydrateWidget :: forall a w. VDomHydrator w a w
hydrateWidget = EFn.mkEffectFn5 \currentNode hydrationSpec@(VDomHydrationSpec { hydrateWidget: hydrateWidgetInternal }) _ build w -> do
res <- EFn.runEffectFn1 (hydrateWidgetInternal hydrationSpec currentNode) w
let
res' :: VDomStep a w
res' = res # unStep \(Step n _ _ _) ->
mkStep $ Step n { build, widget: res } patchWidget haltWidget
pure res'

patchWidget a w. EFn.EffectFn2 (WidgetState a w) (VDom a w) (VDomStep a w)
patchWidget = EFn.mkEffectFn2 \state vdom → do
let { build, widget } = state
Expand Down

0 comments on commit f214200

Please sign in to comment.