-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathDocson.res
37 lines (28 loc) · 1.09 KB
/
Docson.res
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
type t
@module("docson") external docson: t = "default"
@set external setTemplateBaseUrl: (t, string) => unit = "templateBaseUrl"
@module("docson") @scope("default")
external doc: (string, JSON.t, option<string>, string) => unit = "doc"
@react.component
let make = (~tag) => {
let element = React.useRef(Nullable.null)
React.useEffect(() => {
let segment = `https://raw.githubusercontent.com/rescript-lang/rescript/${tag}/docs/docson/build-schema.json`
// The api for docson is a little bit funky, so you need to check out the source to understand what it's doing
// See: https://github.com/lbovet/docson/blob/master/src/index.js
let _ =
Webapi.Fetch.fetch(segment)
->Promise.then(Webapi.Fetch.Response.json)
->Promise.then(schema => {
let _ = switch element.current->Nullable.toOption {
| Some(_el) =>
setTemplateBaseUrl(docson, "/static/docson")
doc("docson-root", schema, None, segment)
| None => ()
}
Promise.resolve()
})
None
}, [])
<div ref={ReactDOM.Ref.domRef(element)} id="docson-root" />
}