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
Copy file name to clipboardExpand all lines: docs/content/docs/contributing/code-generation.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Code Generation
3
3
description: Learn more about the code generation process for @rescript/webapi.
4
-
slug: "03-code-generation"
4
+
slug: "04-code-generation"
5
5
---
6
6
7
7
The original bindings were generated using a modified version of [TypeScript-DOM-lib-generator](https://github.com/microsoft/TypeScript-DOM-lib-generator).
When an interface inherits from another interface, the base interface methods can be [included](https://rescript-lang.org/syntax-lookup#include) into the inheriting interface.
40
+
All methods from [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement#instance_methods) should also be available on [HTMLButtonElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement#instance_methods).
41
+
42
+
exportconst htmlElementModule =`
43
+
open DOMAPI
44
+
45
+
// A concrete type for \`T.t\` is passed later using the \`include\` keyword.
46
+
module Impl = (T: { type t }) => {
47
+
48
+
/**
49
+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLElement/focus)
50
+
*/
51
+
@send
52
+
external focus: (T.t, ~options: focusOptions=?) => unit = "focus"
53
+
54
+
}
55
+
56
+
include Impl({ type t = htmlElement })
57
+
`;
58
+
59
+
<Code
60
+
code={htmlElementModule}
61
+
title="DOMAPI/HTMLElement.res"
62
+
lang="ReScript"
63
+
></Code>
64
+
65
+
exportconst buttonModule =`
66
+
open DOMAPI
67
+
68
+
// Include all the methods from HTMLElement
69
+
include HTMLElement.Impl({ type t = htmlButtonElement })
70
+
71
+
// Add additional methods specific to HTMLButtonElement:
72
+
73
+
/**
74
+
Returns whether a form will validate when it is submitted, without having to submit it.
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
7
-
8
-
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
9
-
10
-
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
11
-
12
-
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
13
-
14
-
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
15
-
16
-
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
17
-
18
-
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
19
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
20
-
*/
21
-
@send
22
-
externaladdEventListener: (
23
-
fontFaceSet,
24
-
~type_: eventType,
25
-
~callback: eventListener<'event>,
26
-
~options: addEventListenerOptions=?,
27
-
) =>unit="addEventListener"
28
-
29
-
/**
30
-
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
31
-
32
-
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
33
-
34
-
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
35
-
36
-
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
37
-
38
-
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
39
-
40
-
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
41
-
42
-
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
43
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
44
-
*/
45
-
@send
46
-
externaladdEventListener2: (
47
-
fontFaceSet,
48
-
~type_: eventType,
49
-
~callback: eventListener<'event>,
50
-
~options: bool=?,
51
-
) =>unit="addEventListener"
52
-
53
-
/**
54
-
Removes the event listener in target's event listener list with the same type, callback, and options.
55
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
56
-
*/
57
-
@send
58
-
externalremoveEventListener: (
59
-
fontFaceSet,
60
-
~type_: eventType,
61
-
~callback: eventListener<'event>,
62
-
~options: eventListenerOptions=?,
63
-
) =>unit="removeEventListener"
64
-
65
-
/**
66
-
Removes the event listener in target's event listener list with the same type, callback, and options.
67
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
68
-
*/
69
-
@send
70
-
externalremoveEventListener2: (
71
-
fontFaceSet,
72
-
~type_: eventType,
73
-
~callback: eventListener<'event>,
74
-
~options: bool=?,
75
-
) =>unit="removeEventListener"
76
-
77
-
/**
78
-
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
79
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
15
-
16
-
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
17
-
18
-
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
19
-
20
-
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
21
-
22
-
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
23
-
24
-
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
25
-
26
-
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
27
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
28
-
*/
29
-
@send
30
-
externaladdEventListener: (
31
-
offscreenCanvas,
32
-
~type_: eventType,
33
-
~callback: eventListener<'event>,
34
-
~options: addEventListenerOptions=?,
35
-
) =>unit="addEventListener"
36
-
37
-
/**
38
-
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
39
-
40
-
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
41
-
42
-
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
43
-
44
-
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
45
-
46
-
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
47
-
48
-
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
49
-
50
-
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
51
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
52
-
*/
53
-
@send
54
-
externaladdEventListener2: (
55
-
offscreenCanvas,
56
-
~type_: eventType,
57
-
~callback: eventListener<'event>,
58
-
~options: bool=?,
59
-
) =>unit="addEventListener"
60
-
61
-
/**
62
-
Removes the event listener in target's event listener list with the same type, callback, and options.
63
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
64
-
*/
65
-
@send
66
-
externalremoveEventListener: (
67
-
offscreenCanvas,
68
-
~type_: eventType,
69
-
~callback: eventListener<'event>,
70
-
~options: eventListenerOptions=?,
71
-
) =>unit="removeEventListener"
72
-
73
-
/**
74
-
Removes the event listener in target's event listener list with the same type, callback, and options.
75
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
76
-
*/
77
-
@send
78
-
externalremoveEventListener2: (
79
-
offscreenCanvas,
80
-
~type_: eventType,
81
-
~callback: eventListener<'event>,
82
-
~options: bool=?,
83
-
) =>unit="removeEventListener"
84
-
85
-
/**
86
-
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
87
-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
Returns an object that exposes an API for drawing on the OffscreenCanvas object. contextId specifies the desired API: "2d", "bitmaprenderer", "webgl", or "webgl2". options is handled by that API.
0 commit comments