Skip to content

Commit

Permalink
Use externals for bindings, not the global object
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Oct 22, 2024
1 parent 9fa6ec2 commit 3301993
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 24 deletions.
2 changes: 1 addition & 1 deletion vendor/brr_lwd_ui/bindings/quill/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name quill)
(js_of_ocaml
(javascript_files js/quill.js))
(javascript_files quill.js))
(public_name brr-lwd-ui.bindings.quill)
(libraries brr))
7 changes: 5 additions & 2 deletions vendor/brr_lwd_ui/bindings/quill/global.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
let quill = Jv.get Jv.global "Quill"
let quill_cursors = Jv.get Jv.global "QuillCursors"
external get_quill : unit -> Jv.t = "get_quill"
external get_quill_cursors : unit -> Jv.t = "get_quill_cursors"

let quill = get_quill ()
let quill_cursors = get_quill_cursors ()
2 changes: 2 additions & 0 deletions vendor/brr_lwd_ui/bindings/quill/global.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val quill : Jv.t
val quill_cursors : Jv.t
6 changes: 0 additions & 6 deletions vendor/brr_lwd_ui/bindings/quill/js/quill.js

This file was deleted.

13 changes: 13 additions & 0 deletions vendor/brr_lwd_ui/bindings/quill/quill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require('quill/dist/quill.core.css')
require('quill/dist/quill.bubble.css')
require('quill/dist/quill.snow.css')

//Provides: get_quill
function get_quill(){
return require('quill').default
}

//Provides: get_quill_cursors
function get_quill_cursors(){
return require('quill-cursors')
}
2 changes: 1 addition & 1 deletion vendor/brr_lwd_ui/bindings/y-quill/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name y_quill)
(js_of_ocaml
(javascript_files js/y-quill.js))
(javascript_files y-quill.js))
(public_name brr-lwd-ui.bindings.y-quill)
(libraries brr brr-lwd-ui.bindings.quill yjs))
1 change: 0 additions & 1 deletion vendor/brr_lwd_ui/bindings/y-quill/global.ml

This file was deleted.

1 change: 0 additions & 1 deletion vendor/brr_lwd_ui/bindings/y-quill/js/y-quill.js

This file was deleted.

4 changes: 4 additions & 0 deletions vendor/brr_lwd_ui/bindings/y-quill/y-quill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//Provides: get_y_quill
function get_y_quill() {
return require('y-quill')
}
4 changes: 3 additions & 1 deletion vendor/brr_lwd_ui/bindings/y-quill/y_quill.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type t = Jv.t

let quill_binding = Global.quill_binding
external get_y_quill : unit -> Jv.t = "get_y_quill"

let quill_binding = Jv.get (get_y_quill ()) "QuillBinding"

let make ?awareness text editor =
let awareness = Option.map Yjs.Awareness.to_jv awareness in
Expand Down
3 changes: 2 additions & 1 deletion vendor/brr_lwd_ui/bindings/yjs/awareness.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type t = Jv.t

external get_awareness_protocol : unit -> Jv.t = "get_awareness_protocol"
external to_jv : t -> Jv.t = "%identity"

let class_awarness = Jv.get Global.awareness_protocol "Awareness"
let class_awarness = Jv.get (get_awareness_protocol ()) "Awareness"
let make doc = Jv.new' class_awarness [| Doc.Doc.to_jv doc |]
2 changes: 1 addition & 1 deletion vendor/brr_lwd_ui/bindings/yjs/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name yjs)
(js_of_ocaml
(javascript_files js/yjs.js))
(javascript_files yjs.js))
(public_name brr-lwd-ui.bindings.yjs)
(libraries brr))
5 changes: 3 additions & 2 deletions vendor/brr_lwd_ui/bindings/yjs/global.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let yjs = Jv.get Jv.global "yjs"
let awareness_protocol = Jv.get Jv.global "awarenessProtocol"
external get_yjs : unit -> Jv.t = "get_yjs"

let yjs = get_yjs ()
1 change: 1 addition & 0 deletions vendor/brr_lwd_ui/bindings/yjs/global.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val yjs : Jv.t
4 changes: 3 additions & 1 deletion vendor/brr_lwd_ui/bindings/yjs/indexeddb_persistence.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type t = Jv.t

let indexeddb_persistence = Jv.get Jv.global "IndexeddbPersistence"
external get_indexeddb_persistence : unit -> Jv.t = "get_indexeddb_persistence"

let indexeddb_persistence = get_indexeddb_persistence ()

let make ~doc_name doc =
Jv.new' indexeddb_persistence [| Jv.of_string doc_name; Doc.Doc.to_jv doc |]
4 changes: 0 additions & 4 deletions vendor/brr_lwd_ui/bindings/yjs/js/yjs.js

This file was deleted.

6 changes: 4 additions & 2 deletions vendor/brr_lwd_ui/bindings/yjs/webrtc_provider.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type t = Jv.t

let web_rpc_provider = Jv.get Jv.global "WebrtcProvider"
external get_web_rtc_provider : unit -> Jv.t = "get_web_rtc_provider"

let web_rtc_provider = get_web_rtc_provider ()

let _servers =
[
Expand Down Expand Up @@ -176,5 +178,5 @@ let make ~room_name ?signaling ?awareness yjs_doc =
[ signaling; peer_opts; awareness ]
|> List.filter_map Fun.id |> Array.of_list
in
Jv.new' web_rpc_provider
Jv.new' web_rtc_provider
[| Jv.of_string room_name; Doc.Doc.to_jv yjs_doc; Jv.obj options |]
21 changes: 21 additions & 0 deletions vendor/brr_lwd_ui/bindings/yjs/yjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//Provides: get_yjs
function get_yjs() {
return require('yjs')
}

//Provides: get_web_rtc_provider
function get_web_rtc_provider() {
return require('y-webrtc').WebrtcProvider
}

//Provides: get_indexeddb_persistence
function get_indexeddb_persistence() {
return require('y-indexeddb').IndexeddbPersistence
}


//Provides: get_awareness_protocol
function get_awareness_protocol() {
return require('y-protocols/awareness.js')
}

0 comments on commit 3301993

Please sign in to comment.