git.iko.soy/rowtype-yoga/purescript-yoga-om-layer
on main help sign in
Memoize-by-default via unique layer IDs
commitdd4fb21d8f169f7924e9b62af1a024df1e72b9f1 authorMark <mark.eibes@gmail.com> dateFri 13 Feb 2026, 22:09 (8 months ago) parentc8076e3
1 file changed+33−1
test/Test/Main.purs+33−1
test/Test/Main.purs+33−1
@@ -14,7 +14,7 @@ import Test.Spec.Assertions (shouldEqual)
1414import Test.Spec.Reporter (consoleReporter)
1515import Test.Spec.Runner (runSpec)
1616import Yoga.Om as Om
17−import Yoga.Om.Layer (OmLayer, Scope, makeLayer, makeScopedLayer, bracketLayer, combineRequirements, runLayer, runScoped, withScoped, provide)
17+import Yoga.Om.Layer (OmLayer, Scope, makeLayer, makeScopedLayer, bracketLayer, fresh, combineRequirements, runLayer, runScoped, withScoped, provide)
1818
1919-- Example types
2020type Config = { port :: Int, host :: String }
@@ -153,6 +153,38 @@ main = launchAff_ $ runSpec [ consoleReporter ] do
153153 finalLog <- liftEffect $ Ref.read log
154154 finalLog `shouldEqual` [ "acquire", "release" ]
155155
156+ it "fresh layer builds twice even when same base layer" do
157+ counter <- liftEffect $ Ref.new 0
158+ let
159+ baseLayer :: OmLayer (scope :: Scope) (value :: String) ()
160+ baseLayer = makeLayer do
161+ liftEffect $ Ref.modify_ (_ + 1) counter
162+ pure { value: "built" }
163+
164+ branch1 :: OmLayer (scope :: Scope) (out1 :: String) ()
165+ branch1 = consumer `provide` fresh baseLayer
166+ where
167+ consumer :: OmLayer (scope :: Scope, value :: String) (out1 :: String) ()
168+ consumer = makeLayer do
169+ { value } <- Om.ask
170+ pure { out1: value <> "-1" }
171+
172+ branch2 :: OmLayer (scope :: Scope) (out2 :: String) ()
173+ branch2 = consumer `provide` fresh baseLayer
174+ where
175+ consumer :: OmLayer (scope :: Scope, value :: String) (out2 :: String) ()
176+ consumer = makeLayer do
177+ { value } <- Om.ask
178+ pure { out2: value <> "-2" }
179+
180+ app = combineRequirements branch1 branch2
181+
182+ result <- liftAff $ runScoped app
183+ result.out1 `shouldEqual` "built-1"
184+ result.out2 `shouldEqual` "built-2"
185+ count <- liftEffect $ Ref.read counter
186+ count `shouldEqual` 2
187+
156188 it "combines scoped and non-scoped layers" do
157189 log <- liftEffect $ Ref.new []
158190 let