rescript-lang / bucklescript.github.io

BuckleScript's documentation site
https://bucklescript.github.io
55 stars 87 forks source link

object.md out of date, maybe? #150

Closed vphantom closed 5 years ago

vphantom commented 5 years ago

Hello! I'm not sure if this is something I'm doing wrong, or if docs/object.md is out of date so I didn't dare suggest a PR, but the document shows an example and mentions: "Js.Dict is simply backed by a JS object. The entire API uses nothing but ordinary BuckleScript externals, so the whole API disappears after compilation. There should be no mention of Dict anywhere in the generated output."

However, with BS 6.x I cannot reproduce the simplicity of the example, and instead get from:

external testobj : string Js.Dict.t = "testobj" [@@bs.val]
(* later: *)
  ( match Js.Dict.get testobj "test" with
  | None -> Js.log "not found"
  | Some _ -> Js.log "found"
  )

…to:

var match = Js_dict.get(testobj, "test");  // <-- not testobj["test"]
if (match !== undefined) {
  console.log("found");
  return /* () */0;
} else {
  console.log("not foud");
  return /* () */0;
}
bobzhang commented 5 years ago

@vphantom yes, there are some corner cases in the old form(since you can put undefined in object too), maybe we should remove such statement, would you file a PR?