2626// Imports
2727// -------
2828//
29- // ### JavaScript/TypeScript
30- //
31- // #### Third-party
29+ // ### Third-party
3230import ReconnectingWebSocket from "./third-party/ReconnectingWebSocket.cjs" ;
3331import { show_toast as show_toast_core } from "./show_toast.mjs" ;
3432
35- // #### Local
33+ // ### Local
3634import { assert } from "./assert.mjs" ;
3735import {
3836 CodeChatForWeb ,
@@ -91,7 +89,7 @@ class WebSocketComm {
9189
9290 // A promise to serialize calls to and from the Client. This is important: a
9391 // `CurrentFile` requires the Client to save, then switch to a new web page.
94- // If an `Update` comes in, it should be applied after the `CurrentFile` is
92+ // If an `Update` comes in, it should be applied after the `CurrentFile` has
9593 // finished executing.
9694 promise = Promise . resolve ( ) ;
9795
@@ -123,7 +121,7 @@ class WebSocketComm {
123121 // Handle websocket messages.
124122 this . ws . onmessage = ( event : MessageEvent ) => {
125123 // Parse the received message, which must be a single element of a
126- // dictionary representing a `JointMessage `.
124+ // dictionary representing an `EditorMessage `.
127125 const joint_message = JSON . parse ( event . data ) as EditorMessage ;
128126 const { id, message } = joint_message ;
129127 console_log (
@@ -160,10 +158,11 @@ class WebSocketComm {
160158 if ( contents !== undefined ) {
161159 // I'd prefer to use a system-maintained value to
162160 // determine the ready state of the iframe, such as
163- // `readyState`. However, this value only applies to
164- // the initial load of the iframe; it doesn't change
165- // when the iframe's `src` attribute is changed. So,
166- // we have to track this manually instead.
161+ // [readyState](https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState).
162+ // However, this value only applies to the initial
163+ // load of the iframe; it doesn't change when the
164+ // iframe's `src` attribute is changed. So, we have
165+ // to track this manually instead.
167166 if ( ! this . is_loading ) {
168167 // Wait until after the DOM is ready, since we
169168 // rely on content set in
@@ -297,6 +296,8 @@ class WebSocketComm {
297296 callback : ( ) => void = ( ) => 0 ,
298297 ) => {
299298 const id = this . ws_id ;
299+ // The Client gets every third ID -- the IDE gets another third, while
300+ // the Server gets the final third.
300301 this . ws_id += 3 ;
301302 // Add in the current filename to the message, if it's an `Update`.
302303 if ( typeof message == "object" && "Update" in message ) {
@@ -321,6 +322,9 @@ class WebSocketComm {
321322
322323 // This is called by the Client when the user navigates to another webpage.
323324 current_file = ( url : URL ) => {
325+ // TODO: should we delay execution of user navigation until all previous
326+ // actions have finished, or ignore them and immediately perform the
327+ // user navigation?
324328 this . promise = this . promise . finally ( ( ) => {
325329 if ( url . host === window . location . host ) {
326330 // If this points to the Server, then tell the IDE to load a new
0 commit comments