2

So I've written a few super simple apps in elm. But they're completely in elm. What I'm wondering is if I can make modules in elm and use them in my javascript projects. I often make and maintain opensource projects which I use in projects for my clients. This helps speed up my work, and also gives me feedback from the community on how to improve these projects. It's a great mutual benefit. I have a project that I believe could really benefit from using elm, but I would need to use it as a module in my production projects as I cannot simply port these applications to elm nor can I convince most of my clients that elm is popular enough to make it a good decision to use for their project.

So I'm really curious to know if elm can be used to create modules which can be used in javascript, much to the same effect as how you can make typescript modules which you can use in your vanilla JS.

1

1 Answer 1

4

Do you mean to use function implemented by Elm from javascript?

Then, here is what I did with my project.

You can code your Elm project using Platform.program.

main : Program Never Model Msg
main =
  Platform.program
    { init = init
    , update = update
    , subscriptions = subscriptions
    }

then you can load compiled code and interact with the compiled module via port from your javascript project.

// load main Elm script
const app = require('./elm').Main.worker()
app.ports.test.subscribe(.......
Sign up to request clarification or add additional context in comments.

1 Comment

Very interesting, so it's as though you communicate with the module via a channel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.