From 2fc4e793b12341df6264e22c0b8bd0f6dd2bd27d Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 29 Apr 2021 15:20:11 +0200 Subject: Added pop-up and events in editor --- editor/storage.ml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'editor/storage.ml') diff --git a/editor/storage.ml b/editor/storage.ml index 5dbaab9..f893c2d 100755 --- a/editor/storage.ml +++ b/editor/storage.ml @@ -76,9 +76,9 @@ let save' storage. The right key is given by the result of the function [f] *) let load - : (unit -> Jstr.t option) -> content Js.t - = fun f -> - match f () with + : Jstr.t option -> content Js.t + = fun key -> + match key with | None -> load' storage_key | Some value -> let key = Jstr.concat @@ -87,9 +87,9 @@ let load load' key let save - : check:(content Js.t -> bool) -> content Js.t -> (unit -> Jstr.t option) -> (bool, Jv.Error.t) result - = fun ~check object_content f -> - match f () with + : check:(content Js.t -> bool) -> content Js.t -> Jstr.t option -> (bool, Jv.Error.t) result + = fun ~check object_content key -> + match key with | None -> save' ~check object_content storage_key | Some value -> @@ -103,11 +103,12 @@ let delete = fun f -> match f () with | None -> () - | Some key -> + | Some value -> + let key = Jstr.concat + ~sep:(Jstr.v "_") + [storage_key ; value] in let storage = Brr_io.Storage.local G.window in - let () = Brr_io.Storage.remove_item storage key in - (* Reload the page *) - Brr.Window.reload G.window + Brr_io.Storage.remove_item storage key let get_ids : unit -> Jstr.t list @@ -120,7 +121,7 @@ let get_ids let start = Jstr.length sub in let rec add_element acc = function - | 0 -> acc + | -1 -> acc | nb -> begin match Storage.key storage nb with | Some key when (Jstr.starts_with ~sub key) -> @@ -128,7 +129,8 @@ let get_ids let key_name = Jstr.sub key ~start in add_element (key_name::acc) (nb -1) - | _ -> add_element acc (nb -1) + | _ -> + add_element acc (nb -1) end in -- cgit v1.2.3