You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let set_config (x : config Js.t) = Js.Unsafe.global##.myAppConfig := x
18
18
>>
19
19
20
-
You can also use {{{Js.Unsafe.js_expr}}} for any JavaScript expression:
20
+
You can also use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.js_expr>> for any JavaScript expression:
21
21
<<code language="ocaml"|
22
22
let v = (Js.Unsafe.js_expr "window")##.document
23
23
>>
24
24
25
-
Be careful: both {{{Js.Unsafe.global}}} and {{{Js.Unsafe.js_expr}}} are untyped.
25
+
Be careful: both <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.global>> and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.js_expr>> are untyped.
26
26
Verify the library documentation before writing type annotations.
27
27
28
28
=== Untyped property access
29
29
30
30
When a property is missing from the OCaml interface (e.g., dynamically added
31
-
by a library), use {{{Js.Unsafe.coerce}}} for untyped access:
31
+
by a library), use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.coerce>> for untyped access:
32
32
33
33
<<code language="ocaml"|
34
34
(* Read a property *)
@@ -81,8 +81,8 @@ end
81
81
OCaml method names are transformed to JavaScript names using underscore
82
82
conventions. When accessing a field of an object, the name given in OCaml
83
83
is transformed by:
84
-
1. Removing a leading underscore (if present)
85
-
2. Removing all characters starting from the last underscore
84
+
# Removing a leading underscore (if present)
85
+
# Removing all characters starting from the last underscore
86
86
87
87
This enables:
88
88
- **Capitalized names**: Use {{{_Foo}}} to refer to JavaScript's {{{Foo}}}
@@ -155,8 +155,8 @@ these functions to convert between them.
155
155
156
156
=== Strings
157
157
158
-
OCaml strings and JavaScript strings have different encodings. Use {{{Js.string}}}
159
-
and {{{Js.to_string}}} for UTF-8 encoded OCaml strings:
158
+
OCaml strings and JavaScript strings have different encodings. Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.string>>
159
+
and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.to_string>> for UTF-8 encoded OCaml strings:
For binary data (bytes 0-255), use {{{Js.bytestring}}} and {{{Js.to_bytestring}}}:
169
+
For binary data (bytes 0-255), use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.bytestring>> and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.to_bytestring>>:
170
170
171
171
<<code language="ocaml"|
172
172
let js_bytes = Js.bytestring "\x00\x01\x02"
@@ -175,7 +175,7 @@ let ocaml_bytes = Js.to_bytestring js_bytes
175
175
176
176
=== Booleans
177
177
178
-
JavaScript booleans are not OCaml booleans. Use {{{Js.bool}}} and {{{Js.to_bool}}}:
178
+
JavaScript booleans are not OCaml booleans. Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.bool>> and <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.to_bool>>:
179
179
180
180
<<code language="ocaml"|
181
181
let js_true : bool Js.t = Js._true (* or Js.bool true *)
Use {{{Js.Unsafe.fun_call}}} for functions where {{{this}}} doesn't matter:
303
+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.fun_call>> for functions where {{{this}}} doesn't matter:
304
304
305
305
<<code language="ocaml"|
306
306
(* Equivalent to: decodeURI(s) *)
@@ -318,7 +318,7 @@ let parseInt (s : Js.js_string Js.t) : int =
318
318
319
319
=== Methods with {{{meth_call}}}
320
320
321
-
Use {{{Js.Unsafe.meth_call}}} to call a method on an object ({{{this}}} is
321
+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.meth_call>> to call a method on an object ({{{this}}} is
322
322
bound to the object):
323
323
324
324
<<code language="ocaml"|
@@ -330,7 +330,7 @@ let slice arr start stop =
330
330
331
331
=== Functions with explicit {{{this}}} binding
332
332
333
-
Use {{{Js.Unsafe.call}}} when you need to explicitly set {{{this}}}:
333
+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.call>> when you need to explicitly set {{{this}}}:
334
334
335
335
<<code language="ocaml"|
336
336
(* Equivalent to: func.call(thisArg, arg1, arg2) *)
@@ -346,9 +346,9 @@ API for more details.
346
346
When JavaScript code needs to call back into OCaml (e.g., event handlers,
347
347
callbacks for async operations), you must wrap OCaml functions appropriately.
348
348
349
-
=== Basic callbacks with {{{Js.wrap_callback}}}
349
+
=== Basic callbacks with <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_callback>>
350
350
351
-
Use {{{Js.wrap_callback}}} to wrap an OCaml function for JavaScript:
351
+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_callback>> to wrap an OCaml function for JavaScript:
352
352
353
353
<<code language="ocaml"|
354
354
(* setTimeout example *)
@@ -360,13 +360,13 @@ let set_timeout f ms =
360
360
let () = set_timeout (fun () -> print_endline "Hello!") 1000.
361
361
>>
362
362
363
-
{{{Js.wrap_callback}}} handles partial application correctly: if JavaScript
363
+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_callback>> handles partial application correctly: if JavaScript
364
364
calls the function with fewer arguments than expected, the result is a
365
365
partially applied function.
366
366
367
367
=== Callbacks with {{{this}}} binding
368
368
369
-
Use {{{Js.wrap_meth_callback}}} when the callback needs access to {{{this}}}:
369
+
Use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.wrap_meth_callback>> when the callback needs access to {{{this}}}:
370
370
371
371
<<code language="ocaml"|
372
372
(* The first parameter receives the 'this' value *)
@@ -379,7 +379,7 @@ let callback = Js.wrap_meth_callback (fun this event ->
379
379
=== Strict arity callbacks
380
380
381
381
For performance-critical code, or when you don't need partial application
382
-
support, use {{{Js.Unsafe.callback}}} or {{{Js.Unsafe.callback_with_arity}}}:
382
+
support, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.callback>> or <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.callback_with_arity>>:
383
383
384
384
<<code language="ocaml"|
385
385
(* Strict callback - missing args become undefined, extra args are lost *)
@@ -391,9 +391,9 @@ let arity_cb = Js.Unsafe.callback_with_arity 2 (fun x y -> x + y)
391
391
392
392
=== DOM event handlers
393
393
394
-
For DOM events, use {{{Dom.handler}}} or {{{Dom_html.handler}}} which
394
+
For DOM events, use <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Dom.handler>> or <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Dom_html.handler>> which
395
395
automatically wraps the function and handles the return value (returning
396
-
{{{Js._false}}} prevents the default action):
396
+
<<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js._false>> prevents the default action):
Copy file name to clipboardExpand all lines: doc/dev/manual/build-toplevel.wiki
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
= Building a toplevel
2
2
3
-
First, initialize the toplevel using {{{Js_of_ocaml_toplevel.JsooTop.initialize}}}.
3
+
First, initialize the toplevel using <<a_api subproject="js_of_ocaml-toplevel"|val Js_of_ocaml_toplevel.JsooTop.initialize>>.
4
4
5
5
Then, build your bytecode program with debug enabled ({{{-g}}}) and linkall ({{{-linkall}}}). Link in all the libraries you want accessible in the final toplevel.
Copy file name to clipboardExpand all lines: doc/dev/manual/contribute.wiki
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,20 @@
4
4
5
5
If you encounter a problem when using js_of_ocaml or if you have any questions, please open a [[https://github.com/ocsigen/js_of_ocaml/issues/|GitHub issue]].
6
6
7
-
1. Check first if your issue has already been [[https://github.com/ocsigen/js_of_ocaml/issues/|reported]].
8
-
2. Include the version of ocaml and js_of_ocaml you are using ({{{ocamlc -version}}}, {{{js_of_ocaml --version}}}).
9
-
3. Describe the expected and actual behavior.
10
-
4. Do not unsubscribe from the issue until it is closed, the maintainers may ask for your feedback.
7
+
# Check first if your issue has already been [[https://github.com/ocsigen/js_of_ocaml/issues/|reported]].
8
+
# Include the version of ocaml and js_of_ocaml you are using ({{{ocamlc -version}}}, {{{js_of_ocaml --version}}}).
9
+
# Describe the expected and actual behavior.
10
+
# Do not unsubscribe from the issue until it is closed, the maintainers may ask for your feedback.
11
11
12
12
== Pull Requests
13
13
14
14
We actively welcome pull requests.
15
15
16
-
1. Prior to investing a large amount of time into significant or invasive changes, it is likely more efficient to first open an issue for discussion and planning.
17
-
2. Install all dependencies (see Install dependencies)
18
-
3. Fork the repository and create your branch from {{{master}}}.
19
-
4. If you have added code that should be tested, add tests.
20
-
5. Ensure tests still pass (see Running the tests).
16
+
# Prior to investing a large amount of time into significant or invasive changes, it is likely more efficient to first open an issue for discussion and planning.
17
+
# Install all dependencies (see Install dependencies)
18
+
# Fork the repository and create your branch from {{{master}}}.
19
+
# If you have added code that should be tested, add tests.
20
+
# Ensure tests still pass (see Running the tests).
0 commit comments