text
stringlengths
0
601k
module Attributes = struct let max value = attribute " " " max " value let min value = attribute " " " min " value let step value = attribute " " " step " value let disabled b = if b then attribute " " " disabled " " true " else noProp let selected b = if b then attribute " " " selected " " true " else noProp let accep...
type response_status = { code : int ; message : string }
type response = { url : string ; status : response_status ; headers : string Map . Make ( String ) . t ; body : responseBody }
type ' parsedata error = | BadUrl of string | Timeout | NetworkError | Aborted | BadStatus of response | BadPayload of ' parsedata * response
let string_of_error = function | BadUrl url -> " Bad Url : " ^ url | Timeout -> " Timeout " | NetworkError -> " Unknown network error " | Aborted -> " Request aborted " | BadStatus resp -> " Bad Status : " ^ resp . url | BadPayload ( _customData , resp ) -> " Bad Payload : " ^ resp . url
type header = Header of string * string
type ' res expect = Expect of bodyType * ( response -> ( ' res , string ) Tea_result . t )
type ' msg requestEvents = { onreadystatechange : ( ' msg Vdom . applicationCallbacks ref -> ( Web . XMLHttpRequest . event_readystatechange -> unit ) ) option ; onprogress : ( ' msg Vdom . applicationCallbacks ref -> ( Web . XMLHttpRequest . event_progress -> unit ) ) option }
let emptyRequestEvents = { onreadystatechange = None ; onprogress = None }
type ' res rawRequest = { method ' : string ; headers : header list ; url : string ; body : requestBody ; expect : ' res expect ; timeout : Tea_time . t option ; withCredentials : bool }
type ( ' msg , ' res ) request = Request of ' res rawRequest * ' msg requestEvents option
let expectStringResponse func = let open Web . XMLHttpRequest in Expect ( TextResponseType , ( fun { body ; _ } -> match body with | TextResponse s -> func s | _ -> Tea_result . Error " Non - text response returned " ) )
let expectString = expectStringResponse ( fun resString -> Tea_result . Ok resString )
let request rawRequest = Request ( rawRequest , None )
let getString url = request { method ' = " GET " ; headers = [ ] ; url = url ; body = Web . XMLHttpRequest . EmptyBody ; expect = expectString ; timeout = None ; withCredentials = false }
let send resultToMessage ( Request ( request , maybeEvents ) ) = let module StringMap = Map . Make ( String ) in let { method ' ; headers ; url ; body ; expect ; timeout ; withCredentials } = request in let ( Expect ( typ , responseToResult ) ) = expect in Tea_cmd . call ( fun callbacks -> let enqRes result = fun _ev -...
let encodeUri str = encodeURIComponent str
let decodeUri str = try Some ( decodeURIComponent str ) with _ -> None
module Progress = struct | SomeProgress of bytesProgressed | FailProgress of ' parseFailData error | DoneProgress of ' data type ( ' msg , ' parseFailData ) trackedRequest = { request : ' msg rawRequest ; toProgress : bytesProgressed -> ' msg ; toError : ' parseFailData error -> ' msg } ) * type t = { bytes : int ; byt...
module Decoder = struct type error = String . t module ObjectDict = Map . Make ( String ) type ( ' input , ' result ) t = Decoder of ( ' input -> ( ' result , error ) Tea_result . t ) exception ParseFail of string let string = Decoder ( fun value -> let open Web . Json in match classify value with | JSONString s -> Tea...
module Encoder = struct open Web type t = Json . t let encode indentLevel value = Web . Json . string_of_json ~ indent : indentLevel ( Js . Undefined . return value ) let string ( v : string ) = Json . of_type Json . String v let int ( v : int ) = Json . of_type Json . Number ( float_of_int v ) let float ( v : float ) ...
type ( ' flags , ' model , ' msg ) navigationProgram = { init : ' flags -> Web . Location . location -> ' model * ' msg Tea_cmd . t ; update : ' model -> ' msg -> ' model * ' msg Tea_cmd . t ; view : ' model -> ' msg Vdom . t ; subscriptions : ' model -> ' msg Tea_sub . t ; shutdown : ' model -> ' msg Tea_cmd . t }
let getLocation ( ) = Web . Location . asRecord ( Web . Document . location ( ) )
let notifier : ( Web . Location . location -> unit ) option ref = ref None
let notifyUrlChange ( ) = match ! notifier with | None -> ( ) | Some cb -> let location = getLocation ( ) in let ( ) = cb location in ( )
let subscribe tagger = let open Vdom in let enableCall callbacks = let notifyHandler location = callbacks . enqueue ( tagger location ) in let ( ) = notifier := Some notifyHandler in let handler : Web . Node . event_cb = fun [ @ bs ] _event -> notifyUrlChange ( ) in let ( ) = Web . Window . addEventListener " popstate ...
let replaceState url = let _ = Web . Window . History . replaceState Web . Window . window ( Js . Json . parseExn " { } " ) " " url in ( )
let pushState url = let _ = Web . Window . History . pushState Web . Window . window ( Js . Json . parseExn " { } " ) " " url in ( )
let modifyUrl url = Tea_cmd . call ( fun _enqueue -> let ( ) = replaceState url in let ( ) = notifyUrlChange ( ) in ( ) )
let newUrl url = Tea_cmd . call ( fun _enqueue -> let ( ) = pushState url in let ( ) = notifyUrlChange ( ) in ( ) )
let navigationProgram locationToMessage stuff = let init flag = stuff . init flag ( getLocation ( ) ) in let subscriptions model = Tea_sub . batch [ subscribe locationToMessage ; stuff . subscriptions model ] in let open ! Tea_app in program { init = init ; update = stuff . update ; view = stuff . view ; subscriptions ...
type ' msg processMsg = | PushMsg of ' msg | Kill
let spawn initState update shutdown = let state = ref ( Some initState ) in let onMessage procMsg = match ! state with | None -> ( ) | Some model -> ( match procMsg with | PushMsg msg -> let ( ) = state := ( update model msg ) in ( ) | Kill -> let ( ) = shutdown model in let ( ) = state := None in ( ) ) in onMessage
module type Process = sig type msg val handleMsg : msg -> unit end
let ( ) = Random . self_init ( )
type ' typ t = | Generator of ( Random . State . t -> ' typ )
let bool = Generator ( fun state -> Random . State . bool state )
let int min max = Generator ( fun state -> min + Random . State . int state max )
let float min max = Generator ( fun state -> min . + Random . State . float state max )
let list count ( Generator genCmd ) = let rec buildList state i = if i > 0 then ( genCmd state ) ( :: buildList state ( i - 1 ) ) else [ ] in Generator ( fun state -> buildList state count )
let map func ( Generator genCmd ) = Generator ( fun state -> func ( genCmd state ) )
let map2 func ( Generator genCmd1 ) ( Generator genCmd2 ) = Generator ( fun state -> let res1 = genCmd1 state in let res2 = genCmd2 state in func res1 res2 )
let map3 func ( Generator genCmd1 ) ( Generator genCmd2 ) ( Generator genCmd3 ) = Generator ( fun state -> let res1 = genCmd1 state in let res2 = genCmd2 state in let res3 = genCmd3 state in func res1 res2 res3 )
let map4 func ( Generator genCmd1 ) ( Generator genCmd2 ) ( Generator genCmd3 ) ( Generator genCmd4 ) = Generator ( fun state -> let res1 = genCmd1 state in let res2 = genCmd2 state in let res3 = genCmd3 state in let res4 = genCmd4 state in func res1 res2 res3 res4 )
let map5 func ( Generator genCmd1 ) ( Generator genCmd2 ) ( Generator genCmd3 ) ( Generator genCmd4 ) ( Generator genCmd5 ) = Generator ( fun state -> let res1 = genCmd1 state in let res2 = genCmd2 state in let res3 = genCmd3 state in let res4 = genCmd4 state in let res5 = genCmd5 state in func res1 res2 res3 res4 res5...
let andThen func ( Generator genCmd ) = Generator ( fun state -> let res = genCmd state in let ( Generator userGen ) = func res in userGen state )
let pair gen1 gen2 = map2 ( fun a b -> a , b ) gen1 gen2
let generate tagger ( Generator genCmd ) = Tea_cmd . call ( fun callbacks -> let state = Random . get_state ( ) in let genValue = genCmd state in let ( ) = Random . set_state state in let open Vdom in ! callbacks . enqueue ( tagger genValue ) )
type seed = | Seed of Random . State . t
let step ( Generator genCmd ) ( Seed state ) = let newState = Random . State . copy state in genCmd newState , Seed newState
let initialSeed seed = Seed ( Random . State . make [ | seed ] ) |
type ( ' a , ' b ) t = ( ' a , ' b ) result = | Ok of ' a | Error of ' b
let result_to_option = function | Ok a -> Some a | Error _ -> None
let option_of_result = function | Ok a -> Some a | Error _ -> None
let ok = function | Ok a -> Some a | Error _ -> None
let error = function | Ok _ -> None | Error e -> Some e
let rec last_of = function | [ ] -> failwith " ` Tea . Result . do ` must never be passed the empty list " | [ last ] -> last | next :: tl -> match next with | Error _ as e -> e | Ok _ -> last_of tl
let rec accumulate = function | [ ] -> Ok [ ] | [ last ] -> begin match last with | Error _ as e -> e | Ok o -> Ok [ o ] end | next :: tl -> match next with | Error _ as e -> e | Ok o -> match accumulate tl with | Error _ as e -> e | Ok os -> Ok ( o :: os )
let first fst = function | Error _ as e -> e | Ok _ -> fst
let rec error_of_any = function | [ ] -> None | hd :: tl -> match hd with | Error e -> Some e | Ok _ -> error_of_any tl
let error_of_first fst = function | Error e -> Some e | Ok _ -> error fst
type ' msg t = | NoSub : _ t | Batch : ' msg t list -> ' msg t | Registration : string * ( ' msg Vdom . applicationCallbacks ref -> ( unit -> unit ) ) * ( unit -> unit ) option ref -> ' msg t | Mapper : ( ' msg Vdom . applicationCallbacks ref -> ' msgB Vdom . applicationCallbacks ref ) * ' msgB t -> ' msg t
type ' msg applicationCallbacks = ' msg Vdom . applicationCallbacks
let batch subs = Batch subs
let registration key enableCall = Registration ( key , ( fun callbacks -> enableCall ! callbacks ) , ref None )
let map msgMapper sub = let open Vdom in let func callbacks = ref { enqueue = ( fun userMsg -> ! callbacks . enqueue ( msgMapper userMsg ) ) } in Mapper ( func , sub )
let mapFunc func sub = Mapper ( func , sub )
let rec run : type msgOld msgNew . msgOld Vdom . applicationCallbacks ref -> msgNew Vdom . applicationCallbacks ref -> msgOld t -> msgNew t -> msgNew t = fun oldCallbacks newCallbacks oldSub newSub -> let rec enable : type msg . msg Vdom . applicationCallbacks ref -> msg t -> unit = fun callbacks -> function | NoSub ->...
let text str = text str
let lazy1 key gen = lazyGen key gen
let node tagName ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace tagName key unique props nodes
let svg ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " svg " key unique props nodes
let foreignObject ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " foreignObject " key unique props nodes
let animate ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " animate " key unique props nodes
let animateColor ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " animateColor " key unique props nodes
let animateMotion ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " animateMotion " key unique props nodes
let animateTransform ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " animateTransform " key unique props nodes
let mpath ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " mpath " key unique props nodes
let set ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " set " key unique props nodes
let a ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " a " key unique props nodes
let defs ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " defs " key unique props nodes
let g ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " g " key unique props nodes
let marker ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " marker " key unique props nodes
let mask ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " mask " key unique props nodes
let missingGlyph ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " missingGlyph " key unique props nodes
let pattern ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " pattern " key unique props nodes
let switch ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " switch " key unique props nodes
let symbol ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " symbol " key unique props nodes
let desc ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " desc " key unique props nodes
let metadata ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " metadata " key unique props nodes
let title ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " title " key unique props nodes
let feBlend ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feBlend " key unique props nodes
let feColorMatrix ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feColorMatrix " key unique props nodes
let feComponentTransfer ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feComponentTransfer " key unique props nodes
let feComposite ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feComposite " key unique props nodes
let feConvolveMatrix ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feConvolveMatrix " key unique props nodes
let feDiffuseLighting ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feDiffuseLighting " key unique props nodes
let feDisplacementMap ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feDisplacementMap " key unique props nodes
let feFlood ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feFlood " key unique props nodes
let feFuncA ( ? key " " ) = ( ? unique " " ) = props nodes = fullnode svgNamespace " feFuncA " key unique props nodes