Module

Elmish.Dispatch

Package
purescript-elmish
Repository
collegevine/purescript-elmish

#(<?|) Source

Operator alias for Elmish.Dispatch.handleMaybe (right-associative / precedence 0)

#(<|) Source

Operator alias for Elmish.Dispatch.handle (right-associative / precedence 0)

#Dispatch Source

type Dispatch msg = msg -> Effect Unit

A function that a view can use to report messages originating from JS/DOM.

#Handle Source

class Handle msg event f | f -> msg event where

Members

  • handle :: Dispatch msg -> f -> EffectFn1 event Unit

    A convenience function to make construction of event handlers with arguments (i.e. EffectFn1) a bit shorter. The first parameter is a Dispatch. 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 <|

    textarea
      { value: state.text
      , onChange: dispatch <| \e -> TextAreaChanged (E.textareaText e)
      , onMouseDown: dispatch <| TextareaClicked
      }
    

Instances

#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 nor handleMaybe 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 to Effect Unit. If a message needs to be dispatched, the consuming code is expected to do it via calling the Dispatch 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

#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 a Maybe 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