attach method

Object attach(
  1. Function listener
)

Attaches a function that will be executed when notify() is called.

Returns a key object that can be used to detach the listener from the notifier to stop execution on notify() call and avoid memory leaks.

Implementation

Object attach(Function listener) {
  final key = Object();
  _listeners[key] = listener;
  return key;
}