text stringlengths 12 786k |
|---|
let relink_request_node ( node : Dom_html . element Js . t ) = let id = Js . Opt . get node ## ( getAttribute ( Js . string Eliom_runtime . RawXML . node_id_attrib ) ) ( fun ( ) -> Lwt_log . raise_error_f ~ section " unique node without id attribute " ) in Js . Optdef . ... |
let relink_request_nodes root = Lwt_log . ign_debug ~ section " Relink request nodes " ; if ! Eliom_config . debug_timings then Firebug . console ## ( time ( Js . string " relink_request_nodes " ) ) ; Eliommod_dom . iter_nodeList ( Eliommod_dom . select_request_nodes root ) relin... |
let relink_page_but_client_values ( root : Dom_html . element Js . t ) = Lwt_log . ign_debug ~ section " Relink page " ; let ( a_nodeList , form_nodeList , process_nodeList , closure_nodeList , attrib_nodeList ) = Eliommod_dom . select_nodes root in Eliommod_dom . iter_nodeList a_nod... |
let is_closure_attrib , get_closure_name , get_closure_id = let v_prefix = Eliom_runtime . RawXML . closure_attr_prefix in let v_len = String . length v_prefix in let v_prefix_js = Js . string v_prefix in let n_prefix = Eliom_runtime . RawXML . closure_name_prefix in let n_len = String . length ... |
let relink_closure_node root onload table ( node : Dom_html . element Js . t ) = Lwt_log . ign_debug ~ section " Relink closure node " ; let aux attr = if is_closure_attrib attr then let cid = Js . to_bytestring ( get_closure_id attr ) in let name = get_closure_name attr in try let cv = Eli... |
let relink_closure_nodes ( root : Dom_html . element Js . t ) event_handlers closure_nodeList = Lwt_log . ign_debug_f ~ section " Relink % i closure nodes " closure_nodeList . ## length ; let onload = ref [ ] in Eliommod_dom . iter_nodeList closure_nodeList ( fun node -> relink_closure_... |
let is_attrib_attrib , get_attrib_id = let v_prefix = Eliom_runtime . RawXML . client_attr_prefix in let v_len = String . length v_prefix in let v_prefix_js = Js . string v_prefix in let n_prefix = Eliom_runtime . RawXML . client_name_prefix in let n_len = String . length n_prefix in let n_prefix_... |
let relink_attrib _root table ( node : Dom_html . element Js . t ) = Lwt_log . ign_debug ~ section " Relink attribute " ; let aux attr = if is_attrib_attrib attr then let cid = Js . to_bytestring ( get_attrib_id attr ) in try let value = Eliom_runtime . RawXML . ClosureMap . find cid ... |
let relink_attribs ( root : Dom_html . element Js . t ) attribs attrib_nodeList = Lwt_log . ign_debug_f ~ section " Relink % i attributes " attrib_nodeList . ## length ; Eliommod_dom . iter_nodeList attrib_nodeList ( fun node -> relink_attrib root attribs node ) |
let load_data_script page = Lwt_log . ign_debug ~ section " Load Eliom application data " ; let head = Eliommod_dom . get_head page in let data_script : Dom_html . scriptElement Js . t = match Dom . list_of_nodeList head . ## childNodes with | _ :: _ :: data_script :: _ -> ( let data_s... |
let scroll_to_fragment ? offset fragment = match offset with | Some pos -> Eliommod_dom . setDocumentScroll pos | None -> ( match fragment with | None | Some " " -> Eliommod_dom . setDocumentScroll Eliommod_dom . top_position | Some fragment -> let scroll_to_element e = e ## ( scrollIntoView ... |
let with_progress_cursor : ' a Lwt . t -> ' a Lwt . t = fun t -> try % lwt Dom_html . document . ## body . ## style . ## cursor := Js . string " progress " ; let % lwt res = t in Dom_html . document . ## body . ## style . ## cursor := Js . string " auto " ; Lwt . ... |
type tmp_recontent = | RELazy of Xml . econtent Eliom_lazy . request | RE of Xml . econtent |
type tmp_elt = { tmp_elt : tmp_recontent ; tmp_node_id : Xml . node_id } |
let unwrap_tyxml tmp_elt = let elt = match tmp_elt . tmp_elt with | RELazy elt -> Eliom_lazy . force elt | RE elt -> elt in Lwt_log . ign_debug ~ section " Unwrap tyxml " ; let elt = let context = " unwrapping ( i . e . utilize it in whatsoever form ) " in Xml . make_lazy ~ id : tmp... |
let unwrap_client_value cv = Eliom_client_core . Client_value . find ~ instance_id ( : Eliom_runtime . Client_value_server_repr . instance_id cv ) |
let unwrap_global_data ( global_data ' , _ ) = Eliom_client_core . global_data := String_map . map ( fun { Eliom_runtime . server_sections_data ; client_sections_data } -> { Eliom_client_core . server_section = Array . to_list server_sections_data ; client_section = Array . to_list... |
let _ = Eliom_unwrap . register_unwrapper ' ( Eliom_unwrap . id_of_int Eliom_common_base . client_value_unwrap_id_int ) unwrap_client_value ; Eliom_unwrap . register_unwrapper ( Eliom_unwrap . id_of_int Eliom_runtime . tyxml_unwrap_id_int ) unwrap_tyxml ; Eliom_unwrap . register_unwrapper ... |
let add_string_event_listener o e f capt : unit = let e = Js . string e and capt = Js . bool capt and f e = match f e with | Some s -> let s = Js . string s in ( Js . Unsafe . coerce e ) . ## returnValue := s ; Js . def s | None -> Js . undefined in let f = Js . Unsafe . callback ... |
type state = { template : string option ; position : Eliommod_dom . position } |
let random_int = if Js . Optdef . test Js . Unsafe . global . ## crypto && Js . Optdef . test Js . Unsafe . global . ## crypto . ## getRandomValues then fun ( ) -> Typed_array . unsafe_get Js . Unsafe . global . ## crypto ## ( getRandomValues ( new % js Typed_array . int... |
let section_page = Lwt_log . Section . make " eliom : client : page " |
type state_id = { session_id : int ; state_index : int } |
module Page_status_t = struct type t = Generating | Active | Cached | Dead let to_string st = match st with | Generating -> " Generating " | Active -> " Active " | Cached -> " Cached " | Dead -> " Dead " end |
type page = { page_unique_id : int ; mutable page_id : state_id ; mutable url : string ; page_status : Page_status_t . t React . S . t ; mutable previous_page : int option ; set_page_status : ? step : React . step -> Page_status_t . t -> unit ; mutable dom : Dom_html . bodyElement ... |
let string_of_page p = Printf . sprintf " % d /% d % s % s % d % b " p . page_unique_id p . page_id . state_index p . url ( Page_status_t . to_string @@ React . S . value p . page_status ) ( match p . previous_page with Some pp -> pp | None -> 0 ) ( match p . dom with Som... |
let set_page_status p st = Lwt_log . ign_debug_f ~ section : section_page " Set page status % d /% d : % s " p . page_unique_id p . page_id . state_index ( Page_status_t . to_string st ) ; p . set_page_status st |
let retire_page p = set_page_status p @@ match p . dom with Some _ -> Cached | None -> Dead |
let session_id = random_int ( ) |
let next_state_id = let last = ref 0 in fun ( ) -> incr last ; { session_id ; state_index = ! last } |
let last_page_id = ref ( - 1 ) |
let mk_page ( ? state_id = next_state_id ( ) ) ? url ? previous_page ~ status ( ) = incr last_page_id ; Lwt_log . ign_debug_f ~ section : section_page " Create page % d /% d " ! last_page_id state_id . state_index ; let page_status , set_page_status = React . S . create status ... |
let active_page = ref @@ mk_page ~ status : Active ( ) |
let set_active_page p = Lwt_log . ign_debug_f ~ section : section_page " Set active page % d /% d " p . page_unique_id p . page_id . state_index ; retire_page ! active_page ; active_page := p ; set_page_status ! active_page Active |
let this_page : page Lwt . key = Lwt . new_key ( ) |
let get_this_page ( ) = match Lwt . get this_page with | Some p -> p | None -> Lwt_log . ign_debug_f ~ section : section_page " No page in context " ; ! active_page |
let with_new_page ? state_id ? old_page ~ replace ( ) f = let state_id = if replace then Some ! active_page . page_id else state_id in let url , previous_page = match old_page with | Some o -> Some o . url , o . previous_page | None -> None , None in let page = mk_page ? state_id ? url ? ... |
module History = struct let section = Lwt_log . Section . make " eliom : client : history " let get , set = let history = ref [ ! active_page ] in let set h = Lwt_log . ign_debug_f ~ section " setting history :\ n % s " ( String . concat " \ n " @@ List . map string_of_page !... |
let advance_page ( ) = let new_page = get_this_page ( ) in if new_page != ! active_page then ( new_page . previous_page <- Some ! active_page . page_id . state_index ; ( match History . find_by_state_index new_page . page_id . state_index with | Some _ -> ( ) | None -> History .... |
let state_key { session_id ; state_index } = Js . string ( Printf . sprintf " state_history_ % x_ % x " session_id state_index ) |
let get_state state_id : state = Js . Opt . case ( Js . Optdef . case Dom_html . window . ## sessionStorage ( fun ( ) -> Lwt_log . raise_error_f ~ section " sessionStorage not available " ) ( fun s -> s ## ( getItem ( state_key state_id ) ) ) ) ( fun ( ) -> raise ... |
let set_state i ( v : state ) = Js . Optdef . case Dom_html . window . ## sessionStorage ( fun ( ) -> ( ) ) ( fun s -> s ## ( setItem ( state_key i ) ( Json . output v ) ) ) |
let update_state ( ) = set_state ! active_page . page_id { template = Eliom_request_info . get_request_template ( ) ; position = Eliommod_dom . getDocumentScroll ( ) } |
type ( ' a , ' + b ) server_function = ' a -> ' b Lwt . t |
let only_replace_body = ref false |
let persist_document_head ( ) = only_replace_body := true |
let insert_base page = let b = Dom_html . createBase Dom_html . document in b . ## href := Js . string ( Eliom_process . get_base_url ( ) ) ; b . ## id := Js . string Eliom_common_base . base_elt_id ; Js . Opt . case page ## ( querySelector ( Js . string " head " ) ) ... |
let get_global_data ( ) = let def ( ) = None and id = Js . string " __global_data " in Js . Optdef . case Dom_html . window . ## localStorage def @@ fun storage -> Js . Opt . case storage ## ( getItem id ) def @@ fun v -> Lwt_log . ign_debug_f " Unwrap __global_data " ; ... |
let normalize_app_path p = let p = Eliom_lib . Url . split_path p in let p = match p with " " :: p -> p | _ -> p in match List . rev p with " " :: p -> List . rev p | _ -> p |
let init_client_app ~ app_name ( ? ssl = false ) ~ hostname ( ? port = 80 ) ~ site_dir ( ) = Lwt_log . ign_debug_f " Eliom_client . init_client_app called . " ; Eliom_process . appl_name_r := Some app_name ; Eliom_request_info . client_app_initialised := true ; Eliom_process .... |
let is_client_app ( ) = ! Eliom_common . is_client_app |
let _ = Eliom_common . is_client_app := not ( Js . Optdef . test Js . Unsafe . global . ## ___eliom_appl_process_info_foo ) |
let onunload_fun _ = update_state ( ) ; run_callbacks ( flush_onunload ( ) ) ; Js . _true |
let onbeforeunload_fun _ = run_onbeforeunload ( ) |
let set_base_url ( ) = Eliom_process . set_base_url ( String . concat " " [ Js . to_string Dom_html . window . ## location . ## protocol ; " " // ; Js . to_string Dom_html . window . ## location . ## host ; Js . to_string Dom_html . window . ## location . ## pat... |
let dom_history_ready = ref false |
let init ( ) = ( if is_client_app ( ) && Js . Optdef . test Js . Unsafe . global . ## ___eliom_server_ && Js . Optdef . test Js . Unsafe . global . ## ___eliom_app_name_ then let app_name = Js . to_string Js . Unsafe . global . ## ___eliom_app_name_ and site_dir = Js . ... |
let create_request__ ? absolute ? absolute_path ? https ( type m ) ( ~ service : ( _ , _ , m , _ , _ , _ , _ , _ , _ , _ , _ ) Eliom_service . t ) ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params get_params post_params = let path , ... |
let create_request_ ( type m ) ? absolute ? absolute_path ? https ( ~ service : ( _ , _ , m , _ , _ , _ , _ , _ , _ , _ , _ ) Eliom_service . t ) ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params get_params post_params = match Eliom_se... |
let raw_call_service ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params ? progress ? upload_progress ? override_mime_type get_params post_params = let with_credentials = not ( Eliom_service . is_external service ) in let % lw... |
let call_service ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params ? progress ? upload_progress ? override_mime_type get_params post_params = let % lwt _ , content = raw_call_service ? absolute ? absolute_path ? https ~ ser... |
let exit_to ? window_name ? window_features ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params get_params post_params = match create_request_ ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_... |
let window_open ~ window_name ? window_features ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params get_params = match create_request_ ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ... |
let unwrap_caml_content content = let r : ' a Eliom_runtime . eliom_caml_service_data = Eliom_unwrap . unwrap ( Url . decode content ) 0 in Lwt . return ( r . Eliom_runtime . ecs_data , r . Eliom_runtime . ecs_request_data ) |
let call_ocaml_service ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ? nl_params ? keep_get_na_params ? progress ? upload_progress ? override_mime_type get_params post_params = Lwt_log . ign_debug ~ section " Call OCaml service " ; let % lwt _ , co... |
let path_and_args_of_uri uri = let path_of_string s = match Url . path_of_path_string s with " . " :: path -> path | path -> path in match Url . url_of_string uri with | Some ( Url . Http url | Url . Https url ) -> url . Url . hu_path , url . Url . hu_arguments | _ -> ( match t... |
let set_current_uri , get_current_uri = let set_current_uri uri = let current_uri = fst ( Url . split_fragment uri ) in ( get_this_page ( ) ) . url <- current_uri ; let path , all_get_params = path_and_args_of_uri current_uri in Lwt . async @@ fun ( ) -> Eliom_request_info . update_... |
let current_pseudo_fragment = ref " " |
let reload_function = ref None |
let set_reload_function f = reload_function := Some f |
let set_max_dist_history_doms limit = History . max_num_doms := limit ; History . garbage_collect_doms ( ) |
let push_history_dom ( ) = if ! dom_history_ready then ( let page = ! active_page in let dom = if ! only_replace_body then Dom_html . document . ## body else Dom_html . document . ## documentElement in page . dom <- Some dom ; History . garbage_collect_doms ( ) ) |
module Page_status = struct include Page_status_t let signal ( ) = let p = get_this_page ( ) in p . page_status module Events = struct let changes ( ) = React . S . changes ( signal ( ) ) let active ( ) = changes ( ) |> React . E . fmap @@ function Active -> Some ( ) ... |
let is_in_cache state_id = match History . find_by_state_index state_id . state_index with | Some { dom = Some _ } -> true | _ -> false |
let stash_reload_function f = let page = get_this_page ( ) in let state_id = page . page_id in let id = state_id . state_index in Lwt_log . ign_debug_f ~ section : section_page " Update reload function for page % d " id ; page . reload_function <- Some f |
let change_url_string ~ replace uri = Lwt_log . ign_debug_f ~ section : section_page " Change url string : % s " uri ; let full_uri = if ! Eliom_common . is_client_app then uri else Url . resolve uri in set_current_uri full_uri ; if Eliom_process . history_api then ( let this_page = get_this_... |
let change_url ( ? replace = false ) ? absolute ? absolute_path ? https ~ service ? hostname ? port ? fragment ? keep_nl_params ? nl_params params = Lwt_log . ign_debug ~ section : section_page " Change url " ; ( reload_function := match Eliom_service . xhr_with_cookies service with | No... |
let set_template_content ~ replace ~ uri ? fragment = let really_set content ( ) = reload_function := None ; ( match fragment with | None -> change_url_string ~ replace uri | Some fragment -> change_url_string ~ replace ( uri ^ " " # ^ fragment ) ) ; let % lwt ( ) = Lwt_mutex . ... |
let set_uri ~ replace ? fragment uri = match fragment with | None -> change_url_string ~ replace uri | Some fragment -> change_url_string ~ replace ( uri ^ " " # ^ fragment ) |
let replace_page ~ do_insert_base new_page = if ! Eliom_config . debug_timings then Firebug . console ## ( time ( Js . string " replace_page " ) ) ; if ! only_replace_body then let new_body = new_page . ## childNodes ## ( item 1 ) in Js . Opt . iter new_body ( fun new_body -> D... |
let set_content_local ? offset ? fragment new_page = Lwt_log . ign_debug ~ section : section_page " Set content local " ; let locked = ref true in let recover ( ) = if ! locked then Lwt_mutex . unlock Eliom_client_core . load_mutex ; if ! Eliom_config . debug_timings then Firebug . consol... |
let set_content ~ replace ~ uri ? offset ? fragment content = Lwt_log . ign_debug ~ section : section_page " Set content " ; let target_uri = uri in let % lwt ( ) = run_lwt_callbacks { in_cache = is_in_cache ! active_page . page_id ; origin_uri = get_current_uri ( ) ; target_uri ; ... |
let ocamlify_params = List . map ( function v , ` String s -> v , Js . to_string s | _ , _ -> assert false ) |
let make_uri subpath params = let base = if is_client_app ( ) then match subpath with _ :: _ -> String . concat " " / subpath | [ ] -> " " / else let path = match subpath with _ :: _ -> String . concat " " / subpath | [ ] -> " " and port = match Url . Current . por... |
let route ( { Eliom_route . i_subpath ; i_get_params ; i_post_params } as info ) = Lwt_log . ign_debug ~ section : section_page " Route " ; let info , i_subpath = match i_subpath with | [ " . " ; " " ] -> { info with i_subpath = [ ] } , [ ] | i_subpath -> i... |
let switch_to_https ( ) = let info = Eliom_process . get_info ( ) in Eliom_process . set_info { info with Eliom_common . cpi_ssl = true } |
let string_of_result result = match result with | Eliom_service . No_contents -> " No_contents " | Dom _ -> " Dom " | Redirect _ -> " Redirect " | Reload_action { hidden ; https } -> let values = match hidden , https with | false , false -> " false , false " | false , true... |
let rec handle_result ~ replace ~ uri result = let % lwt result = result in Lwt_log . ign_debug ~ section : section_page ( " handle_result : result is " ^ string_of_result result ) ; match result with | Eliom_service . No_contents -> Lwt . return_unit | Dom d -> change_url_string ~ replace... |
let change_page_uri_a ? cookies_info ? tmpl ( ? get_params = [ ] ) full_uri = Lwt_log . ign_debug ~ section : section_page " Change page uri " ; with_progress_cursor ( let uri , fragment = Url . split_fragment full_uri in if uri <> get_current_uri ( ) || fragment = None then ( if ... |
let change_page_uri ? replace full_uri = Lwt_log . ign_debug ~ section : section_page " Change page uri " ; try % lwt match Url . url_of_string full_uri with | Some ( Url . Http url | Url . Https url ) -> Lwt_log . ign_debug ~ section : section_page " change page uri : url is http or ht... |
let change_page_get_form ? cookies_info ? tmpl form full_uri = with_progress_cursor ( let form = Js . Unsafe . coerce form in let uri , fragment = Url . split_fragment full_uri in match tmpl with | Some t when tmpl = Eliom_request_info . get_request_template ( ) -> let % lwt uri , content = ... |
let change_page_post_form ? cookies_info ? tmpl form full_uri = with_progress_cursor ( let form = Js . Unsafe . coerce form in let uri , fragment = Url . split_fragment full_uri in match tmpl with | Some t when tmpl = Eliom_request_info . get_request_template ( ) -> let % lwt uri , content =... |
let _ = ( Eliom_client_core . change_page_uri_ := fun ? cookies_info ? tmpl href -> Lwt . ignore_result ( change_page_uri_a ? cookies_info ? tmpl href ) ) ; ( Eliom_client_core . change_page_get_form_ := fun ? cookies_info ? tmpl form href -> Lwt . ignore_result ( change_page_get_form ... |
let restore_history_dom id = match History . find_by_state_index id with | Some page -> ( match page . dom with | Some dom -> if ! only_replace_body then Dom . replaceChild Dom_html . document . ## documentElement dom Dom_html . document . ## body else Dom . replaceChild Dom_html . document ... |
let ( ) = if Eliom_process . history_api then ( let revisit full_uri state_id = let state = try get_state state_id with Not_found -> failwith ( Printf . sprintf " revisit : state id % x /% x not found in sessionStorage ( % s ) " state_id . session_id state_id . state_index full_uri ) i... |
let ( ) = Eliom_unwrap . register_unwrapper ( Eliom_unwrap . id_of_int Eliom_common_base . server_function_unwrap_id_int ) ( fun ( service , _ ) -> call_ocaml_service ~ absolute : true ~ service ( ) ) |
let section = Lwt_log . Section . make " eliom : client " |
let create_buffer ( ) = let stack = ref [ ] in let elts = ref [ ] in let add x = elts := x :: ! elts and get ( ) = List . rev ! elts in let push ( ) = stack := ! elts :: ! stack ; elts := [ ] in let flush ( ) = let res = get ( ) in ( match ! stack with | l :: r ... |
module Client_closure : sig val register : closure_id : string -> closure ( : _ -> _ ) -> unit val find : closure_id : string -> poly -> poly let client_closures = Jstable . create ( ) let register ~ closure_id ~ closure = Jstable . add client_closures ( Js . string closure_id ) ( f... |
module Client_value : sig val find : instance_id : int -> poly option val initialize : Eliom_runtime . client_value_datum -> unit let table = new % js Js . array_empty let find ~ instance_id = if instance_id = 0 then None else Js . Optdef . to_option ( Js . array_get table instance_id ) let in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.