text stringlengths 12 786k |
|---|
let middleClick ev = match Dom_html . taggedEvent ev with | Dom_html . MouseEvent ev -> Dom_html . buttonPressed ev = Dom_html . Middle_button || Js . to_bool ev . ## ctrlKey || Js . to_bool ev . ## shiftKey || Js . to_bool ev . ## altKey || Js . to_bool ev . ## metaKey | _ -> fal... |
module Injection : sig val get : ? ident : string -> ? pos : pos -> name : string -> _ val initialize : compilation_unit_id : string -> Eliom_client_value . injection_datum -> unit let table = Jstable . create ( ) let get ? ident ? pos ~ name = Lwt_log . ign_debug_f ~ section " Get inje... |
type compilation_unit_global_data = { mutable server_section : Eliom_runtime . client_value_datum array list ; mutable client_section : Eliom_runtime . injection_datum array list } |
let global_data = ref String_map . empty |
let do_next_server_section_data ~ compilation_unit_id = Lwt_log . ign_debug_f ~ section " Do next client value data section in compilation unit % s " compilation_unit_id ; try let data = String_map . find compilation_unit_id ! global_data in match data . server_section with | l :: r -> data . ser... |
let do_next_client_section_data ~ compilation_unit_id = Lwt_log . ign_debug_f ~ section " Do next injection data section in compilation unit % s " compilation_unit_id ; try let data = String_map . find compilation_unit_id ! global_data in match data . client_section with | l :: r -> data . client... |
let register_unwrapped_elt , force_unwrapped_elts = let suspended_nodes = ref [ ] in ( ( fun elt -> suspended_nodes := elt :: ! suspended_nodes ) , fun ( ) -> Lwt_log . ign_debug ~ section " Force unwrapped elements " ; List . iter Xml . force_lazy ! suspended_nodes ; suspended_... |
let register_process_node , find_process_node = let process_nodes : Dom . node Js . t Jstable . t = Jstable . create ( ) in let find id = Lwt_log . ign_debug_f ~ section " Find process node % a " ( fun ( ) -> Js . to_string ) id ; Jstable . find process_nodes id in let register ... |
let registered_process_node id = Js . Optdef . test ( find_process_node id ) |
let getElementById id = Js . Optdef . case ( find_process_node ( Js . string id ) ) ( fun ( ) -> Lwt_log . ign_warning_f ~ section " getElementById % s : Not_found " id ; raise Not_found ) ( fun pnode -> pnode ) |
let register_request_node , find_request_node , reset_request_nodes = let request_nodes : Dom . node Js . t Jstable . t ref = ref ( Jstable . create ( ) ) in let find id = Jstable . find ! request_nodes id in let register id node = Lwt_log . ign_debug_f ~ section " Register request node... |
let load_mutex = Lwt_mutex . create ( ) |
let _ = ignore ( Lwt_mutex . lock load_mutex ) |
let in_onload , broadcast_load_end , wait_load_end , set_loading_phase = let loading_phase = ref true in let load_end = Lwt_condition . create ( ) in let set ( ) = loading_phase := true in let in_onload ( ) = ! loading_phase in let broadcast_load_end ( ) = loading_phase := false ; Lwt... |
let change_page_uri_ : ( ? cookies_info : bool * string list -> ? tmpl : string -> string -> unit ) ref = ref ( fun ? cookies_info : _ ? tmpl : _ _href -> assert false ) |
let change_page_get_form_ : ( ? cookies_info : bool * string list -> ? tmpl : string -> Dom_html . formElement Js . t -> string -> unit ) ref = ref ( fun ? cookies_info : _ ? tmpl : _ _form _href -> assert false ) |
let change_page_post_form_ = ref ( fun ? cookies_info : _ ? tmpl : _ _form _href -> assert false ) |
type client_form_handler = Dom_html . event Js . t -> bool Lwt . t |
let raw_a_handler node cookies_info tmpl ev = let href = ( Js . Unsafe . coerce node : Dom_html . anchorElement Js . t ) . ## href in let https = Url . get_ssl ( Js . to_string href ) in middleClick ev || ( not ! Eliom_common . is_client_app ) && ( ( https = Some true && not El... |
let raw_form_handler form kind cookies_info tmpl ev client_form_handler = let action = Js . to_string form . ## action in let https = Url . get_ssl action in let change_page_form = match kind with | ` Form_get -> ! change_page_get_form_ | ` Form_post -> ! change_page_post_form_ in let f ( ) = ... |
let raw_event_handler value = let handler = ( Eliom_lib . from_poly ( Eliom_lib . to_poly value ) : # Dom_html . event Js . t -> unit ) in fun ev -> try handler ev ; true with Eliom_client_value . False -> false |
let closure_name_prefix_len = String . length closure_name_prefix |
let reify_caml_event name node ce = match ce with | Xml . CE_call_service None -> name , ` Other ( fun _ -> true ) | Xml . CE_call_service ( Some ( ` A , cookies_info , tmpl , _ ) ) -> ( name , ` Other ( fun ev -> let node = Js . Opt . get ( Dom_html . CoerceTo . ... |
let register_event_handler , flush_load_script = let add , _ , flush , _ = create_buffer ( ) in let register node ( name , ev ) = match reify_caml_event name node ev with | " onload " , ` Other f -> add f | " onload " , ` Keyboard _ -> failwith " keyboard event handler for ... |
let rebuild_attrib_val = function | Xml . AFloat f -> ( Js . number_of_float f ) ## toString | Xml . AInt i -> ( Js . number_of_float ( float_of_int i ) ) ## toString | Xml . AStr s -> Js . string s | Xml . AStrL ( Xml . Space , sl ) -> Js . string ( String . concat " ... |
let class_list_of_racontent = function | Xml . AStr s -> [ s ] | Xml . AStrL ( _space , l ) -> l | _ -> failwith " attribute class is not a string " |
let class_list_of_racontent_o = function | Some c -> class_list_of_racontent c | None -> [ ] |
let rebuild_class_list l1 l2 l3 = let f s = ( not ( List . exists ( ( = ) s ) l2 ) ) && not ( List . exists ( ( = ) s ) l3 ) in l3 @ List . filter f l1 |
let rebuild_class_string l1 l2 l3 = rebuild_class_list l1 l2 l3 |> String . concat " " |> Js . string |
let get_prop node name = if Js . Optdef . test ( Js . Unsafe . get node name ) then Some name else None |
let iter_prop node name f = match get_prop node name with Some n -> f n | None -> ( ) |
let iter_prop_protected node name f = match get_prop node name with | Some n -> ( try f n with _ -> ( ) ) | None -> ( ) |
let space_re = Regexp . regexp " " |
let current_classes node = let name = Js . string " class " in Js . Opt . case node ## ( getAttribute name ) ( fun ( ) -> [ ] ) ( fun s -> Js . to_string s |> Regexp . ( split space_re ) ) |
let rebuild_reactive_class_rattrib node s = let name = Js . string " class " in let e = React . S . diff ( fun v v ' -> v ' , v ) s and f ( v , v ' ) = let l1 = current_classes node and l2 = class_list_of_racontent_o v and l3 = class_list_of_racontent_o v ' in let s = rebuild_clas... |
let rec rebuild_rattrib node ra = match Xml . racontent ra with | Xml . RA a when Xml . aname ra = " class " -> let l1 = current_classes node and l2 = class_list_of_racontent a in let name = Js . string " class " and s = rebuild_class_string l1 l2 l2 in node ## ( setAttribute name s ) | Xm... |
let delay f = Lwt . ignore_result ( Lwt . pause ( ) >>= fun ( ) -> f ( ) ; Lwt . return_unit ) |
module ReactState : sig type t val get_node : t -> Dom . node Js . t val change_dom : t -> Dom . node Js . t -> bool val init_or_update : ? state : t -> Eliom_content_core . Xml . elt -> t type t = { elt : Eliom_content_core . Xml . elt ; global_version : int Js . js_array Js . t ;... |
type content_ns = [ ` HTML5 | ` SVG ] |
let rec rebuild_node_with_state ns ? state elt = match Xml . get_node elt with | Xml . DomNode node -> node | Xml . ReactChildren ( node , elts ) -> let dom = raw_rebuild_node ns node in Js_of_ocaml_tyxml . Tyxml_js . Util . update_children dom ( ReactiveData . RList . map ( rebuild_nod... |
let is_before_initial_load , set_initial_load = let before_load = ref true in ( fun ( ) -> ! before_load ) , fun ( ) -> before_load := false |
let rebuild_node_ns ns context elt ' = Lwt_log . ign_debug_f ~ section " Rebuild node % a ( % s ) " ( fun ( ) e -> Eliom_content_core . Xml . string_of_node_id ( Xml . get_node_id e ) ) elt ' context ; if is_before_initial_load ( ) then Lwt_log . raise_error_f ~ section ~ ... |
let rebuild_node_svg context elt = let elt ' = Eliom_content_core . Svg . F . toelt elt in rebuild_node_ns ` SVG context elt ' |
let rebuild_node context elt = let elt ' = Eliom_content_core . Html . F . toelt elt in rebuild_node_ns ` HTML5 context elt ' |
module Syntax_helpers = struct let register_client_closure closure_id closure = Client_closure . register ~ closure_id ~ closure let open_client_section compilation_unit_id = do_next_server_section_data ~ compilation_unit_id ; do_next_client_section_data ~ compilation_unit_id let close_server_section compila... |
let section = Eliom_lib . Lwt_log . Section . make " eliom : comet " |
module Configuration = struct type configuration_data = { active_until_timeout : bool ; time_between_request_unfocused : ( float * float * float ) list option ; time_after_unfocus : float ; time_between_request : float } let default_configuration = { active_until_timeout = false ; time_betwe... |
let handle_exn , set_handle_exn_function = let closed = ref false in let r = ref ( fun ? exn ( ) -> let s = " Unknown exception during comet . Customize this with Eliom_comet . set_handle_exn_function . " in match exn with | Some exn -> Eliom_lib . Lwt_log . raise_error ~ section ~ exn s... |
type stateless_message = ( chan_id * ( string * int ) Ecb . channel_data ) list |
module Service_handler : sig type ' a t type ' a kind type stateless type stateful val stateless : stateless kind val stateful : stateful kind val make : Ecb . comet_service -> ' a kind -> ' a t val wait_data : ' a t -> ( chan_id * int option * string Ecb . channel_data ) list Lwt . t val ... |
type ' a handler = { hd_service_handler : ' a Service_handler . t ; hd_stream : ( string * int option * string Ecb . channel_data ) Lwt_stream . t } |
let handler_stream hd = Lwt_stream . map_list ( fun x -> x ) ( Lwt_stream . from ( fun ( ) -> Lwt . try_bind ( fun ( ) -> Service_handler . wait_data hd ) ( fun s -> Lwt . return_some s ) ( fun _ -> Lwt . return_none ) ) ) |
let stateful_handler_table : ( Ecb . comet_service , Service_handler . stateful handler ) Hashtbl . t = Hashtbl . create 1 |
let stateless_handler_table : ( Ecb . comet_service , Service_handler . stateless handler ) Hashtbl . t = Hashtbl . create 1 |
let init ( service : Ecb . comet_service ) kind table = let hd_service_handler = Service_handler . make service kind in let hd_stream = handler_stream hd_service_handler in let hd = { hd_service_handler ; hd_stream } in Hashtbl . add table service hd ; hd |
let get_stateful_hd ( service : Ecb . comet_service ) : Service_handler . stateful handler = try Hashtbl . find stateful_handler_table service with Not_found -> init service Service_handler . stateful stateful_handler_table |
let get_stateless_hd ( service : Ecb . comet_service ) : Service_handler . stateless handler = try Hashtbl . find stateless_handler_table service with Not_found -> init service Service_handler . stateless stateless_handler_table |
let activate ( ) = let f _ { hd_service_handler } = Service_handler . activate hd_service_handler in Hashtbl . iter f stateless_handler_table ; Hashtbl . iter f stateful_handler_table |
let restart ( ) = let f _ { hd_service_handler } = Service_handler . restart hd_service_handler in Hashtbl . iter f stateless_handler_table ; Hashtbl . iter f stateful_handler_table |
let close = function | Ecb . Stateful_channel ( chan_service , chan_id ) -> let { hd_service_handler } = get_stateful_hd chan_service in Service_handler . close hd_service_handler ( Ecb . string_of_chan_id chan_id ) | Ecb . Stateless_channel ( chan_service , chan_id , _kind ) -> let... |
let unmarshal s : ' a = Eliom_unwrap . unwrap ( Eliom_lib . Url . decode s ) 0 |
type position_relation = | Equal | Greater |
type position = | No_position | Position of position_relation * int option ref |
let position_of_kind = function | Ecb . After_kind i -> Position ( Equal , ref ( Some i ) ) | Ecb . Newest_kind i -> Position ( Greater , ref ( Some i ) ) | Ecb . Last_kind None -> Position ( Greater , ref None ) | Ecb . Last_kind ( Some _ ) -> Position ( Equal , ref ... |
let check_and_update_position position msg_pos data = match position , msg_pos , data with | No_position , None , _ -> true | No_position , Some _ , _ | Position _ , None , Ecb . Data _ -> Eliom_lib . Lwt_log . raise_error ~ section " check_position : channel kind and message do not... |
let register ' hd position ( _ : Ecb . comet_service ) ( chan_id : ' a Ecb . chan_id ) = let chan_id = Ecb . string_of_chan_id chan_id in let stream = Lwt_stream . filter_map_s ( function | id , pos , data when id = chan_id && check_and_update_position position pos data -> ( match ... |
let register_stateful ( ? wake = true ) service chan_id = let hd = get_stateful_hd service in let stream = register ' hd No_position service chan_id in let chan_id = Ecb . string_of_chan_id chan_id in Service_handler . add_channel_stateful hd . hd_service_handler chan_id ; if wake then Service_handl... |
let register_stateless ( ? wake = true ) service chan_id kind = let hd = get_stateless_hd service in let stream = register ' hd ( position_of_kind kind ) service chan_id in let chan_id = Ecb . string_of_chan_id chan_id in Service_handler . add_channel_stateless hd . hd_service_handler chan_id kind... |
let register ( ? wake = true ) ( wrapped_chan : ' a Ecb . wrapped_channel ) = match wrapped_chan with | Ecb . Stateful_channel ( s , c ) -> register_stateful ~ wake s c | Ecb . Stateless_channel ( s , c , kind ) -> register_stateless ~ wake s c kind |
let internal_unwrap ( wrapped_chan , _unwrapper ) = register wrapped_chan |
let ( ) = Eliom_unwrap . register_unwrapper Eliom_common . comet_channel_unwrap_id internal_unwrap |
let is_active ( ) = let max a b = match a with | ` Inactive -> ` Inactive | ` Idle -> let b = b ( ) in if b = ` Active then ` Idle else b | ` Active -> b ( ) in let f _ hd active = max active ( fun ( ) -> Service_handler . is_active hd . hd_service_handler ) in max ( H... |
module Channel = struct type ' a t = ' a Lwt_stream . t end |
let section = Lwt_log . Section . make " eliom : comet " |
let answer_to_string = Deriving_Json . to_string Eliom_comet_base . answer_json |
let encode_downgoing s = answer_to_string ( Eliom_comet_base . Stateful_messages ( Array . of_list s ) ) |
let encode_global_downgoing s = answer_to_string ( Eliom_comet_base . Stateless_messages ( Array . of_list s ) ) |
let timeout_msg = answer_to_string Eliom_comet_base . Timeout |
let state_closed_msg = answer_to_string Eliom_comet_base . State_closed |
let error_msg s = answer_to_string ( Eliom_comet_base . Comet_error s ) |
let marshal ( v : ' a ) = let wrapped = Eliom_wrap . wrap v in let value : ' a Eliom_runtime . eliom_comet_data_type = wrapped in Eliom_lib . Url . encode ~ plus : false ( Marshal . to_string value [ ] ) |
module Comet_param = struct type page = string let translate content = Lwt . return ( content , json_content_type ) end |
module Comet = Eliom_registration . Customize ( Eliom_registration . String ) ( Comet_param ) |
let fallback_service = Eliom_common . lazy_site_value_from_fun @@ fun ( ) -> Comet . create ~ meth ( : Eliom_service . Get Eliom_parameter . unit ) ~ path ( : Eliom_service . Path comet_path ) ( fun ( ) ( ) -> Lwt . return state_closed_msg ) |
let fallback_global_service = Eliom_common . lazy_site_value_from_fun @@ fun ( ) -> Comet . create ~ meth ( : Eliom_service . Get Eliom_parameter . unit ) ~ path ( : Eliom_service . Path comet_global_path ) ( fun ( ) ( ) -> Lwt . return ( error_msg " request with no post pa... |
let timeout ( ) = timeout_base . * ( 1 . . + ( timeout_jitter . * ( Random . float 2 . . - 1 . ) ) ) |
module Stateless : sig type channel val create : ? name : string -> size : int -> string Lwt_stream . t -> channel val get_id : channel -> string val get_service : unit -> Eliom_comet_base . comet_service val get_kind : newest : bool -> channel -> Eliom_comet_base . stateless_kind val chan_id_of_s... |
let ( ) = Eliommod . register_site_init ( fun ( ) -> ignore ( Eliom_common . force_lazy_site_value fallback_global_service ) ; ignore ( Eliom_common . force_lazy_site_value fallback_service ) ; ignore ( Stateless . get_service ( ) ) ) |
module Stateful : sig type t val create : ? scope : Eliom_common . client_process_scope -> ? name : chan_id -> size : int -> _ React . event -> t val create_unlimited : ? scope : Eliom_common . client_process_scope -> ? name : chan_id -> _ Lwt_stream . t -> t val get_id : t -> string type... |
module Channel : sig type ' a t type comet_scope = [ Eliom_common . site_scope | Eliom_common . client_process_scope ] val create_from_events : ? scope [ :< comet_scope ] -> ? name : string -> ? size : int -> ' a React . event -> ' a t val create : ? scope [ :< comet_scope ] ->... |
type ' a chan_id = string |
type position = | Newest of int | After of int | Last of int option |
type comet_stateless_request = ( string * position ) array [ @@ deriving json ] |
type command = Register of string | Close of string [ @@ deriving json ] |
type comet_stateful_request = Request_data of int | Commands of command array |
type comet_request = | Stateless of comet_stateless_request | Stateful of comet_stateful_request |
let comet_request_param = Eliom_parameter . ocaml " comet_request " [ % json : comet_request ] |
type ' a channel_data = Data of ' a | Full | Closed [ @@ deriving json ] |
type answer = | Stateless_messages of ( string * ( string * int ) channel_data ) array | Stateful_messages of ( string * string channel_data ) array | Timeout | State_closed | Comet_error of string |
type comet_service = | Comet_service : ( unit , bool * comet_request , Eliom_service . post , Eliom_service . att , _ , _ , _ , [ ` WithoutSuffix ] , unit , [ ` One of bool ] Eliom_parameter . param_name * [ ` One of comet_request Eliom_parameter . ocaml ] Eliom_par... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.