Skip to content

Commit f148fe5

Browse files
committed
Cleanup session interpreters
1 parent db54047 commit f148fe5

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/WebRow/Session.purs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Data.Lazy (force) as Lazy
88
import Data.Map (Map)
99
import Data.Maybe (fromMaybe)
1010
import Data.Validation.Semigroup (toEither)
11-
import Effect (Effect)
1211
import Effect.Ref (Ref)
1312
import HTTPure (empty) as Headers
1413
import Polyform.Validator.Dual.Pure (Dual, runSerializer, runValidator) as Pure
@@ -70,38 +69,29 @@ cookieName = "session"
7069

7170
runInStore
7271
eff session.
73-
Effect (SessionStore (Run (Cookies + EffRow + eff)) session)
72+
SessionStore (Run (Cookies + EffRow + eff)) session
7473
Run (Cookies + EffRow + Session session + eff)
7574
~> Run (Cookies + EffRow + eff)
76-
runInStore store = runInRunStore (Run.liftEffect store)
77-
78-
runInRunStore
79-
eff session.
80-
Run (Cookies + EffRow + eff) (SessionStore (Run (Cookies + EffRow + eff)) session)
81-
Run (Cookies + EffRow + Session session + eff)
82-
~> Run (Cookies + EffRow + eff)
83-
runInRunStore store action = do
84-
s ← store
75+
runInStore store action = do
8576
let
8677
handleSession
8778
SessionF session ~> Run (Cookies + EffRow + eff)
8879
handleSession (DeleteF next) = do
8980
void $ Cookies.delete cookieName
90-
s.delete >>= next >>> pure
81+
store.delete >>= next >>> pure
9182

9283
handleSession (FetchF next) = do
9384
-- | TODO:
9485
-- | * Handle custom cookie attributes (expiration etc.).
9586
-- | * Should we raise here internalServerError when `set` returns `false`?
9687
-- | * Should we run testing cycle of test cookie setup?
97-
void $ Cookies.set cookieName { value: s.key, attributes: Cookies.defaultAttributes }
98-
s.fetch >>= next >>> pure
88+
void $ Cookies.set cookieName { value: store.key, attributes: Cookies.defaultAttributes }
89+
store.fetch >>= next >>> pure
9990

10091
handleSession (SaveF v next) = do
101-
void $ Cookies.set cookieName { value: s.key, attributes: Cookies.defaultAttributes }
102-
a ← s.save v
92+
void $ Cookies.set cookieName { value: store.key, attributes: Cookies.defaultAttributes }
93+
a ← store.save v
10394
pure (next a)
104-
10595
Run.interpret (Run.on _session handleSession Run.send) action
10696

10797
runInMemoryStore
@@ -113,9 +103,9 @@ runInMemoryStore ∷
113103
runInMemoryStore ref defaultSession action = do
114104
-- | This laziness is a myth let's drop this all together
115105
lazySessionKey ← Cookies.lookup cookieName
116-
let
117-
effSessionStore = SessionStore.InMemory.new ref defaultSession (Lazy.force lazySessionKey)
118-
runInStore (SessionStore.hoist Run.liftEffect <$> effSessionStore) action
106+
effSessionStore ← Run.liftEffect $
107+
SessionStore.InMemory.new ref defaultSession (Lazy.force lazySessionKey)
108+
runInStore (SessionStore.hoist Run.liftEffect $ effSessionStore) action
119109

120110
-- | The whole session is stored in a cookie value so visible in the browser.
121111
-- | We don't need any key-value session store.

0 commit comments

Comments
 (0)