File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ module Miso
31
31
, Sink
32
32
-- ** Component
33
33
, mail
34
+ , checkMail
34
35
, parent
35
36
, broadcast
36
37
-- ** Subscriptions
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ module Miso.Runtime
39
39
, ComponentState
40
40
-- ** Communication
41
41
, mail
42
+ , checkMail
42
43
, broadcast
43
44
, parent
44
45
) where
@@ -930,6 +931,30 @@ mail vcompId message = io_ $
930
931
pure ()
931
932
Just ComponentState {.. } ->
932
933
liftIO $ sendMail componentMailbox (toJSON message)
934
+ ----------------------------------------------------------------------------
935
+ -- | Helper function for processing 'Mail' from 'mail'.
936
+ --
937
+ -- @
938
+ --
939
+ -- data Action
940
+ -- = ParsedMail Message
941
+ -- | ErrorMail MisoString
942
+ --
943
+ -- main = app { mailbox = checkMail ParsedMail ErrorMail }
944
+ --
945
+ -- @
946
+ --
947
+ -- @since 1.9.0.0
948
+ checkMail
949
+ :: FromJSON value
950
+ => (value -> action )
951
+ -> (MisoString -> action )
952
+ -> Value
953
+ -> Maybe action
954
+ checkMail successful errorful value =
955
+ pure $ case fromJSON value of
956
+ Success x -> successful x
957
+ Error err -> errorful (ms err)
933
958
-----------------------------------------------------------------------------
934
959
-- | Fetches the parent `model` from the child.
935
960
--
You can’t perform that action at this time.
0 commit comments