unsubscribe static method

dynamic unsubscribe(
  1. dynamic value
)

Implementation

static unsubscribe(value) {
  bool isTopic = value is String && messages.containsKey(value);
  bool isToken = !isTopic && value is String;
  bool isFunction = value is Function;

  if (isTopic) {
    EventEmitter.clear(value);
    return;
  }

  if (isFunction && !messages.containsValue(value)) {
    print('[warn]: unable unsubscribe, no found subscribe: $value');
    return;
  }

  messages.forEach((_, message) {
    if (isToken) {
      message.remove(value);
    }

    if (isFunction) {
      message.removeWhere((_, fn) => fn == value);
    }
  });
}