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

          Line data    Source code
       1             : /// Used for caching calculated values, the cache is determined to be valid by
       2             : /// comparing a list of values that can be of any type and is compared to the
       3             : /// values that was last used when the cache was updated.
       4             : class ValueCache<T> {
       5             :   T? value;
       6             : 
       7             :   List<dynamic> _lastValidCacheValues = <dynamic>[];
       8             : 
       9          29 :   ValueCache();
      10             : 
      11           9 :   bool isCacheValid<F>(List<F> validCacheValues) {
      12           9 :     if (value == null) {
      13             :       return false;
      14             :     }
      15          36 :     for (var i = 0; i < _lastValidCacheValues.length; ++i) {
      16          36 :       if (_lastValidCacheValues[i] != validCacheValues[i]) {
      17             :         return false;
      18             :       }
      19             :     }
      20             :     return true;
      21             :   }
      22             : 
      23           9 :   T updateCache<F>(T value, List<F> validCacheValues) {
      24           9 :     this.value = value;
      25           9 :     _lastValidCacheValues = validCacheValues;
      26             :     return value;
      27             :   }
      28             : }

Generated by: LCOV version 1.15