Racket Rx
1 Event Helpers
event%
get-timestamp
2 Event Emitter
add-listener!
remove-listener!
trigger
3 Event Streams
event-stream-filter
event-stream-map
event-stream-merge
7.1

Racket Rx

Racket Rx is a set of utilities and classes for reactive programming. The modules are layered based upon their level of abstraction. For instance, rx/event-stream builds on top of rx/event-emitter, while rx/gui uses both modules, and so on.

1 Event Helpers

 (require rx/event) package: rx

class

event% : class?

  superclass: object%

This is a convenience class for quickly implementing custom events. Though in no way neccessary, it can be used as a common base for quickly distinguishing events from other values.

method

(send an-event get-timestamp)  integer?

Get the current timestamp, in milliseconds, of when the event was created.

2 Event Emitter

An event emitter is a simple class that is able to broadcast events to its associated event listeners.

 (require rx/event-emitter) package: rx

procedure

(add-listener! ee callback)  void?

  ee : event-emitter?
  callback : procedure?
Registers callback with the given event emitter, so that subsequent triggers of the emitter will result in this callback being called.

procedure

(remove-listener! ee callback)  void?

  ee : event-emitter?
  callback : procedure?
Unregisters callbac from the given emitter, so that subsequent trigger of the emitter will not result in the callback being called.

procedure

(trigger ee arg ...)  void?

  ee : event-emitter?
  arg : any?
Broadcasts an event specified by the given arguments to all of its listeners. The listeners are called with the arguments that were passed to this function.

As a matter of convenience, it is common to only pass one argument to this function, which in itself is a composite structure or class.

3 Event Streams

 (require rx/event-stream) package: rx

procedure

(event-stream-filter es pred)  event-stream?

  es : event-stream?
  pred : (-> any/c bool/c)
Creates a new event stream that filters events that are passed through the original stream on the given predicate.

See also #f.

procedure

(event-stream-map es proc)  event-stream?

  es : event-stream?
  proc : (-> any/c any/c)
Creates a new event stream that maps values that are passed through the original stream using the given procedure.

See also #f.

procedure

(event-stream-merge es ...)  event-stream?

  es : event-stream?
Merges the given event streams into one new big stream.