Module
Elmish.Dispatch
- Package
- purescript-elmish
- Repository
- collegevine/purescript-elmish
#HandleEffect Source
class HandleEffect event f | f -> event where
Members
handleEffect :: f -> EffectFn1 event Unit
An escape-hatch way to create an event handler for when neither
handle
norhandleMaybe
are appropriate, which usually happens when the event handler must do something else, besides dispatching a message.The argument may be either an
Effect Unit
or a function from the event object toEffect Unit
. If a message needs to be dispatched, the consuming code is expected to do it via calling theDispatch
function directly.div { onKeyDown: E.handleEffect \(E.KeyboardEvent e) -> do window >>= localStorage >>= setItem "Last key pressed" e.key dispatch PressedKey , onClick: E.handleEffect \e -> do E.stopPropagation e dispatch ClickedDiv }
Instances
HandleEffect event (event -> Effect Unit)
HandleEffect event (Effect Unit)
#HandleMaybe Source
class HandleMaybe msg event f | f -> msg event where
Members
handleMaybe :: Dispatch msg -> f -> EffectFn1 event Unit
A variant of
handle
(aka<|
) that allows to dispatch a message or not conditionally via returning aMaybe message
.Expected usage for this function is in its operator form
<?|
div { onMouseDown: dispatch <?| \(E.MouseEvent e) -> if e.ctrlKey then Just ClickedWithControl else Nothing }
Instances
(TypeEquals (t msg) (Maybe msg)) => HandleMaybe msg event (event -> t msg)
(TypeEquals (t msg) (Maybe msg)) => HandleMaybe msg event (t msg)
A convenience function to make construction of event handlers with arguments (i.e.
EffectFn1
) a bit shorter. The first parameter is aDispatch
. The second parameter can be either a message or a function from the event object to a message.Expected usage for this function is in its operator form
<|