From c6265278f05aa4d3af60e420f2d4d13e4bce8ad7 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 3 Dec 2021 04:19:53 +0100 Subject: Removed the application mecanism from the state module --- editor/actions/add_page.ml | 8 +++++--- editor/actions/delete_page.ml | 7 ++++--- editor/actions/dune | 1 + editor/actions/editor_actions.ml | 11 ++++++----- editor/actions/editor_actions.mli | 2 +- editor/actions/export.ml | 7 ++++--- editor/actions/import.ml | 5 +++-- editor/actions/to_markdown.ml | 8 +++++--- editor/app/dune | 8 ++++++++ editor/app/editor_app.ml | 1 + editor/app/editor_app.mli | 14 ++++++++++++++ editor/dune | 1 + editor/editor.ml | 7 ++++--- editor/state/state.ml | 4 ---- editor/state/state.mli | 15 --------------- 15 files changed, 57 insertions(+), 42 deletions(-) create mode 100755 editor/app/dune create mode 100644 editor/app/editor_app.ml create mode 100644 editor/app/editor_app.mli (limited to 'editor') diff --git a/editor/actions/add_page.ml b/editor/actions/add_page.ml index fcad87f..5e52d43 100755 --- a/editor/actions/add_page.ml +++ b/editor/actions/add_page.ml @@ -1,4 +1,5 @@ module Js = Js_of_ocaml.Js +module App = Editor_app module M = struct @@ -16,9 +17,10 @@ module M = struct State.new_page ~title (Some page_id) state end + (** Create a new element *) let create - : unit -> State.event Note.event + : unit -> App.event Note.event = fun () -> let title = Jstr.v "Nouvelle page" in let form = Forms.Add_page.create () in @@ -34,9 +36,9 @@ let create () in Note.E.map - (fun v -> State.E + (fun v -> App.E (v - , (module M : State.Event with type t = M.t ))) + , (module M : App.Event with type t = M.t ))) (* Option.on_some trigger the event only when the pop up is validated. Closing the popup doesn't do anything. *) diff --git a/editor/actions/delete_page.ml b/editor/actions/delete_page.ml index fbd4fde..7fa609b 100755 --- a/editor/actions/delete_page.ml +++ b/editor/actions/delete_page.ml @@ -1,3 +1,4 @@ +module App = Editor_app module M = struct type t = unit @@ -14,7 +15,7 @@ module M = struct end let create - : unit -> State.event Note.event + : unit -> App.event Note.event = fun () -> let title = Jstr.v "Confirmation" and message = @@ -26,7 +27,7 @@ let create () in Note.E.map - (fun v -> State.E + (fun v -> App.E ( v - , (module M : State.Event with type t = M.t ))) + , (module M : App.Event with type t = M.t ))) (Note.E.Option.on_some ev) diff --git a/editor/actions/dune b/editor/actions/dune index 10279dd..6406828 100755 --- a/editor/actions/dune +++ b/editor/actions/dune @@ -8,6 +8,7 @@ blog forms state + editor_app ) (preprocess (pps js_of_ocaml-ppx)) ) diff --git a/editor/actions/editor_actions.ml b/editor/actions/editor_actions.ml index 518e0c7..48974c0 100755 --- a/editor/actions/editor_actions.ml +++ b/editor/actions/editor_actions.ml @@ -1,6 +1,7 @@ open StdLabels open Brr open Brr_note +module App = Editor_app module Js = Js_of_ocaml.Js @@ -9,7 +10,7 @@ module Js = Js_of_ocaml.Js let note_id_attribute = Jstr.v "data-note-id" type t = - { ev : State.event Note.event + { ev : App.event Note.event ; childs : El.t list ; ul : El.t ; mutable completed : bool @@ -108,7 +109,7 @@ let build let redirect_handler = - (module Load_page.M : State.Event with type t = Load_page.M.t ) in + (module Load_page.M : App.Event with type t = Load_page.M.t ) in let ul = El.ul [] in @@ -127,14 +128,14 @@ let build Note.E.select [ Evr.on_el Ev.click - (fun _ -> State.E (None, redirect_handler)) + (fun _ -> App.E (None, redirect_handler)) home_button ; Evr.on_el Ev.click (fun ev -> let el = Jv.Id.of_jv @@ Jv.Id.to_jv @@ Ev.target ev in let name = El.at note_id_attribute el in - State.E (name, redirect_handler)) + App.E (name, redirect_handler)) ul ] in let childs = @@ -163,7 +164,7 @@ let build ; completed = false } let get_event - : t -> State.event Note.event + : t -> App.event Note.event = fun {ev; _} -> ev (** Collect all the notes in the cache and return them into links. *) diff --git a/editor/actions/editor_actions.mli b/editor/actions/editor_actions.mli index 65c10f3..b1ac054 100755 --- a/editor/actions/editor_actions.mli +++ b/editor/actions/editor_actions.mli @@ -6,7 +6,7 @@ val build (** Get the events triggered by the actions buttons *) val get_event - : t -> State.event Note.event + : t -> Editor_app.event Note.event (** Finalize the creation, register the handler to state update, and return the dom elements. diff --git a/editor/actions/export.ml b/editor/actions/export.ml index 71e3b64..657e0da 100755 --- a/editor/actions/export.ml +++ b/editor/actions/export.ml @@ -1,4 +1,5 @@ module Js = Js_of_ocaml.Js +module App = Editor_app module M = struct @@ -31,8 +32,8 @@ end (** Create a new element *) let create - : unit -> State.event + : unit -> App.event = fun () -> - State.E + App.E ( () - , (module M : State.Event with type t = M.t )) + , (module M : App.Event with type t = M.t )) diff --git a/editor/actions/import.ml b/editor/actions/import.ml index 13ed938..c847ed3 100755 --- a/editor/actions/import.ml +++ b/editor/actions/import.ml @@ -1,4 +1,5 @@ module Js = Js_of_ocaml.Js +module App = Editor_app let uncheck_import = fun ~previous ~update -> @@ -53,7 +54,7 @@ let create () = in Note.E.map - (fun v -> State.E + (fun v -> App.E ( v - , (module M : State.Event with type t = M.t ))) + , (module M : App.Event with type t = M.t ))) (Note.E.Option.on_some ev) diff --git a/editor/actions/to_markdown.ml b/editor/actions/to_markdown.ml index c1ac774..80191f9 100755 --- a/editor/actions/to_markdown.ml +++ b/editor/actions/to_markdown.ml @@ -1,5 +1,7 @@ module Js = Js_of_ocaml.Js module PM = Prosemirror +module App = Editor_app + type buffer = Jstr.t Js.js_array Js.t type f = (buffer -> PM.Model.node Js.t -> unit) @@ -287,8 +289,8 @@ end (** Create a new element *) let create - : PM.t -> State.event + : PM.t -> App.event = fun pm -> - State.E + App.E ( pm - , (module ToMarkdown : State.Event with type t = ToMarkdown.t )) + , (module ToMarkdown : App.Event with type t = ToMarkdown.t )) diff --git a/editor/app/dune b/editor/app/dune new file mode 100755 index 0000000..f88bc75 --- /dev/null +++ b/editor/app/dune @@ -0,0 +1,8 @@ +(library + (name editor_app) + (libraries + state + application + ) + (preprocess (pps js_of_ocaml-ppx)) + ) diff --git a/editor/app/editor_app.ml b/editor/app/editor_app.ml new file mode 100644 index 0000000..2d23cfb --- /dev/null +++ b/editor/app/editor_app.ml @@ -0,0 +1 @@ +include Application.Make(struct type t = State.t end) diff --git a/editor/app/editor_app.mli b/editor/app/editor_app.mli new file mode 100644 index 0000000..3c7646b --- /dev/null +++ b/editor/app/editor_app.mli @@ -0,0 +1,14 @@ +module type Event = sig + + type t + + val update: t -> State.t -> State.t + +end + +type event = E : 'a * (module Event with type t = 'a) -> event + +(** Simple helper for the main event loop *) +val run + : ?eq:(State.t -> State.t -> bool) -> State.t -> event Note.E.t -> State.t Note.S.t + diff --git a/editor/dune b/editor/dune index 6b13228..ea79d53 100755 --- a/editor/dune +++ b/editor/dune @@ -6,6 +6,7 @@ prosemirror blog state + editor_app plugins editor_actions ) diff --git a/editor/editor.ml b/editor/editor.ml index 2441265..d272f56 100755 --- a/editor/editor.ml +++ b/editor/editor.ml @@ -113,6 +113,7 @@ module Store = struct end end +module App = Editor_app let app id content = @@ -139,15 +140,15 @@ let app id content = 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 + let app_state = App.run ~eq:State.eq init_state (Note.E.select [ Brr_note.Evr.on_els Ev.focusout (fun _ _ -> - State.E + App.E ( title - , (module Store:State.Event with type t = Store.t))) + , (module Store:App.Event with type t = Store.t))) [ editor ; title ] ; btn_events ]) in diff --git a/editor/state/state.ml b/editor/state/state.ml index 2662a48..33b796f 100755 --- a/editor/state/state.ml +++ b/editor/state/state.ml @@ -14,7 +14,6 @@ type t = ; window : Brr.El.t list ; pm : PM.t } -type state = t (** Compare two states together. @@ -108,6 +107,3 @@ let init ; window = [] ; pm } - - -include Application.Make(struct type t = state end) diff --git a/editor/state/state.mli b/editor/state/state.mli index 4376723..57b45fa 100755 --- a/editor/state/state.mli +++ b/editor/state/state.mli @@ -31,18 +31,3 @@ val new_page (** Initialise a new state *) val init : Prosemirror.t -> Prosemirror.View.editor_view Js.t -> float -> Jstr.t option -> t - -type state = t -module type Event = sig - - type t - - val update: t -> state -> state - -end - -type event = E : 'a * (module Event with type t = 'a) -> event - -(** Simple helper for the main event loop *) -val run - : ?eq:(t -> t -> bool) -> t -> event Note.E.t -> state Note.S.t -- cgit v1.2.3