Bindings are one of the most difficult parts for beginners, recently I made some clean up on how externals are handled and think it could be significantly simplified. This comes with two enhancement, the first one is a minor enhancement, the second one is a major one. This proposal should be backwards compatible
- First enhancement , no redundant attributes like
@val
Previously, for a simple binding, user has to add an attribute, this does not need any more
@val
external getElementById : string => dom = "getElementById"
let h = getElementById("x")
Without @val
, this should just work:
external getElementById : string => dom = "getElementById"
let h = getElementById("x")
- Second enhancement: we can accept more kinds of payload in the string literals:
external add : (float,float) => float = "(a,b)=> a+ b"
User can write any valid JS function inside the string literal, since it is plain JavaScript, so in theory, user can build any bindings without a second thought. Thanks to ES6 syntax, this could be very short. We will do as much check as we can, optimisations can be added later