registerNotifier method

String registerNotifier({
  1. required Object controller,
  2. required NeuronAtom notifier,
  3. String? debugLabel,
  4. String kind = 'signal',
})

Implementation

String registerNotifier({
  required Object controller,
  required NeuronAtom notifier,
  String? debugLabel,
  String kind = 'signal',
}) {
  final controllerRecord = _controllers.putIfAbsent(
    controller,
    () => _ControllerRecord(controller),
  );

  final id = _buildId(controllerRecord, debugLabel, kind);
  final existing = _notifiers[id];
  if (existing != null) {
    _reverseLookup[notifier] = id;
    return id;
  }

  controllerRecord.notifierIds.add(id);

  final entry = _NotifierRecord(
    id: id,
    notifier: notifier,
    kind: kind,
    controllerName: controllerRecord.name,
    label: debugLabel,
  );

  _notifiers[id] = entry;
  _reverseLookup[notifier] = id;

  if (_enabled) {
    _attachListener(entry);
    _pushEvent(
      NeuronDebugEvent.register(
        id,
        entry.snapshotValue,
        meta: {
          'controller': controllerRecord.name,
          'kind': kind,
          if (debugLabel != null) 'label': debugLabel,
        },
      ),
    );
  }

  return id;
}