Closed gurdiga closed 6 years ago
Have you tried elm ports? I think they are the best way to do js interoperability. In my opinion native modules is for stuff that needs low level interop, is that your case?
Yes, I have tried ports, and I will probably switch to them as soon as I clarify what exactly do I need to get from outside Elm. Right now Iโm trying to rich to Intl, for some number- and date-formatting functions.
@gurdiga Hi!, sorry for the delay, but I have updated the example with a function with two parameters as you were expecting. I hope this can help you.
Hi Gabriel! ๐
Thank you for putting this together: It helped me get started with Native modules in Elm 0.18! ๐ค
NOTE: This is not really an issue, itโs more like an idea to add to the README, if it looks useful to you. ๐
So, in my case I needed a function thatโd take 2 arguments:
and then I tried to call it like this:
It compiled, but when run in the browser (through
elm-reactor
) it crashed the whole Elm app with something like this in the Chrome console:๐ถThen I went on to look how itโs done in the
elm-lang/core
and found this inNative/Debug.js
:Then I looked in my bundle and found
F2
:So my guess after all of this, is that if a native function that we want to use in Elm takes more than one argument, it has to be wrapped into an
F<number>
thing like that โ it seems like further on Elm decides how many arguments to pass it. ๐ค (I foundF1
toF9
in my bundle. ๐ค)Iโm not sure where would this insight go in the README, but I thought this may be useful for someone! ๐ค
Cheers! ๐