From e78c236a8d28784370f192a3410693c456dc628f Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 2 Dec 2021 21:36:42 +0100 Subject: Added comment in editor event loop --- editor/actions/editor_actions.mli | 3 ++- editor/editor.ml | 11 +++++++++++ editor/prosemirror/prosemirror.ml | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/editor/actions/editor_actions.mli b/editor/actions/editor_actions.mli index a0a3c3b..65c10f3 100755 --- a/editor/actions/editor_actions.mli +++ b/editor/actions/editor_actions.mli @@ -8,7 +8,8 @@ val build val get_event : t -> State.event Note.event -(** Finalize the creation, register the handler to state update, and return the dom elements. +(** Finalize the creation, register the handler to state update, and return the + dom elements. Raise an error if already completed. *) val complete diff --git a/editor/editor.ml b/editor/editor.ml index 5883ec8..2441265 100755 --- a/editor/editor.ml +++ b/editor/editor.ml @@ -131,8 +131,14 @@ let app id content = let init_state = State.init pm view last_backup page_id in + (* Initialize the buttons actions and get the associated events. + At this point, the HTML element is not yet created, and cannot be + inserted in the document. + *) let side_elements = Editor_actions.build pm in let btn_events = Editor_actions.get_event side_elements in + + (* Create the main event loop with all the collected events *) let app_state = State.run ~eq:State.eq init_state @@ -146,7 +152,12 @@ let app id content = ; btn_events ]) in + (* Get the html element associated with the buttons, and add it in the + page. + The state event is already created, and can be given in the html + creation in order to update the elements when the state change. + *) let childs = Editor_actions.complete side_elements app_state in let () = El.append_children sidebar childs in let _ = Note.(Logr.hold (S.log app_state (fun _ -> ()))) in diff --git a/editor/prosemirror/prosemirror.ml b/editor/prosemirror/prosemirror.ml index e413084..c44d090 100755 --- a/editor/prosemirror/prosemirror.ml +++ b/editor/prosemirror/prosemirror.ml @@ -18,6 +18,7 @@ module Model = struct module Fragment = struct + (** https://prosemirror.net/docs/ref/#model.Fragment^fromArray *) let from_array : t -> node Js.t Js.js_array Js.t -> fragment Js.t = fun t elements -> -- cgit v1.2.3