LIFF ports for Elm

Hi all,

I creating a ports library to make Elm running on LINE Frontend Framework (or LIFF) called elm-liff. It’s far to be done but it work in normal use-case in common LIFF app. Because of it’s a ports module, that’s means it cannot publish to elm-packages anyway. I would love to see how do you manage this kind library in practice?

Another things that I realize that LIFF cannot open a new window without calling liff.openWindow. It’s make Elm debugger not working anyway. I not sure how to make it works. :frowning:

And I’m really welcome if someone can review my code and suggesting me because I just start learning an Elm around 1 month and I didn’t any experience with functional language so much. :slight_smile:

1 Like

Hi, you cannot publish a ports module, but there is something of a workaround for that.

Suppose your module looks like this:

port module MyAwesomeLib exposing (somePort)

port somePort : String -> Cmd msg

You can change it instead to be:

module MyAwesomeLib exposing (SomePort)

type alias SomePort = String -> Cmd msg

Now anyone wanting to use your package needs to define the port themselves in their application. They will also need the corresponding javascript side code. You can make this easier for them by:

  1. Describe in the README exactly what ports they need to set up in the application, and what they need to be called. So tell them to put this in the application, along with the other instructions on how to use it:
    port somePort : MyAwesomeLib.SomePort
  1. Publish your javascript code on npm, so that it can easily be added as a dependency in package.json. OR if its just a very short snippet, you could put the javascript code in the README. There will need to be a short snippet in the README anyway, to show how to wire the port up:
    app.ports.somePort.subscribe(request => {

Thanks for your reply. I open a PR to confirm with you that I understand you right here It seems the library needs to tell user what exact name of port to user to avoid unexpected working in the library. I start thinking that I can provide a shell script or node command line tools (can bundle with npm package) to initialize port to avoid this situation.

Yes, that looks right. You also corrected my mistake (which I also fixed above). Its not SomePort : X -> Cmd msg it is as you have done it type alias SomePort = X -> Cmd msg.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.