3 ms·
This looks really cool, and TIL (from their compiled JavaScript) about JS' reflect: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj
by mcintyre1994 5y ago
This looks really cool, and TIL (from their compiled JavaScript) about JS' reflect: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I guess that's the magic behind most JS data binding libraries?
I do find the syntax on the Gleam side a little bit odd:
external fn query_selector(String) -> Element =
"" "document.querySelector"
Becomes:
function query_selector(arg0) {
return document.querySelector(arg0)
}
I'm not sure what the empty string first argument is doing in this case.
- tynanbe 5y agoIt references module, which can be seen when creating an `external fn` for Erlang or Elixir, for example. https://gleam.run/book/tour/external-functions.html https://gleam.run/book/tour/external-functions.html
- lpil 5y agoThe first specifies the module that the the function is contain by. In this case we are using global functions so there is no module, but if we specified and module the function would be imported from it.
- jitl 5y ago> I guess that's the magic behind most JS data binding libraries? Most of the functions on Reflect can be done using built-in language features, I haven’t seen much use of it in libraries. For reactive, magic data binding see Proxy, which allows a callback on object property access for arbitrary objects. Proxy is the magic behind Mobx for instance. Reflect fits in well because it can be used as the “default” or fallback implementation for Proxy methods. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...