Skip to content

Commit

Permalink
runST (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Solomon <[email protected]>
  • Loading branch information
Mike Solomon and Mike Solomon authored Dec 7, 2022
1 parent 49f6632 commit 56ce8b4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.9.7] - 2022-12-07

- Makes `runST` polymorphic over `r`.


## [0.9.6] - 2022-12-01

- Adds `NutWith`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-deku",
"version": "0.9.6",
"version": "0.9.7",
"description": "A friendly tree-like structure in the browser.",
"scripts": {
"postinstall": "node node_modules/puppeteer/install.js",
Expand Down
75 changes: 48 additions & 27 deletions src/Deku/Toplevel.purs
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,64 @@ derive instance Newtype Template _

runSSR
:: Template
-> ( forall lock
-> ( forall lock r
. Domable lock
(RRef.STRef Global (Array Instruction) -> ST Global Unit)
(RRef.STRef r (Array Instruction) -> ST r Unit)
-> ST r String
)
-> ST Global String
runSSR = runSSR' "body"

runSSR'
:: String
-> Template
-> ( forall lock
-> ( forall lock r
. Domable lock
(RRef.STRef Global (Array Instruction) -> ST Global Unit)
(RRef.STRef r (Array Instruction) -> ST r Unit)
-> ST r String
)
-> ST Global String
runSSR' topTag (Template { head, tail }) children =
(head <> _) <<< (_ <> tail) <<< ssr' topTag
<$> liftST
( do
seed <- RRef.new 0
instr <- RRef.new []
let di = ssrDOMInterpret seed
void $ subscribePure
( ( __internalDekuFlatten
{ parent: Just "deku-root"
, scope: Local "rootScope"
, raiseId: \_ -> pure unit
, ez: true
, pos: Nothing
, dynFamily: Nothing
}
di
children
)
runSSR' topTag (Template { head, tail }) = go
where
go
:: forall lock r
. Domable lock
(RRef.STRef r (Array Instruction) -> ST r Unit)
-> ST r String
go children' = do
let
children =
( unsafeCoerce
:: ( Domable lock
(RRef.STRef r (Array Instruction) -> ST r Unit)
)
-> ( Domable lock
(RRef.STRef Global (Array Instruction) -> ST Global Unit)
)
) children'
unglobal = unsafeCoerce :: ST Global String -> ST r String

unglobal
( (head <> _) <<< (_ <> tail) <<< ssr' topTag
<$>
( do
seed <- RRef.new 0
instr <- RRef.new []
let di = ssrDOMInterpret seed
void $ subscribePure
( ( __internalDekuFlatten
{ parent: Just "deku-root"
, scope: Local "rootScope"
, raiseId: \_ -> pure unit
, ez: true
, pos: Nothing
, dynFamily: Nothing
}
di
children
)
)
\i -> i instr
RRef.read instr
)
\i -> i instr
RRef.read instr
)

__internalDekuFlatten
Expand Down

0 comments on commit 56ce8b4

Please sign in to comment.