aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2021-12-03 04:19:53 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commitc6265278f05aa4d3af60e420f2d4d13e4bce8ad7 (patch)
treedece2b116d79a052a00e20c1ee2f7677c64190f9
parente78c236a8d28784370f192a3410693c456dc628f (diff)
Removed the application mecanism from the state module
-rwxr-xr-xeditor/actions/add_page.ml8
-rwxr-xr-xeditor/actions/delete_page.ml7
-rwxr-xr-xeditor/actions/dune1
-rwxr-xr-xeditor/actions/editor_actions.ml11
-rwxr-xr-xeditor/actions/editor_actions.mli2
-rwxr-xr-xeditor/actions/export.ml7
-rwxr-xr-xeditor/actions/import.ml5
-rwxr-xr-xeditor/actions/to_markdown.ml8
-rwxr-xr-xeditor/app/dune8
-rw-r--r--editor/app/editor_app.ml1
-rw-r--r--editor/app/editor_app.mli14
-rwxr-xr-xeditor/dune1
-rwxr-xr-xeditor/editor.ml7
-rwxr-xr-xeditor/state/state.ml4
-rwxr-xr-xeditor/state/state.mli15
15 files changed, 57 insertions, 42 deletions
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