Halogen: TypeError: eff is not a function

I’m building a small web app in Halogen and I just wrapped a little bit of Javascript to close a Bootstrap modal. Javascript:

exports.hide = modalId => {
    $('#'+modalId).modal("hide");
}

Purescript:

module App.Modal where

import Data.Unit (Unit)
import Effect (Effect)

foreign import hide :: String -> Effect Unit

Calling this in handleAction using H.liftEffect (hide foo) works - the modal closes. However, a few seconds after that, I get this error on the console:

Uncaught TypeError: eff is not a function
    at runSync (index.js:1613)
    at _run (index.js:1613)
    at index.js:1613
    at drain (index.js:1613)
    at Object.enqueue (index.js:1613)
    at Object.run (index.js:1613)
    at __do (index.js:1613)
    at index.js:1613
    at index.js:1613
    at mbEmit (index.js:1613)

I’m not sure if this is related to my code. It doesn’t happen if I don’t open/close the modal at all.

What does the error tell me? I don’t even have the word eff in my code. The traceback is to Data.Map.Internal. It’s really confusing me.

I can provide more sample code, but I cannot publish the whole repository.

Effects in PureScript are represented in the compiled JS as functions that take no parameters. Thus, you would have to change the definition of hide to this:

exports.hide = modalId => () => {
    $('#'+modalId).modal("hide");
}

See https://github.com/purescript/documentation/blob/4f6c0e3b8b6184329ab1e9f7ec3c0f5a5e27a393/guides/FFI-Tips.md#why-doesnt-my-effect-work-when-passed-to-a-normal-js-function.

1 Like

Excellent, thank you. Indeed it works now!

1 Like