EventCallback<T> typedef

T EventCallback (
  1. [dynamic]

EventCallback typedef to assist in enforcing the callback style needed for the EventEmitter library to work properly.

All event callbacks MUST have the following items:

  1. It must have, at least, a single dynamic param, enclosed within an optional positional list, with a minimum of a data parameter.
  • If you are not adding your own param, data should be added as the only argument in the optional param list, held within an unnamed optional list. You may use the data param as you wish - it will be resolved to the eventId that you assign to each Listener- or leave it alone. See example below.
  • If you are adding your own param, data should be added as the LASTelement in the param List. Again, you may use it as you wish, or leave it be. The library processes it as if you are using it, so it should be accounted for in your EventCallback function creation.
  • The library uses Function.hashCode to register and search for Listener's so that each Listener can be removed if and when required. For this reason, an anonymous Function without being assigned to a named variable cannot be used.
  1. Your placeholder params should not be statically typed.
  • In order to use the typedef, we cannot statically type the individual List params.

Example EventCallback Function's:

EventCallback<void> test = ([data]){ // no user-defined param
  print('Hello World!');

EventCallback<void> test_2 = ([counter,data]){ // a single user-defined param
  print('$data has been called $counter times');


typedef EventCallback<T> = T Function([dynamic]);