more events
play

More Events CS 51 and CSCI E-51 April 5, 2014 . Road map The - PowerPoint PPT Presentation

Supplementary Video: More Events CS 51 and CSCI E-51 April 5, 2014 . Road map The concept Using events Implementation of events UI events 2:1 The concept 3:1 The concept 3:2 The concept 3:3 The concept 3:4 The concept


  1. Supplementary Video: More Events CS 51 and CSCI E-51 April 5, 2014 .

  2. Road map • The concept • Using events • Implementation of events • UI events 2:1

  3. The concept 3:1

  4. The concept 3:2

  5. The concept 3:3

  6. The concept 3:4

  7. The concept 3:5

  8. The concept 3:6

  9. The concept 3:7

  10. The concept 3:8

  11. The concept 3:9

  12. Basic event primitives . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:1

  13. Basic event primitives . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:2

  14. Basic event primitives . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:3

  15. Basic event primitives . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:4

  16. Basic event primitives . . . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:5

  17. Basic event primitives . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:6

  18. Basic event primitives . . . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:7

  19. Basic event primitives . . . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:8

  20. Basic event primitives . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:9

  21. Basic event primitives . . . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:10

  22. Basic event primitives . . . . . . . . . . . . . . . . . . module Event51 : sig type id type ’a event val new_event : unit -> ’a event val add_listener : ’a event -> (’a -> unit) -> id val fire_event : ’a event -> ’a -> unit val add_one_shot_listener : ’a event -> (’a -> unit) -> id val remove_listener : ’a event -> id -> unit · · · end 4:11

  23. — To Emacs —

  24. Event implementation . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:1

  25. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:2

  26. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:3

  27. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:4

  28. Event implementation . . . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:5

  29. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:6

  30. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:7

  31. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:8

  32. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:9

  33. Event implementation . . . . . . . . . . . . . . . . type ’a waiter = { id : id; action : ’a -> unit } type ’a event = ’a waiter list ref let new_event () : ’a event = ref [] let add_listener ( e : ’a event) ( f : ’a -> unit) : id = let i = new_id () in e := { id = i; action = f } :: !e; i let fire_event ( e : ’a event) ( v : ’a) : unit = List.iter !e ~f:( fun w -> w.action v) 6:10

Recommend


More recommend