1234567891011121314151617181920212223242526272829303132333435363738394041424344454647open!Core_kernelincludeUi_event_intftypet=..typet+=Ignore|Manyoftlist(* We use this table for dispatching to the appropriate handler in an efficient way. *)lethandlers:(t->unit)Hashtbl.M(Int).t=Hashtbl.create(moduleInt)~size:8moduleObj=structmoduleExtension_constructor=struct[@@@ocaml.warning"-3"]letid=Caml.Obj.extension_idletof_val=Caml.Obj.extension_constructorendendmoduleDefine(Handler:Handler):Swithtypeaction:=Handler.Action.tandtypet:=t=structtypet+=C:Handler.Action.t->tletkey=Obj.Extension_constructor.id[%extension_constructorC]let()=Hashtbl.add_exnhandlers~key~data:(funinp->matchinpwith|Cvalue->Handler.handlevalue|_->raise_s[%message"Unrecognized variant"]);;letinjectv=Cvendletget_keyt=Obj.Extension_constructor.id(Obj.Extension_constructor.of_valt)lethandle_registered_eventt=Hashtbl.find_exnhandlers(get_keyt)tmoduleExpert=structletrechandlet=matchtwith|Ignore->()|Manyl->List.iter~f:handlel|t->handle_registered_eventt;;lethandlers=handlersend