Skip to content

Commit

Permalink
stopped cleaning up regions allocated from a StaticRegion, was never …
Browse files Browse the repository at this point in the history
…necessary anyway
  • Loading branch information
jterbraak committed Jul 23, 2024
1 parent 1091470 commit c970858
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
17 changes: 4 additions & 13 deletions deku-core/src/Deku/Core.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Deku.Core
, PSR(..)
, newPSR
, pump
, handleScope
, attributeAtYourOwnRisk
, callbackWithCaution
, cb
Expand Down Expand Up @@ -96,6 +97,7 @@ import Deku.Internal.Region (Anchor(..), Bound, Region(..), StaticRegion(..), al
import Effect (Effect, forE)
import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, mkEffectFn1, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3)
import FRP.Event as Event
import FRP.Event.Class (once)
import FRP.Poll (Poll(..))
import FRP.Poll as Poll
import FRP.Poll.Unoptimized as UPoll
Expand Down Expand Up @@ -289,7 +291,7 @@ newPSR = mkSTFn2 \lifecycle region -> do
forE 0 l \i -> do
unsafePartial $ Array.unsafeIndex stack ( l - 1 - i )

pure (PSR { lifecycle, region, defer: doDefer, dispose })
pure (PSR { lifecycle : once lifecycle, region, defer: doDefer, dispose })

handleScope :: EffectFn1 PSR Unit
handleScope = mkEffectFn1 \psr -> do
Expand Down Expand Up @@ -486,9 +488,6 @@ useDynWith elements options cont = Nut $ mkEffectFn2 \psr di -> do
Region region <- liftST $ (un StaticRegion (un PSR psr).region).region
span <- liftST $ runSTFn2 newSpan region.begin region.bump

runEffectFn2 deferO psr do
liftST region.remove

let
handleElements :: EffectFn1 (Tuple (Maybe Int) value) Unit
handleElements = mkEffectFn1 \(Tuple initialPos value) -> do
Expand Down Expand Up @@ -524,11 +523,7 @@ useDynWith elements options cont = Nut $ mkEffectFn2 \psr di -> do
target <- liftST eltRegion.begin
runEffectFn3 (un DOMInterpret di).beamRegion fromBegin fromEnd target

disposeElementRegion :: Effect Unit
disposeElementRegion =
liftST eltRegion.remove

runEffectFn2 deferO eltPSR disposeElementRegion
runEffectFn2 deferO eltPSR (liftST eltRegion.remove)
runEffectFn3 pump eltPSR sendTo handleSendTo
runEffectFn2 nut eltPSR di

Expand Down Expand Up @@ -582,8 +577,6 @@ elementify ns tag arrAtts nuts = Nut $ mkEffectFn2 \psr di -> do
runEffectFn2 Event.fastForeachE nuts handleNuts

runEffectFn2 (un DOMInterpret di).attachElement (DekuChild elt) regionEnd


runEffectFn1 handleScope psr

text_ :: String -> Nut
Expand Down Expand Up @@ -702,7 +695,6 @@ portaled buffer beam beamed bumped trackBegin trackEnd =
unsubBeamed <- runEffectFn2 Event.subscribeO beamed $ mkEffectFn1 \_ -> do
whenM ( not <$> liftST ( ST.read stolen ) ) do
void $ liftST $ ST.write true stolen
liftST region.remove

unsubBumped <- runEffectFn2 Event.subscribeO bumped $ mkEffectFn1 $ liftST
<<< runSTFn1 region.bump
Expand Down Expand Up @@ -737,7 +729,6 @@ portaled buffer beam beamed bumped trackBegin trackEnd =
target
void $ liftST $ ST.write buffer trackBegin
void $ liftST $ ST.write true stolen
liftST region.remove

runEffectFn2 deferO psr restoreBuffer
runEffectFn1 handleScope psr
7 changes: 3 additions & 4 deletions deku-core/src/Deku/Internal/Region.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ import Control.Plus (empty)
import Data.Array as Array
import Data.Array.ST as STArray
import Data.Foldable (traverse_)
import Data.Maybe (Maybe(..), fromMaybe, isJust, maybe)
import Data.Maybe (Maybe(..), isJust, maybe)
import Data.Newtype (class Newtype)
import Deku.Internal.Entities (DekuElement, DekuParent, DekuText)
import Effect.Exception.Unsafe (unsafeThrow)
import FRP.Event (createPure)
import FRP.Poll (Poll, pollFromEvent, stRefToPoll)
import Partial.Unsafe (unsafePartial)
Expand Down Expand Up @@ -152,15 +151,15 @@ newSpan = mkSTFn2 \parent parentBump -> do
-- `bumpBound` and `clearBound` have safeguards to never call this effect
pushAnchor :: STFn1 Anchor Global Unit
pushAnchor =
mkSTFn1 \_ -> unsafeThrow "parent forced to update anchor"
mkSTFn1 \_ -> pure unit -- unsafeThrow "parent forced to update anchor"

ST.new { owner, extent, bound: parent, pushAnchor }

let
parentRegion :: ManagedRegion
parentRegion =
{ ix: pure 0
, pushIx: mkSTFn1 \_ -> unsafeThrow "parent forced to update index"
, pushIx: mkSTFn1 \_ -> pure unit -- unsafeThrow "parent forced to update index"
, position: empty
, end: parentBound
}
Expand Down
4 changes: 2 additions & 2 deletions deku/test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import Web.HTML.Window (alert)

foreign import hackyInnerHTML :: String -> String -> Effect Unit

runTest :: Nut -> Effect Unit
runTest = void <<< runInBody
runTest :: Nut -> Effect (Effect Unit)
runTest = runInBody

sanityCheck :: Nut
sanityCheck = D.span [ DA.id_ "hello" ] [ text_ "Hello" ]
Expand Down
3 changes: 2 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const doTest = (name, closure, ionly) => {
}
document.getElementsByTagName("html")[0].innerHTML =
'<head></head><body id="mybody"></body>';
tests.runTest(myTest)();
const unsub = tests.runTest(myTest)();
await myScript(false);
unsub();
});
});
};
Expand Down

0 comments on commit c970858

Please sign in to comment.