aboutsummaryrefslogtreecommitdiff
path: root/editor/forms
diff options
context:
space:
mode:
Diffstat (limited to 'editor/forms')
-rwxr-xr-xeditor/forms/add_page.ml53
-rwxr-xr-xeditor/forms/add_page.mli7
-rwxr-xr-xeditor/forms/delete_page.ml24
-rwxr-xr-xeditor/forms/events.ml12
4 files changed, 47 insertions, 49 deletions
diff --git a/editor/forms/add_page.ml b/editor/forms/add_page.ml
index ac45824..9786f47 100755
--- a/editor/forms/add_page.ml
+++ b/editor/forms/add_page.ml
@@ -3,10 +3,29 @@ open Brr_note
open Note
module Js = Js_of_ocaml.Js
-type t = { title : Jstr.t }
-type Events.kind +=
- | AddPage of t [@@unboxed]
+module Handler = struct
+
+ type t = { title : Jstr.t }
+
+ let key_of_title
+ : Jstr.t -> Jstr.t
+ = fun title ->
+ title
+
+ let on_close
+ : t -> State.t -> State.t
+ = fun {title} state ->
+ let page_id = key_of_title title in
+ let new_date = (new%js Js.date_now)##getTime in
+ let content_obj = object%js
+ val content = Js.null
+ val title = Js.some title
+ val date = Js.some new_date
+ end in
+ State.load_page (Some page_id) state content_obj
+
+end
let create
: unit -> Events.t
@@ -17,13 +36,19 @@ let create
~at:At.[type' (Jstr.v "text")]
in
+ let init =
+ Events.Event
+ ( Handler.{ title = Jstr.empty }
+ , (module Handler : Events.Handler with type t = Handler.t)) in
+
let state =
- S.hold (AddPage { title = Jstr.empty })
+ S.hold init
@@ Evr.on_el
(Ev.input)
(fun _ ->
- AddPage { title = El.prop El.Prop.value input }
- )
+ Events.Event
+ ( Handler.{ title = El.prop El.Prop.value input }
+ , (module Handler : Events.Handler with type t = Handler.t)) )
input in
( state
@@ -38,19 +63,3 @@ let create
]
] )
-let key_of_title
- : Jstr.t -> Jstr.t
- = fun title ->
- title
-
-let on_close
- : t -> State.t -> State.t
- = fun {title} state ->
- let page_id = key_of_title title in
- let new_date = (new%js Js.date_now)##getTime in
- let content_obj = object%js
- val content = Js.null
- val title = Js.some title
- val date = Js.some new_date
- end in
- State.load_page (Some page_id) state content_obj
diff --git a/editor/forms/add_page.mli b/editor/forms/add_page.mli
index 6be1611..8a4ff6f 100755
--- a/editor/forms/add_page.mli
+++ b/editor/forms/add_page.mli
@@ -1,9 +1,2 @@
-type t = { title : Jstr.t }
-type Events.kind +=
- | AddPage of t [@@unboxed]
-
val create
: unit -> Events.t
-
-val on_close
- : t -> State.t -> State.t
diff --git a/editor/forms/delete_page.ml b/editor/forms/delete_page.ml
index 3328dd7..7c973c2 100755
--- a/editor/forms/delete_page.ml
+++ b/editor/forms/delete_page.ml
@@ -1,17 +1,27 @@
open Brr
open Note
-type t = Jstr.t
+module Handler = struct
-type Events.kind +=
- | DeletePage of t [@@unboxed]
+ type t = Jstr.t
+
+ let on_close
+ : t -> State.t -> State.t
+ = fun id state ->
+ State.Storage.delete (fun () -> Some id);
+ let json = State.Storage.load None in
+ State.load_page None state json
+end
let create
: Jstr.t -> Events.t
= fun name ->
let state =
- S.const (DeletePage name) in
+ S.const
+ (Events.Event
+ ( name
+ , (module Handler: Events.Handler with type t = Handler.t))) in
let message = begin
let open Jstr in
@@ -25,9 +35,3 @@ let create
, El.txt message
)
-let on_close
- : t -> State.t -> State.t
- = fun id state ->
- State.Storage.delete (fun () -> Some id);
- let json = State.Storage.load None in
- State.load_page None state json
diff --git a/editor/forms/events.ml b/editor/forms/events.ml
index f7f5711..a88aa76 100755
--- a/editor/forms/events.ml
+++ b/editor/forms/events.ml
@@ -1,13 +1,3 @@
-(** This type is designed to be extended for each form.
-
- Each of them hold the values inside the form.
-
-*)
-type kind = ..
-
-(** The signal has to be log in order to be completely working *)
-type t = kind Note.signal * Brr.El.t
-
module type Handler = sig
type t
@@ -18,3 +8,5 @@ end
type event = Event : 'a * (module Handler with type t = 'a) -> event
+(** The signal has to be log in order to be completely working *)
+type t = event Note.signal * Brr.El.t