Skip to content

Commit e10c6d8

Browse files
committed
Adds runWithDispatch helper to RunWithCommands
This allows you to execute a `RunWithCommands` all the way down to the model, running any commands that it contains using a provided dispatch function. This is useful when `RunWithCommands` is being used from with the body of command that is being constructed via `dispatchCmd`.
1 parent 56e2b33 commit e10c6d8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/DOM/Erumu/RunWithCommands.purs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module DOM.Erumu.RunWithCommands
22
( RunWithCommands
33
, run
4+
, runWithDispatch
45
, lift
56
, mapMsg
67
, mapModel
@@ -17,7 +18,7 @@ module DOM.Erumu.RunWithCommands
1718
import Prelude
1819
import Control.Parallel as Par
1920

20-
import DOM.Erumu.Types (UpdateResult, Command, (!), dispatchCmd, runCommand, nocmd)
21+
import DOM.Erumu.Types (UpdateResult, Command, (!), DispatchFn, dispatchCmd, runCommand, nocmd)
2122
import DOM.Erumu.Types as Types
2223

2324
{-
@@ -75,6 +76,17 @@ run ::
7576
run (RunWithCommands action) =
7677
action
7778

79+
runWithDispatch ::
80+
forall m msg model.
81+
Monad m =>
82+
DispatchFn m msg ->
83+
RunWithCommands m msg model ->
84+
m model
85+
runWithDispatch dispatch runWithCommands = do
86+
updateResult <- run runWithCommands
87+
runCommand dispatch updateResult.command
88+
pure updateResult.model
89+
7890
lift ::
7991
forall m msg model.
8092
Applicative m =>

0 commit comments

Comments
 (0)