package virtual_dom

  1. Overview
  2. Docs

Source file event_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(** The event type used for creating virtual-dom callbacks.

    The various kinds of handlers are registered by users of virtual dom, and allow them
    to pick up events that are scheduled by other users, without these use-cases
    interfering with each other.
*)

open Js_of_ocaml

module type Handler = sig
  module Action : sig
    type t
  end

  val handle : Action.t -> unit
end

module type Visibility_handler = sig
  val handle : unit -> unit
end

module type S = sig
  type action
  type t = private ..
  type t += C : action -> t

  val inject : action -> t
end

module type Event = sig
  type t = private ..

  type t +=
    | Ignore  (** [Ignore] events are dropped, so no handler is called *)
    | Viewport_changed
    (** [Viewport_changed] events are delivered to all visibility handlers  *)
    | Stop_propagation
    (** [Stop_propagation] prevents the underlying DOM event from propagating up to the
        parent elements *)
    | Prevent_default
    (** [Prevent_default] prevents the default browser action from occurring as a result
        of this event *)
    | Many of t list
    (** Allows one to represent a list of handlers, which will be individually dispatched
        to their respective handlers. This is so callbacks can return multiple events of
        whatever kind. *)

  module type Handler = Handler
  module type Visibility_handler = Visibility_handler
  module type S = S

  (** For registering a new handler and a corresponding new constructor of the Event.t
      type *)
  module Define (Handler : Handler) :
    S with type action := Handler.Action.t and type t := t

  (** For registering a handler for Viewport_changed events. Note that if this functor is
      called multiple times, each handler will see all of the events. *)
  module Define_visibility (VH : Visibility_handler) : sig end

  module Expert : sig
    (** [handle t] looks up the [Handler.handle] function in the table of [Define]d
        functions, unwraps the [Event.t] back into its underlying [Action.t], and applies
        the two.  This is only intended for internal use by this library, specifically by
        the attribute code. *)
    val handle : #Dom_html.event Js.t -> t -> unit

    (** [handle_non_dom_event_exn] is the same as [handle] except that it raises in any
        case that would have required the [#Dom_html.event Js.t]. In particular, this
        can be to feed Actions back to the system that are not triggered by events from
        the DOM and do not have a corresponding [#Dom_html.event Js.t]. *)
    val handle_non_dom_event_exn : t -> unit
  end
end
OCaml

Innovation. Community. Security.