diff --git a/src/dom-nodes/DOMTree.res b/src/dom-nodes/DOMTree.res index 9611fd51..460bd4df 100644 --- a/src/dom-nodes/DOMTree.res +++ b/src/dom-nodes/DOMTree.res @@ -8,15 +8,14 @@ type slotAssignmentMode = | @as("manual") Manual | @as("named") Named -type customStateSet = {} +type customStateSet = private {} /** Node is an interface from which a number of WebApiDOM API object types inherit. It allows those types to be treated similarly; for example, inheriting the same set of methods, or being tested in the same way. [See Node on MDN](https://developer.mozilla.org/docs/Web/API/Node) -TODO: mark as private once mutating fields of private records is allowed */ @editor.completeFrom(Node) -type rec node = { +type rec node = private { ...DOM.eventTarget, /** Returns the type of node. @@ -91,9 +90,8 @@ type rec node = { /** Element is the most general base class from which all objects in a Document inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from Element. [See Element on MDN](https://developer.mozilla.org/docs/Web/API/Element) -TODO: mark as private once mutating fields of private records is allowed */ -@editor.completeFrom(Element) and element = { +@editor.completeFrom(Element) and element = private { // Base properties from Node /** Returns the type of node. @@ -463,7 +461,7 @@ A minimal document object that has no parent. It is used as a lightweight versio [See DocumentFragment on MDN](https://developer.mozilla.org/docs/Web/API/DocumentFragment) TODO: mark as private once mutating fields of private records is allowed */ -@editor.completeFrom(DocumentFragment) and documentFragment = { +@editor.completeFrom(DocumentFragment) and documentFragment = private { // Base properties from Node /** Returns the type of node. @@ -560,7 +558,7 @@ TODO: mark as private once mutating fields of private records is allowed [See ShadowRoot on MDN](https://developer.mozilla.org/docs/Web/API/ShadowRoot) TODO: mark as private once mutating fields of private records is allowed */ -@editor.completeFrom(ShadowRoot) and shadowRoot = { +@editor.completeFrom(ShadowRoot) and shadowRoot = private { // Base properties from DocumentFragment // End base properties from DocumentFragment @@ -703,7 +701,7 @@ Any HTML element. Some elements directly implement this interface, while others [See HTMLElement on MDN](https://developer.mozilla.org/docs/Web/API/HTMLElement) TODO: mark as private once mutating fields of private records is allowed */ -@editor.completeFrom(HTMLElement) and htmlElement = { +@editor.completeFrom(HTMLElement) and htmlElement = private { // Base properties from Element /** Returns the namespace. @@ -996,7 +994,7 @@ A
element in the WebApiDOM; it allows access to and in some cases modific [See HTMLFormElement on MDN](https://developer.mozilla.org/docs/Web/API/HTMLFormElement) TODO: mark as private once mutating fields of private records is allowed */ -@editor.completeFrom(HTMLFormElement) and htmlFormElement = { +@editor.completeFrom(HTMLFormElement) and htmlFormElement = private { // Base properties from HTMLElement /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLElement/title) @@ -1298,12 +1296,12 @@ TODO: mark as private once mutating fields of private records is allowed } @editor.completeFrom(HTMLFormControlsCollection) -and htmlFormControlsCollection = { +and htmlFormControlsCollection = private { length: int, } @editor.completeFrom(HTMLSlotElement) -and htmlSlotElement = { +and htmlSlotElement = private { // Base properties from Element /** Returns the namespace. @@ -1596,7 +1594,7 @@ and htmlSlotElement = { } @editor.completeFrom(ElementInternals) -and elementInternals = { +and elementInternals = private { shadowRoot: Null.t, form: Null.t, willValidate: bool, diff --git a/src/dom-nodes/Node.res b/src/dom-nodes/Node.res index 6d35787a..59206404 100644 --- a/src/dom-nodes/Node.res +++ b/src/dom-nodes/Node.res @@ -11,6 +11,12 @@ module Impl = ( external asNode: T.t => DOMTree.node = "%identity" + @set + external setNodeValue: (T.t, Null.t) => unit = "nodeValue" + + @set + external setTextContent: (T.t, Null.t) => unit = "textContent" + type getRootNodeOptions = {mutable composed?: bool} /** diff --git a/src/file/FileTypes.res b/src/file/FileTypes.res index d50b7cd1..48165b4e 100644 --- a/src/file/FileTypes.res +++ b/src/file/FileTypes.res @@ -37,7 +37,7 @@ This Streams API interface represents a readable stream of byte data. The WebApi [See ReadableStream on MDN](https://developer.mozilla.org/docs/Web/API/ReadableStream) */ @editor.completeFrom(ReadableStream) -type readableStream<'r> = { +type readableStream<'r> = private { /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/ReadableStream/locked) */ @@ -49,7 +49,7 @@ This Streams API interface provides a standard abstraction for writing streamin [See WritableStream on MDN](https://developer.mozilla.org/docs/Web/API/WritableStream) */ @editor.completeFrom(WritableStream) -type writableStream<'w> = { +type writableStream<'w> = private { /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/WritableStream/locked) */ diff --git a/src/file/WritableStream.res b/src/file/WritableStream.res index d2cabeb4..bc64f321 100644 --- a/src/file/WritableStream.res +++ b/src/file/WritableStream.res @@ -1,5 +1,5 @@ @editor.completeFrom(WritableStream) -type t<'w> = FileTypes.writableStream<'w> = {...FileTypes.writableStream<'w>} +type t<'w> = FileTypes.writableStream<'w> = private {...FileTypes.writableStream<'w>} /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/WritableStream) diff --git a/src/html/HTMLSlotElement.res b/src/html/HTMLSlotElement.res index 7e549fe3..5fcc0a63 100644 --- a/src/html/HTMLSlotElement.res +++ b/src/html/HTMLSlotElement.res @@ -7,6 +7,9 @@ type t = DOMTree.htmlSlotElement = private { include HTMLElement.Impl({type t = t}) +@set +external setName: (t, string) => unit = "name" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLSlotElement/assignedNodes) */ diff --git a/src/messaging/WebSocketsTypes.res b/src/messaging/WebSocketsTypes.res index d17d22bb..ca4061e5 100644 --- a/src/messaging/WebSocketsTypes.res +++ b/src/messaging/WebSocketsTypes.res @@ -9,10 +9,9 @@ type messageEventSource = unknown /** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. [See WebSocket on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket) -TODO: mark as private once mutating fields of private records is allowed */ @editor.completeFrom(WebSocket) -type webSocket = { +type webSocket = private { ...DOM.eventTarget, /** Returns the WebApiURL that was used to establish the WebSocket connection. @@ -47,7 +46,7 @@ If the WebSocket connection is closed, this attribute's value will only increase Can be set, to change how binary data is returned. The default is "blob". [Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType) */ - mutable binaryType: binaryType, + binaryType: binaryType, } /** diff --git a/src/storage/IDBIndex.res b/src/storage/IDBIndex.res index e1e7d823..6195f169 100644 --- a/src/storage/IDBIndex.res +++ b/src/storage/IDBIndex.res @@ -1,4 +1,4 @@ -type t = IndexedDbTypes.idbIndex = {...IndexedDbTypes.idbIndex} +type t = IndexedDbTypes.idbIndex = private {...IndexedDbTypes.idbIndex} /** Retrieves the value of the first record matching the given key or key range in query. diff --git a/src/storage/IDBObjectStore.res b/src/storage/IDBObjectStore.res index cf30c2cc..e72cecca 100644 --- a/src/storage/IDBObjectStore.res +++ b/src/storage/IDBObjectStore.res @@ -1,4 +1,4 @@ -type t = IndexedDbTypes.idbObjectStore = {...IndexedDbTypes.idbObjectStore} +type t = IndexedDbTypes.idbObjectStore = private {...IndexedDbTypes.idbObjectStore} /** Adds or updates a record in store with the given value and key. diff --git a/src/storage/IndexedDbTypes.res b/src/storage/IndexedDbTypes.res index cd7315dd..9a6f2680 100644 --- a/src/storage/IndexedDbTypes.res +++ b/src/storage/IndexedDbTypes.res @@ -129,15 +129,15 @@ type idbOpenDBRequest = { /** This example shows a variety of different uses of object stores, from updating the data structure with IDBObjectStore.createIndex inside an onupgradeneeded function, to adding a new item to our object store with IDBObjectStore.add. For a full working example, see our To-do Notifications app (view example live.) [See IDBObjectStore on MDN](https://developer.mozilla.org/docs/Web/API/IDBObjectStore) -TODO: mark as private once mutating fields of private records is allowed */ @editor.completeFrom(IDBObjectStore) -type idbObjectStore = { +type idbObjectStore = private { /** Returns the name of the store. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/name) */ @throws(JsExn) + @set mutable name: string, /** Returns the key path of the store, or null if none. @@ -164,15 +164,15 @@ type idbObjectStore = { /** IDBIndex interface of the WebApiIndexedDB API provides asynchronous access to an index in a database. An index is a kind of object store for looking up records in another object store, called the referenced object store. You use this interface to retrieve data. [See IDBIndex on MDN](https://developer.mozilla.org/docs/Web/API/IDBIndex) -TODO: mark as private once mutating fields of private records is allowed */ @editor.completeFrom(IDBIndex) -type idbIndex = { +type idbIndex = private { /** Returns the name of the index. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/IDBIndex/name) */ @throws(JsExn) + @set mutable name: string, /** Returns the IDBObjectStore the index belongs to. diff --git a/tests/DOMAPI/AddEventListener__test.res b/tests/DOMAPI/AddEventListener__test.res index 7daa3b0b..12949efe 100644 --- a/tests/DOMAPI/AddEventListener__test.res +++ b/tests/DOMAPI/AddEventListener__test.res @@ -1,16 +1,18 @@ let button = DomGlobal.document->Document.querySelector("button")->Null.toOption let h2 = DomGlobal.document->Document.querySelector("h2")->Null.toOption +module AnyElement = Element.Impl({type t = Element.t}) + switch (button, h2) { | (Some(button), Some(h2)) => button->Element.addEventListener(EventType.Click, (e: UiEventsTypes.mouseEvent) => { Console.log(`Button clicked, ${Int.toString(e.button)}`) switch h2.textContent { - | Null => h2.textContent = Value("1") + | Null => h2->AnyElement.setTextContent(Value("1")) | Value(text) => switch Int.fromString(text) { - | None => h2.textContent = Value("1") - | Some(number) => h2.textContent = Value(Int.toString(number + 1)) + | None => h2->AnyElement.setTextContent(Value("1")) + | Some(number) => h2->AnyElement.setTextContent(Value(Int.toString(number + 1))) } } }) diff --git a/tests/DOMAPI/HTMLSlotElement__test.res b/tests/DOMAPI/HTMLSlotElement__test.res index 6e0acc3b..527fb4ad 100644 --- a/tests/DOMAPI/HTMLSlotElement__test.res +++ b/tests/DOMAPI/HTMLSlotElement__test.res @@ -1,7 +1,7 @@ let assignedNodesForElement = (element: DOMTree.element) => switch element.assignedSlot { | Value(slot) => - slot.name = "content" + slot->HTMLSlotElement.setName("content") slot->HTMLSlotElement.assignedNodes | Null => [] } @@ -9,7 +9,7 @@ let assignedNodesForElement = (element: DOMTree.element) => let assignedNodesForText = (text: Text.t) => switch text.assignedSlot { | Value(slot) => - slot.name = "content" + slot->HTMLSlotElement.setName("content") slot->HTMLSlotElement.assignedNodes | Null => [] } diff --git a/tests/FileAPI/ReadableStream__test.res b/tests/FileAPI/ReadableStream__test.res index 8207d12d..fef5dba0 100644 --- a/tests/FileAPI/ReadableStream__test.res +++ b/tests/FileAPI/ReadableStream__test.res @@ -3,9 +3,8 @@ let strategy: FileTypes.queuingStrategy = Obj.magic() let _make: ReadableStream.t = ReadableStream.make() -let _fromUnderlyingSource = ReadableStream.fromUnderlyingSource(underlyingSource) +let _fromUnderlyingSource: ReadableStream.t = + ReadableStream.fromUnderlyingSource(underlyingSource) -let _fromUnderlyingSourceWithStrategy = ReadableStream.fromUnderlyingSource( - underlyingSource, - ~strategy, -) +let _fromUnderlyingSourceWithStrategy: ReadableStream.t = + ReadableStream.fromUnderlyingSource(underlyingSource, ~strategy)