globalWatch<T> function

Rx<T> globalWatch<T>(
  1. T v, {
  2. Object? tag,
})

Create a watched variable from the variable v, a proxy object of the Type of Rx<T>

Implementation

Rx<T> globalWatch<T>(T v, {Object? tag}) {
  final rx = Rx.withPub(v, _globalPub);

  //* Check if the variable [Type] or the [tag] already exists
  if (tag == null) {
    if (!_globalWatchedVar.containsKey(T)) {
      _globalWatchedVar[T] = rx;
      assert(() {
        debugPrint('Info: global watched variable of type: $T');
        return true;
      }());
    }
    /*
    else {
      assert(() {
        print('Info: Global watched variable of Type: $T already exists.');
        print(
            'If the watched variable would be used across files, please use the [tag] parameter.');
        return true;
      }());
    }
    */
  } else {
    if (!_globalWatchedVar.containsKey(tag)) {
      _globalWatchedVar[tag] = rx;
    } else {
      throw FlutterError(
          'Error: Global watched variable of tag:$tag already exists.');
    }
  }

  return rx;
}