Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file React.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668typedomReftype'valueref={mutablecurrent:'value}moduleRef=structtypet=domReftypecurrentDomRef=Dom.elementJs.nullablereftypecallbackDomRef=Dom.elementJs.nullable->unitexternaldomRef:currentDomRef->domRef="%identity"externalcallbackDomRef:callbackDomRef->domRef="%identity"endletcreateRef()={current=None}letuseRefvalue={current=value}letforwardReff=f()moduleEvent=structtype'asyntheticmoduleMakeEventWithType(Type:sigtypetend)=structletbubbles:Type.t->bool=fun_->falseletcancelable:Type.t->bool=fun_->falseletcurrentTarget:Type.t-><..>Js.t=fun_->objectendletdefaultPrevented:Type.t->bool=fun_->falseleteventPhase:Type.t->int=fun_->0letisTrusted:Type.t->bool=fun_->falseletnativeEvent:Type.t-><..>Js.t=fun_->objectendletpreventDefault:Type.t->unit=fun_->()letisDefaultPrevented:Type.t->bool=fun_->falseletstopPropagation:Type.t->unit=fun_->()letisPropagationStopped:Type.t->bool=fun_->falselettarget:Type.t-><..>Js.t=fun_->objectendlettimeStamp:Type.t->float=fun_->0.lettype_:Type.t->string=fun_->""letpersist:Type.t->unit=fun_->()endmoduleSynthetic=structtypetagtypet=tagsyntheticletbubbles:'asynthetic->bool=fun_->falseletcancelable:'asynthetic->bool=fun_->falseletcurrentTarget:'asynthetic-><..>Js.t=fun_->objectendletdefaultPrevented:'asynthetic->bool=fun_->falseleteventPhase:'asynthetic->int=fun_->0letisTrusted:'asynthetic->bool=fun_->falseletnativeEvent:'asynthetic-><..>Js.t=fun_->objectendletpreventDefault:'asynthetic->unit=fun_->()letisDefaultPrevented:'asynthetic->bool=fun_->falseletstopPropagation:'asynthetic->unit=fun_->()letisPropagationStopped:'asynthetic->bool=fun_->falselettarget:'asynthetic-><..>Js.t=fun_->objectendlettimeStamp:'asynthetic->float=fun_->0.lettype_:'asynthetic->string=fun_->""letpersist:'asynthetic->unit=fun_->()end(* let toSyntheticEvent : 'a synthetic -> Synthetic.t = i -> i *)moduleClipboard=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letclipboardData:t-><..>Js.t=fun_->objectendendmoduleComposition=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdata:t->string=fun_->""endmoduleKeyboard=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletcharCode:t->int=fun_->0letctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletkey:t->string=fun_->""letkeyCode:t->int=fun_->0letlocale:t->string=fun_->""letlocation:t->int=fun_->0letmetaKey:t->bool=fun_->falseletrepeat:t->bool=fun_->falseletshiftKey:t->bool=fun_->falseletwhich:t->int=fun_->0endmoduleFocus=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letrelatedTarget:t-><..>Js.toption=fun_->NoneendmoduleForm=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleMouse=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletbutton:t->int=fun_->0letbuttons:t->int=fun_->0letclientX:t->int=fun_->0letclientY:t->int=fun_->0letctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletmetaKey:t->bool=fun_->falseletmovementX:t->int=fun_->0letmovementY:t->int=fun_->0letpageX:t->int=fun_->0letpageY:t->int=fun_->0letrelatedTarget:t-><..>Js.toption=fun_->NoneletscreenX:t->int=fun_->0letscreenY:t->int=fun_->0letshiftKey:t->bool=fun_->falseendmodulePointer=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdetail:t->int=fun_->0(* let view : t -> Dom.window = fun _ -> object end *)letscreenX:t->int=fun_->0letscreenY:t->int=fun_->0letclientX:t->int=fun_->0letclientY:t->int=fun_->0letpageX:t->int=fun_->0letpageY:t->int=fun_->0letmovementX:t->int=fun_->0letmovementY:t->int=fun_->0letctrlKey:t->bool=fun_->falseletshiftKey:t->bool=fun_->falseletaltKey:t->bool=fun_->falseletmetaKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletbutton:t->int=fun_->0letbuttons:t->int=fun_->0letrelatedTarget:t-><..>Js.toption=fun_->None(* let pointerId : t -> Dom.eventPointerId *)letwidth:t->float=fun_->0.letheight:t->float=fun_->0.letpressure:t->float=fun_->0.lettangentialPressure:t->float=fun_->0.lettiltX:t->int=fun_->0lettiltY:t->int=fun_->0lettwist:t->int=fun_->0letpointerType:t->string=fun_->""letisPrimary:t->bool=fun_->falseendmoduleSelection=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleTouch=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletchangedTouches:t-><..>Js.t=fun_->objectendletctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletmetaKey:t->bool=fun_->falseletshiftKey:t->bool=fun_->falselettargetTouches:t-><..>Js.t=fun_->objectendlettouches:t-><..>Js.t=fun_->objectendendmoduleUI=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdetail:t->int=fun_->0(* let view : t -> Dom.window *)endmoduleWheel=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdeltaMode:t->int=fun_->0letdeltaX:t->float=fun_->0.letdeltaY:t->float=fun_->0.letdeltaZ:t->float=fun_->0.endmoduleMedia=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleImage=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleAnimation=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letanimationName:t->string=fun_->""letpseudoElement:t->string=fun_->""letelapsedTime:t->float=fun_->0.endmoduleTransition=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letpropertyName:t->string=fun_->""letpseudoElement:t->string=fun_->""letelapsedTime:t->float=fun_->0.endmoduleDrag=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletbutton:t->int=fun_->0letbuttons:t->int=fun_->0letclientX:t->int=fun_->0letclientY:t->int=fun_->0letctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletmetaKey:t->bool=fun_->falseletmovementX:t->int=fun_->0letmovementY:t->int=fun_->0letpageX:t->int=fun_->0letpageY:t->int=fun_->0letrelatedTarget:t-><..>Js.toption=fun_->NoneletscreenX:t->int=fun_->0letscreenY:t->int=fun_->0letshiftKey:t->bool=fun_->falseletdataTransfer:t-><..>Js.toption=fun_->NoneendendmoduleJSX=structtypeevent=|Dragof(Event.Drag.t->unit)|Mouseof(Event.Mouse.t->unit)|Selectionof(Event.Selection.t->unit)|Touchof(Event.Touch.t->unit)|UIof(Event.UI.t->unit)|Wheelof(Event.Wheel.t->unit)|Clipboardof(Event.Clipboard.t->unit)|Compositionof(Event.Composition.t->unit)|Transitionof(Event.Transition.t->unit)|Animationof(Event.Animation.t->unit)|Pointerof(Event.Pointer.t->unit)|Keyboardof(Event.Keyboard.t->unit)|Focusof(Event.Focus.t->unit)|Formof(Event.Form.t->unit)|Mediaof(Event.Media.t->unit)|Inlineofstringtypeprop=|Boolof(string*bool)|Stringof(string*string)|Styleofstring|DangerouslyInnerHtmlofstring|RefofRef.t|Eventofstring*eventletboolkeyvalue=Bool(key,value)letstringkeyvalue=String(key,value)letstylevalue=Stylevalueletintkeyvalue=String(key,string_of_intvalue)letfloatkeyvalue=String(key,string_of_floatvalue)letdangerouslyInnerHtmlvalue=DangerouslyInnerHtmlvalue#__htmlletrefvalue=Refvalueleteventkeyvalue=Event(key,value)moduleEvent=structletdragkeyvalue=eventkey(Dragvalue)letmousekeyvalue=eventkey(Mousevalue)letselectionkeyvalue=eventkey(Selectionvalue)lettouchkeyvalue=eventkey(Touchvalue)letuikeyvalue=eventkey(UIvalue)letwheelkeyvalue=eventkey(Wheelvalue)letclipboardkeyvalue=eventkey(Clipboardvalue)letcompositionkeyvalue=eventkey(Compositionvalue)lettransitionkeyvalue=eventkey(Transitionvalue)letanimationkeyvalue=eventkey(Animationvalue)letpointerkeyvalue=eventkey(Pointervalue)letkeyboardkeyvalue=eventkey(Keyboardvalue)letfocuskeyvalue=eventkey(Focusvalue)letformkeyvalue=eventkey(Formvalue)letmediakeyvalue=eventkey(Mediavalue)endendtypelower_case_element={tag:string;attributes:JSX.proplist;children:elementlist;}andelement=|Lower_case_elementoflower_case_element|Upper_case_componentof(unit->element)|Listofelementarray|Textofstring|InnerHtmlofstring|Fragmentofelement|Empty|Providerofelement|Consumerofelement|Suspenseof{children:element;fallback:element}exceptionInvalid_childrenofstringletcompare_attributeleftright=match(left,right)with|JSX.Bool(left_key,_),JSX.Bool(right_key,_)->String.compareleft_keyright_key|String(left_key,_),String(right_key,_)->String.compareleft_keyright_key|Styleleft_styles,Styleright_styles->String.compareleft_stylesright_styles|_->0letclone_attributeaccattrnew_attr=letopenJSXinmatch(attr,new_attr)with|Bool(left,_),Bool(right,value)whenleft==right->Bool(left,value)::acc|String(left,_),String(right,value)whenleft==right->String(left,value)::acc|_->new_attr::accmoduleStringMap=Map.Make(String)letattributes_to_mapattributes=letopenJSXinList.fold_left(funaccattr->matchattrwith|Bool(key,value)->acc|>StringMap.addkey(Bool(key,value))|String(key,value)->acc|>StringMap.addkey(String(key,value))(* The following constructors shoudn't be part of the Map: *)|DangerouslyInnerHtml_->acc|Ref_->acc|Event_->acc|Style_->acc)StringMap.emptyattributesletclone_attributesattributesnew_attributes=letattribute_map=attributes_to_mapattributesinletnew_attribute_map=attributes_to_mapnew_attributesinStringMap.merge(fun_keyattrnew_attr->match(attr,new_attr)with|Someattr,Somenew_attr->Some(clone_attribute[]attrnew_attr)|Someattr,None->Some[attr]|None,Somenew_attr->Some[new_attr]|None,None->None)attribute_mapnew_attribute_map|>StringMap.bindings|>List.map(fun(_,attrs)->attrs)|>List.flatten|>List.rev|>List.sortcompare_attributeletcreate_element_innertagattributeschildren=letdangerouslySetInnerHTML=List.find_opt(functionJSX.DangerouslyInnerHtml_->true|_->false)attributesinletchildren=match(dangerouslySetInnerHTML,children)with|None,children->children|Some(JSX.DangerouslyInnerHtmlinnerHtml),[]->(* This adds as children the innerHTML, and we treat it differently
from Element.Text to avoid encoding to HTML their content *)[InnerHtmlinnerHtml]|Some_,_children->raise(Invalid_childrentag)inLower_case_element{tag;attributes;children}letcreateElementtagattributeschildren=matchHtml.is_self_closing_tagtagwith|truewhenList.lengthchildren>0->(* TODO: Add test for this *)raise@@Invalid_children"closing tag with children isn't valid"|true->Lower_case_element{tag;attributes;children=[]}|false->create_element_innertagattributeschildren(* cloneElements overrides childrens but is not always obvious what to do with
Provider, Consumer or Suspense. TODO: Check original (JS) implementation *)letcloneElementelementnew_attributes=matchelementwith|Lower_case_element{tag;attributes;children}->Lower_case_element{tag;attributes=clone_attributesattributesnew_attributes;children;}|Fragment_childrens->Fragment_childrens|Textt->Textt|InnerHtmlt->InnerHtmlt|Empty->Empty|Listl->Listl|Providerchild->Providerchild|Consumerchild->Consumerchild|Upper_case_componentf->Upper_case_componentf|Suspense{fallback;children}->Suspense{fallback;children}moduleFragment=structletmake~children?key:_()=Fragmentchildrenendletfragmentchildren=Fragment.make~children?key:None()(* ReasonReact APIs *)letstringtxt=Texttxtletnull=Emptyletinti=Text(string_of_inti)(* FIXME: float_of_string might be different from the browser *)letfloatf=Text(string_of_floatf)letarrayarr=Listarrletlist_to_arraylist=letrecto_arrayires=matchi<0with|true->res|false->letitem=List.nthlistiinletrest=Array.append[|item|]resinto_array(i-1)restinto_array(List.lengthlist-1)[||]letlistl=List(list_to_arrayl)type'aprovider=value:'a->children:element->unit->elementtype'acontext={current_value:'aref;provider:'aprovider;consumer:children:element->element;}moduleContext=structtype'at='acontextletproviderctx=ctx.providerendletcreateContext(initial_value:'a):'aContext.t=letref_value={current=initial_value}inletprovider~value~children()=ref_value.current<-value;Providerchildreninletconsumer~children=Consumerchildrenin{current_value=ref_value;provider;consumer}moduleSuspense=structletor_react_null=functionNone->null|Somex->xletmake?fallback?children()=Suspense{fallback=or_react_nullfallback;children=or_react_nullchildren}end(* let memo f : 'props * 'props -> bool = f
let memoCustomCompareProps f _compare : 'props * 'props -> bool = f *)letuseContextcontext=context.current_value.currentletuseState(make_initial_value:unit->'state)=letinitial_value:'state=make_initial_value()inletsetState(fn:'state->'state)=let_=fninitial_valuein()in(initial_value,setState)letinternal_id=ref0letuseId()=internal_id:=!internal_id+1;Int.to_string!internal_idletuseMemofn=fn()letuseMemo0fn=fn()letuseMemo1fn_=fn()letuseMemo2fn_=fn()letuseMemo3fn_=fn()letuseMemo4fn_=fn()letuseMemo5fn_=fn()letuseMemo6fn_=fn()letuseCallbackfn=fnletuseCallback0fn=fnletuseCallback1fn_=fnletuseCallback2fn_=fnletuseCallback3fn_=fnletuseCallback4fn_=fnletuseCallback5fn_=fnletuseCallback6fn_=fnletuseReducer_s=(s,fun_->())letuseReducerWithMapState_smapper=(mappers,fun_->())letuseEffect_=()letuseEffect0_=()letuseEffect1__=()letuseEffect2__=()letuseEffect3__=()letuseEffect4__=()letuseEffect5__=()letuseEffect6__=()letuseLayoutEffect0_=()letuseLayoutEffect1__=()letuseLayoutEffect2__=()letuseLayoutEffect3__=()letuseLayoutEffect4__=()letuseLayoutEffect5__=()letuseLayoutEffect6__=()moduleChildren=structletmapelementfn=matchelementwith|Listchildren->Array.mapfnchildren|>Array.to_list|>list|_->fnelementletmapWithIndexelementfn=matchelementwith|Listchildren->Array.mapi(funindexelement->fnelementindex)children|>Array.to_list|>list|_->fnelement0letforEachelementfn=matchelementwith|Listchildren->Array.iterfnchildren|_->let_=fnelementin()letforEachWithIndexelementfn=matchelementwith|Listchildren->Array.iteri(funindexelement->fnelementindex)children|_->let_=fnelement0in()letcountelement=matchelementwith|Listchildren->Array.lengthchildren|Empty->0|_->1letonlyelement=matchelementwith|Listchildren->ifArray.lengthchildren>=1thenArray.getchildren0elseraise(Invalid_argument"Expected at least one child")|_->elementlettoArrayelement=[|element|]endletsetDisplayName__=()letuseTransition()=(false,fun(_cb:unit->unit)->())letuseDebugValue:'value->?format:('value->string)->unit=fun[@warning"-16"]_?format:_->()letuseDeferredValuevalue=value(* `exception Suspend of 'a Lwt`
exceptions can't have type params, this is called existential wrapper *)typeany_promise=Any_promise:'aLwt.t->any_promiseexceptionSuspendofany_promisemoduleExperimental=structletusepromise=matchLwt.statepromisewith|Sleep->raise(Suspend(Any_promisepromise))(* TODO: Fail should raise a FailedSupense and catch at renderTo* *)|Faile->raisee|Returnv->vend