4 ms·
I hear this criticism about ports a lot. Out of curiosity, how could we make it better? Do you have any examples of what you consider to be the ideal FFI? I hav
by fbonetti 10y ago
I hear this criticism about ports a lot. Out of curiosity, how could we make it better? Do you have any examples of what you consider to be the ideal FFI? I haven't used ports a ton, but I have used them for interop between Elm and the Google Maps Javascript API, and I didn't think it was that bad.
- shados 10y agoPureScript is a good example. The problem isn't that it doesn't work. It's that what you do with ports only work in the context of your application. The JavaScript part has to be defined somewhere else, the Elm code assumes the JavaScript part will be there. You can't redistribute that easily. How to make it better? that's easy. IT ALREADY EXISTS and is part of Elm. It's just a private API. But it totally does work. It's how the native wrappers are written. Ports use publisher/subscriber. If I want to, let say, wrap moment.js, which is just a bunch of synchronous functions, how would I do it? Dispatch side effects to "compute dates" and listen to the "response" in my update method? That would be silly. The port system works beautifully to interface with the outside world. It is very poor to bring the outside world in.
- bbcbasic 10y ago> How to make it better? that's easy. IT ALREADY EXISTS and is part of Elm. It's just a private API. But it totally does work. It's how the native wrappers are written. You mean like this: https://github.com/mcapodici/capodicis-notes/blob/master/elmsrc/Native/ExtensionStorage.js https://github.com/mcapodici/capodicis-notes/blob/master/elm... That is an example where I connected chrome extension storage functionality using native wrappers. This is the Elm wrapping for it: https://github.com/mcapodici/capodicis-notes/blob/master/elmsrc/ExtensionStorage.elm https://github.com/mcapodici/capodicis-notes/blob/master/elm...
- efficax 10y agoThe Native interop changed with core >= 4.0, so that relatively straightforward way of accessing native js no longer works, and the new Native is (deliberately, I believe) undocumented.
- bbcbasic 10y agoThat's Elm's weakness then. The goalposts keep moving.
- knewter 10y agoIn a pre-1.0 language, this should be entirely expected. It's bleeding edge a bit, but I've yet to find someone who used it to build something non-trivial and wasn't sold on it. There's definitely some survivor bias there, obviously. For the record, I looked at Elm over 2 years ago and completely dismissed it. I regret that strongly now as I am extreeeeemely happy developing with it and I can build stuff in far shorter timelines with zero runtime errors than I could in react even (which was a high-watermark before Elm for me in that respect)