This is a random idea that might not be useful but I will give it anyway.
It might be useful to be able to conveniently call a JS function from Elm. Ports kinda do this, but it does not give Elm a lot of control over how the function gets called. This might be preventing some Elm package from being simple to set up, such as this one.
Defining this function in a core library seems like an obvious solution (first argument is function name, second is the argument list, and third makes a msg from the return value):
callFunction : String -> List Value -> ( Value -> msg ) -> Cmd msg
But I think the first argument here is a problem. It causes a security risk since any Elm package could call any function without you providing that function. And it’s better to explicitly control how a JS function becomes accessible from the Elm application.
A better solution would be to allow Json
Value to represent a JS function since it is a first class value in JS. The only way for this function to enter the Elm application would be through flags (the best way) or through a port. Then you can use these things which would be defined in some core elm/* package:
callFunction : Value -> List Value -> (Result FuncError Value -> msg) -> Cmd msg type FuncError = Exception Value
There also needs to be a way to construct a
new object when given a constructor