Proposal: directly calling JS functions

I had already implemented a similar API trough Elm’s ports named SimpleJs and discussed here

I was also thinking of such an API for new, but so far I just call JS-functions, and can not create objects without using helper functions, like in here for a JS Date. This works for me.

I do not expect, that JS-objects are equal to Elms Json.Decode.Value, because the do not include the functions / object methods, or at least this is an implementation detail, which can change with every new version, so I have not tried it. I do not expecting the compiler, when copying a variable of Json.Decode.Value type to copy also the included functions. So a special new type additional to Value is necessary, let call it JsObject. Without extending the compiler to support JsObject, JsObject can be a reference, like a Elm Int to a real JS-object. So the parameters of the function need to change from List Value to List JsObject. But then you need the encoders creating a JsObject, which need call JS trough ports again. For me, it seems to difficult to implement using Elm ports, and programming with (references to) objects this way in Elm would not help me to create clean code.

1 Like