LCOV - code coverage report
Current view: top level - lib/src/components/mixins - has_game_ref.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 9 9 100.0 %
Date: 2021-08-10 15:50:53 Functions: 0 0 -

          Line data    Source code
       1             : import '../../../components.dart';
       2             : import '../../../game.dart';
       3             : 
       4             : mixin HasGameRef<T extends BaseGame> on Component {
       5             :   T? _gameRef;
       6             : 
       7           5 :   T get gameRef {
       8           5 :     final ref = _gameRef;
       9             :     if (ref == null) {
      10             :       throw 'Accessing gameRef before the component was added to the game!';
      11             :     }
      12             :     return ref;
      13             :   }
      14             : 
      15           6 :   bool get hasGameRef => _gameRef != null;
      16             : 
      17           6 :   set gameRef(T gameRef) {
      18           6 :     _gameRef = gameRef;
      19           6 :     if (this is BaseComponent) {
      20             :       // TODO(luan) this is wrong, should be done using propagateToChildren
      21             :       (this as BaseComponent)
      22           6 :           .children
      23           6 :           .query<HasGameRef>()
      24           6 :           .forEach((e) => e.gameRef = gameRef);
      25             :     }
      26             :   }
      27             : }

Generated by: LCOV version 1.15