From e7f41c93b34d73f545b78d5bfc5ea3cb35347a41 Mon Sep 17 00:00:00 2001 From: Ali Ghahremani Date: Sat, 1 Apr 2023 12:19:21 +0330 Subject: [PATCH] format: flutter format . --- .../depends_on_async_sample.dart | 8 +++--- lib/src/telescope.dart | 27 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/example/lib/03_2_depends_on_async/depends_on_async_sample.dart b/example/lib/03_2_depends_on_async/depends_on_async_sample.dart index 3f0c7e1..eeceb8e 100644 --- a/example/lib/03_2_depends_on_async/depends_on_async_sample.dart +++ b/example/lib/03_2_depends_on_async/depends_on_async_sample.dart @@ -27,10 +27,10 @@ class DependObservableAsyncSampleLayoutState bmi = Telescope.dependsOnAsync(0, [height, weight], () async { return await calculateBMI(height.value, weight.value); - }, isCalculating: loadingBMI, - enableCaching: true, - cacheExpireTime: const Duration(seconds: 10) - ); + }, + isCalculating: loadingBMI, + enableCaching: true, + cacheExpireTime: const Duration(seconds: 10)); showingText = Telescope.dependsOn([height, weight, bmi, loadingBMI], () { var bmis = bmi.value.toString(); diff --git a/lib/src/telescope.dart b/lib/src/telescope.dart index a1ac06d..649af39 100644 --- a/lib/src/telescope.dart +++ b/lib/src/telescope.dart @@ -58,43 +58,44 @@ class Telescope { bool enableCaching = false, Duration? cacheExpireTime, }) { - var hashmap = HashMap(); var expireTimeMap = HashMap(); - bool isExpired(int key){ - if(cacheExpireTime == null) return false; - if(!expireTimeMap.containsKey(key)) return true; - return expireTimeMap[key]!.millisecondsSinceEpoch < DateTime.now().millisecondsSinceEpoch; + bool isExpired(int key) { + if (cacheExpireTime == null) return false; + if (!expireTimeMap.containsKey(key)) return true; + return expireTimeMap[key]!.millisecondsSinceEpoch < + DateTime.now().millisecondsSinceEpoch; } - int getDependenciesHash(){ - return dependencies.map((e) => e.value.hashCode).reduce((value, - element) => value * element); + int getDependenciesHash() { + return dependencies + .map((e) => e.value.hashCode) + .reduce((value, element) => value * element); } Future cal() async { if (!enableCaching) return await calculate(); var key = getDependenciesHash(); - if (hashmap.containsKey(key) && !isExpired(key)){ + if (hashmap.containsKey(key) && !isExpired(key)) { return hashmap[key] as T; } return await calculate(); } - void calAndUpdate(){ + void calAndUpdate() { isCalculating?.value = true; int dh = getDependenciesHash(); cal().then((value) { - if(enableCaching){ + if (enableCaching) { hashmap[dh] = value; - if(cacheExpireTime!=null){ + if (cacheExpireTime != null) { var expTime = DateTime.now().add(cacheExpireTime); expireTimeMap[dh] = expTime; } } int cdh = getDependenciesHash(); - if(dh!=cdh) return; + if (dh != cdh) return; holden = value; isCalculating?.value = false; notifyAll();