-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * Update disposebag.dart * Update disposebag.dart * 1.4.0 Co-authored-by: Nguyễn Thái Học <[email protected]>
- Loading branch information
Showing
6 changed files
with
111 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// Represents the result of disposing or clearing. | ||
enum BagResult { | ||
/// Disposed successfully. | ||
disposedSuccess, | ||
|
||
/// Cleared successfully. | ||
clearedSuccess, | ||
|
||
/// Disposed unsuccessfully. | ||
disposedFailure, | ||
|
||
/// Cleared unsuccessfully. | ||
clearedFailure, | ||
} | ||
|
||
/// Logs the result of disposing or clearing. | ||
/// By default, prints the result to the console. | ||
typedef Logger = void Function( | ||
BagResult result, | ||
Set<dynamic> resources, [ | ||
Object error, | ||
StackTrace stackTrace, | ||
]); | ||
|
||
/// Default `DisposeBag` logger | ||
final Logger defaultLogger = (result, resources, [error, stackTrace]) { | ||
switch (result) { | ||
case BagResult.disposedSuccess: | ||
print(' ↓ Disposed successfully: '); | ||
break; | ||
case BagResult.clearedSuccess: | ||
print(' ↓ Cleared successfully: '); | ||
break; | ||
case BagResult.disposedFailure: | ||
print(' ↓ Disposed unsuccessfully: '); | ||
print(' → Error: $error'); | ||
print(' → StackTrace: $stackTrace'); | ||
break; | ||
case BagResult.clearedFailure: | ||
print(' ↓ Cleared unsuccessfully: '); | ||
print(' → Error: $error'); | ||
print(' → StackTrace: $stackTrace'); | ||
break; | ||
} | ||
|
||
print(resources.mapIndexed((i, e) => ' $i → $e').join('\n')); | ||
}; | ||
|
||
extension _IterableExtensions<T> on Iterable<T> { | ||
Iterable<R> mapIndexed<R>(R Function(int, T) mapper) sync* { | ||
var index = 0; | ||
for (final item in this) { | ||
yield mapper(index++, item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters