subscribe method

SubscriptionKey subscribe(
  1. Iterable<String> match,
  2. void onData(
    1. String? ref,
    2. Map data
    ), {
  3. String? key,
})
inherited

Implementation

SubscriptionKey subscribe(Iterable<String> match,
  void Function(String? ref, Map<T?,T?> data) onData, {String? key})
{
  final subscriptionKey = SubscriptionKey(key ?? _uuid.v4(), match);

  if(!_listeners.containsKey(subscriptionKey))
  {
    _listeners[subscriptionKey] =_controller.stream
        .where((event)=>subscriptionKey.regexp
          .where((reg)=>reg.hasMatch(event.ref!)).isNotEmpty)
            .listen((NukeEvent event)=>
              onData(event.ref, event.data as Map<T?,T?>));
  }

  return subscriptionKey;
}