LCOV - code coverage report
Current view: top level - src/rx - rx_event.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 17 17 100.0 %
Date: 2020-07-01 03:00:01 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:get/get.dart';
       2             : import 'rx_interface.dart';
       3             : import 'utils/debouncer.dart';
       4             : 
       5           1 : void ever(RxInterface listener, Function(dynamic) callback,
       6             :     {bool condition = true}) {
       7           4 :   listener.subject.stream.listen((event) {
       8             :     if (condition) {
       9           1 :       callback(event);
      10             :     }
      11             :   });
      12             : }
      13             : 
      14           1 : void once(RxInterface listener, Function(dynamic) callback,
      15             :     {bool condition = true}) {
      16             :   int times = 0;
      17           4 :   listener.subject.stream.listen((event) {
      18             :     if (!condition) return null;
      19           1 :     times++;
      20           1 :     if (times < 2) {
      21           1 :       callback(event);
      22             :     }
      23             :   });
      24             : }
      25             : 
      26           1 : void interval(RxInterface listener, Function(dynamic) callback,
      27             :     {Duration time, bool condition = true}) {
      28             :   bool debounceActive = false;
      29           4 :   listener.subject.stream.listen((event) async {
      30             :     if (debounceActive || !condition) return null;
      31             :     debounceActive = true;
      32           2 :     await Future.delayed(time ?? Duration(seconds: 1));
      33             :     debounceActive = false;
      34           1 :     callback(event);
      35             :   });
      36             : }
      37             : 
      38           1 : void debounce(RxInterface listener, Function(dynamic) callback,
      39             :     {Duration time}) {
      40           1 :   final _debouncer = Debouncer(delay: time ?? Duration(milliseconds: 800));
      41           4 :   listener.subject.stream.listen((event) {
      42           2 :     _debouncer(() {
      43           1 :       callback(event);
      44             :     });
      45             :   });
      46             : }

Generated by: LCOV version 1.14