on method

MPS on(
  1. String topic,
  2. Function? callback
)

Subscribe a function to a topic in the event system. If the callback is not already subscribed, adds it to the subscription list. Returns true if the function was added to the list, false if it was already subscribed.

Implementation

MPS on(String topic, Function? callback) {
  if (!_cache.containsKey(topic)) {
    _cache[topic] = [];
  }
  if (!_cache[topic]!.contains(callback)) {
    _cache[topic]!.add(callback);
  }
  return this;
}