aboutsummaryrefslogtreecommitdiff
path: root/css/merger.ml
diff options
context:
space:
mode:
Diffstat (limited to 'css/merger.ml')
-rwxr-xr-xcss/merger.ml36
1 files changed, 10 insertions, 26 deletions
diff --git a/css/merger.ml b/css/merger.ml
index 514793d..d82df98 100755
--- a/css/merger.ml
+++ b/css/merger.ml
@@ -20,6 +20,8 @@ type state =
; elements : int
}
+module App = Application.Make(struct type t = state end)
+
let init =
{ files = new%js Js.array_empty
; result_css = None
@@ -42,20 +44,10 @@ let build_result
Css_lib.Merge.extract_css
merge_result
-module type Handler = sig
-
- type t
-
- val apply: t -> state -> state
-
-end
-
-type event = E : 'a * (module Handler with type t = 'a) -> event
-
module AddFile = struct
type t = file
- let apply file state =
+ let update file state =
let _ = state.files##push file in
let elements = state.files##.length
and result_css = build_result state.files in
@@ -64,7 +56,7 @@ end
module DelFile = struct
type t = File.t
- let apply file state =
+ let update file state =
let files = state.files##filter
(Js.wrap_callback @@ (fun elt _ _ -> Js.bool (elt.file != file))) in
let elements = files##.length
@@ -72,13 +64,6 @@ module DelFile = struct
{ files ; elements ; result_css }
end
-let do_action
- : (event, state) Application.t
- = fun (E (t, (module Handler))) state ->
- Handler.apply t state
-
-type file_event = event S.t
-
(** Read the content from the file *)
let file_loader
: file E.send -> File.t -> unit
@@ -119,7 +104,7 @@ let header =
block
let file_list
- : event E.send -> file -> El.t
+ : App.event E.send -> file -> El.t
= fun sender f ->
let icon =
El.i []
@@ -139,8 +124,8 @@ let file_list
Ev.listen
Ev.click
(fun _ -> sender (
- E( f.file
- , (module DelFile : Handler with type t = DelFile.t))))
+ App.E( f.file
+ , (module DelFile : App.Event with type t = DelFile.t))))
(El.as_target button);
match f.css with
@@ -248,13 +233,12 @@ let main id =
let state =
- Application.run
- do_action
+ App.run
init
(E.select
[ E.map (fun f ->
- E ( f
- , (module AddFile: Handler with type t = AddFile.t )))
+ App.E ( f
+ , (module AddFile: App.Event with type t = AddFile.t )))
add_file_event
; del_file_event
])