This module is semi-deprecated and currently unused within Elmish. It will probably be resurrected as an optional-validation library.

#JsCallback Source

newtype JsCallback (fn :: Type)

This type represents a function that has been wrapped in a way suitable for passing to JavaScript (including parameter validation). The primary use case for such callbacks is to pass them to JSX code for receiving DOM-generated events and turning them into UI messages. See MkJsCallback for more info and examples.


#JsCallback0 Source

type JsCallback0 = JsCallback (Effect Unit)

A parameterless JsCallback

#JsCallbackError Source

data JsCallbackError

Represents an error that may occur as a result of JS code calling a functuion wrapped as JsCallback.


#MkJsCallback Source

class MkJsCallback fn  where

The core logic of jsCallback.

This type class has two instances below:

  • The instance fn ~ Effect Unit represents a parameterless callback.
  • The instance fn ~ MkJsCallback b => a -> b is recursive, so it represents a callback with one or more parameters.



#jsCallback Source

jsCallback :: forall fn. MkJsCallback fn => fn -> JsCallback fn

Wraps a given effect fn (possibly with parameters) as a JS non-curried function with parameter type validation, making it suitable for passing to unsafe JS code.

This function should not (or at least rarely) be used directly. In normal scenarios, Elmish.Dispatch.handle should be used instead.


  -- PureScript:
  createElement' ffiComponent_
      { onSave: jsCallback $ Console.log "Save"
      , onCancel: jsCallback $ Console.log "Cancel"
      , onFoo: jsCallback \(bar::String) (baz::Int) ->
          Console.log $ "bar = " <> bar <> ", baz = " <> show baz

 // JSX:
 export const FfiComponent = props =>
     <button onClick={props.onSave}>Save</button>
     <button onClick={props.onCancel}>Cancel</button>
     <button onClick={() => props.onFoo("bar", 42)}>Foo</button>

In this example, the parameters bar and baz will undergo validation at runtime to make sure they are indeed a String and an Int respectively, and an error will be issued if validation fails.

#jsCallback' Source

jsCallback' :: forall fn. MkJsCallback fn => fn -> (JsCallbackError -> Effect Unit) -> JsCallback fn

A more elaborate version of jsCallback, which takes an extra parameter

  • an effect to be performed in case of errors.

#jsCallback0 Source

jsCallback0 :: Effect Unit -> JsCallback0

Deprecated. Same as jsCallback.