Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file node.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304openBaseopenJs_of_ocamltypevirtual_dom_nodetypevirtual_dom_patchclasstypevirtual_dom=objectmethod_VNode:(Js.js_stringJs.t-><>Js.t->virtual_dom_nodeJs.tJs.js_arrayJs.t->Js.js_stringJs.tJs.optdef->virtual_dom_nodeJs.t)Js.constrJs.readonly_propmethod_VText:(Js.js_stringJs.t->virtual_dom_nodeJs.t)Js.constrJs.readonly_propmethodcreateElement:virtual_dom_nodeJs.t->Dom_html.elementJs.tJs.methmethoddiff:virtual_dom_nodeJs.t->virtual_dom_nodeJs.t->virtual_dom_patchJs.tJs.methmethodpatch:Dom_html.elementJs.t->virtual_dom_patchJs.t->Dom_html.elementJs.tJs.methmethodsvg:(Js.js_stringJs.t-><>Js.t->virtual_dom_nodeJs.tJs.js_arrayJs.t->Js.js_stringJs.tJs.optdef->virtual_dom_nodeJs.t)Js.constrJs.readonly_propendletvirtual_dom:virtual_domJs.t=Js.Unsafe.global##.VirtualDommoduleWidget=structclasstype['s,'element]widget=objectconstraint'element=#Dom_html.elementJs.tmethodtype_:Js.js_stringJs.tJs.writeonly_prop(* virtual-dom considers two widgets of being of the same "kind" if either
of the following holds:
1. They both have a "name" attribute and their "id" fields are equal.
(I think this is probably a bug in virtual-dom and have field an issue
on github: [https://github.com/Matt-Esch/virtual-dom/issues/380])
2. Their [init] methods are "===" equal. This is true when using virtual-dom
widgets in the usual style in Javascript, since the [init] method will be defined
on a prototype, but is not true in this binding as it is redefined for each
call to [widget].
So, we go with option 1 and must have a trivial field called [name].
*)methodname:unitJs.writeonly_propmethodid:('s*'element)Type_equal.Id.tJs.propmethodstate:'sJs.propmethoddestroy:('element->unit)Js.callbackJs.writeonly_propmethodupdate:(('other_state,'other_element)widgetJs.t->'element->'element)Js.callbackJs.writeonly_propmethodinit:(unit->'element)Js.callbackJs.writeonly_propend(* We model JS level objects here so there is a lot of throwing away of type
information. We could possibly try to rediscover more of it. Or maybe we
should see if we can get rid Widget completely.
the unit type parameters here are not actually unit, but part of
the type info we have thrown away into our dance
with JS *)typet=(unit,Dom_html.elementJs.t)widgetJs.t(* here is how we throw away type information. Our good old friend Obj.magic,
but constrained a little bit *)externalt_of_widget:(_,_)widgetJs.t->t="%identity"letcreate(types)?(destroy:s->'element->unit=fun__->())?(update:s->'element->s*'element=funselt->s,elt)~(id:(s*'element)Type_equal.Id.t)~(init:unit->s*'element)()=letobj:(s,_)widgetJs.t=Js.Unsafe.obj[||]inobj##.type_:=Js.string"Widget";obj##.name:=();obj##.id:=id;obj##.init:=Js.wrap_callback(fun()->lets0,dom_node=init()inobj##.state:=s0;dom_node);obj##.update:=Js.wrap_callback(funprevdom_node->(* The [update] method of [obj] is only called by virtual-dom after it has checked
that the [id]s of [prev] and [obj] are "===" equal. Thus [same_witness_exn] will
never raise.
*)matchType_equal.Id.same_witness_exnprev##.ididwith|Type_equal.T->letstate',dom_node'=updateprev##.statedom_nodeinobj##.state:=state';dom_node');obj##.destroy:=Js.wrap_callback(fundom_node->destroyobj##.statedom_node);t_of_widgetobj;;externalto_js:t->virtual_dom_nodeJs.t="%identity"endmoduleT:sigmoduleElement:sigtypetvaltag:t->stringvalattrs:t->Attrs.tvalkey:t->stringoptionvalmap_attrs:t->f:(Attrs.t->Attrs.t)->tvaladd_class:t->string->tvaladd_style:t->Css_gen.t->tendtypet=|Textofstring|ElementofElement.t|WidgetofWidget.tvaltext:string->tvalwidget:?destroy:('s->(#Dom_html.elementas'e)Js.t->unit)->?update:('s->'eJs.t->'s*'eJs.t)->id:('s*'eJs.t)Type_equal.Id.t->init:(unit->'s*'eJs.t)->unit->tvalcreate:string->?key:string->Attr.tlist->tlist->tvalcreate_childless:string->?key:string->Attr.tlist->tvalsvg:string->?key:string->Attr.tlist->tlist->tvalto_js:t->virtual_dom_nodeJs.tend=structtypeelement={tag:string;key:stringoption;attrs:Attrs.t;children:virtual_dom_nodeJs.tlist;kind:[`Vnode|`Svg]}andt=|Textofstring|Elementofelement|WidgetofWidget.tmoduleElement=structtypet=elementlettagt=t.tagletattrst=t.attrsletkeyt=t.keyletmap_attrst~f={twithattrs=ft.attrs}letadd_classtc=map_attrst~f:(funa->Attrs.add_classac)letadd_stylets=map_attrst~f:(funa->Attrs.add_styleas)endletto_js=function|Texts->letvtext=virtual_dom##._VTextinnew%jsvtext(Js.strings)|Element{tag;key;attrs;children;kind=`Vnode}->letvnode=virtual_dom##._VNodein(matchkeywith|None->new%jsvnode(Js.stringtag)(Attr.list_to_objattrs)(Js.array(Array.of_listchildren))Js.Optdef.empty|Somekey->new%jsvnode(Js.stringtag)(Attr.list_to_objattrs)(Js.array(Array.of_listchildren))(Js.Optdef.return(Js.stringkey)))|Element{tag;key;attrs;children;kind=`Svg}->letvnode=virtual_dom##.svgin(matchkeywith|None->new%jsvnode(Js.stringtag)(Attr.list_to_objattrs)(Js.array(Array.of_listchildren))Js.Optdef.empty|Somekey->new%jsvnode(Js.stringtag)(Attr.list_to_objattrs)(Js.array(Array.of_listchildren))(Js.Optdef.return(Js.stringkey)))|Widgetw->Widget.to_jsw;;letelementkind~tag~keyattrschildren=letchildren=List.mapchildren~f:to_jsin{kind;tag;key;attrs;children};;lettexts=Textsletwidget?destroy?update~id~init()=Widget(Widget.create?destroy?update~id~init());;letcreatetag?keyattrschildren=Element(element`Vnode~tag~keyattrschildren)letcreate_childlesstag?keyattrs=createtag?keyattrs[]letsvgtag?keyattrschildren=Element(element`Svg~tag~keyattrschildren)endmoduleElement=T.Elementtypet=T.t=|Textofstring|ElementofElement.t|WidgetofWidget.tlettext=T.textletcreate=T.createletcreate_childless=T.create_childlessletwidget=T.widgetletsvg=T.svgtypenode_creator=?key:string->Attr.tlist->tlist->ttypenode_creator_childless=?key:string->Attr.tlist->tletto_domt:Dom_html.elementJs.t=virtual_dom##createElement(T.to_jst)leta=create"a"letbody=create"body"letbutton=create"button"letdiv=create"div"letfooter=create"footer"leth1=create"h1"leth2=create"h2"leth3=create"h3"leth4=create"h4"leth5=create"h5"letheader=create"header"lethtml=create"html"letinput=create"input"lettextarea=create"textarea"letselect=create"select"letoption=create"option"letlabel=create"label"letli=create"li"letp=create"p"letpre=create"pre"letsection=create"section"letspan=create"span"letstrong=create"strong"lettable=create"table"lettbody=create"tbody"lettd=create"td"letth=create"th"letthead=create"thead"lettr=create"tr"letul=create"ul"letbr=create_childless"br"lethr=create_childless"hr"modulePatch=structtypenode=ttypet=virtual_dom_patchJs.tletcreate~previous~current=virtual_dom##diff(T.to_jsprevious)(T.to_jscurrent)letapplytelt=virtual_dom##patchelttletis_empty=letf=Js.Unsafe.pure_js_expr{js|
(function (patch) {
for (var key in patch) {
if (key !== 'a') return false
}
return true
})
|js}infun(t:t)->Js.Unsafe.fun_callf[|Js.Unsafe.injectt|]|>Js.to_bool;;end