mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Move object utilities to np_common
This commit is contained in:
parent
731e21df7c
commit
7306d3cedf
9 changed files with 42 additions and 20 deletions
|
@ -7,6 +7,7 @@ import 'package:nc_photos/entity/person.dart';
|
|||
import 'package:nc_photos/entity/recognize_face.dart';
|
||||
import 'package:nc_photos/entity/recognize_face_item.dart';
|
||||
import 'package:nc_photos/object_extension.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
part 'recognize.g.dart';
|
||||
|
|
|
@ -1,26 +1,16 @@
|
|||
import 'dart:async';
|
||||
import 'package:np_common/object_util.dart';
|
||||
|
||||
extension ObjectExtension<T> on T {
|
||||
/// Run [fn] with this, and return this
|
||||
T apply(void Function(T obj) fn) {
|
||||
fn(this);
|
||||
return this;
|
||||
}
|
||||
/// Deprecated, use [also]
|
||||
T apply(void Function(T obj) fn) => also(fn);
|
||||
|
||||
/// Run [fn] with this, and return this
|
||||
Future<T> applyFuture(FutureOr<void> Function(T obj) fn) async {
|
||||
await fn(this);
|
||||
return this;
|
||||
}
|
||||
/// Deprecated, use [alsoFuture]
|
||||
Future<T> applyFuture(FutureOr<void> Function(T obj) fn) => alsoFuture(fn);
|
||||
|
||||
/// Run [fn] with this, and return the results of [fn]
|
||||
U run<U>(U Function(T obj) fn) => fn(this);
|
||||
/// Deprecated, use [let]
|
||||
U run<U>(U Function(T obj) fn) => let(fn);
|
||||
|
||||
/// Run [fn] with this, and return the results of [fn]
|
||||
Future<U> runFuture<U>(FutureOr<U> Function(T obj) fn) async {
|
||||
return await fn(this);
|
||||
}
|
||||
|
||||
/// Cast this as U, or null if this is not an object of U
|
||||
U? as<U>() => this is U ? this as U : null;
|
||||
/// Deprecated, use [letFuture]
|
||||
Future<U> runFuture<U>(FutureOr<U> Function(T obj) fn) => letFuture(fn);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import 'package:nc_photos/widget/viewer.dart';
|
|||
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
||||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
|
||||
part 'archive_browser.g.dart';
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import 'package:nc_photos_plugin/nc_photos_plugin.dart';
|
|||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_collection/np_collection.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
import 'package:np_platform_permission/np_platform_permission.dart';
|
||||
import 'package:np_platform_util/np_platform_util.dart';
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ import 'package:nc_photos/widget/viewer.dart';
|
|||
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
||||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
import 'package:np_platform_image_processor/np_platform_image_processor.dart';
|
||||
import 'package:np_platform_util/np_platform_util.dart';
|
||||
import 'package:visibility_detector/visibility_detector.dart';
|
||||
|
|
|
@ -38,6 +38,7 @@ import 'package:nc_photos/widget/selection_app_bar.dart';
|
|||
import 'package:nc_photos/widget/viewer.dart';
|
||||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
|
||||
part 'home_search.g.dart';
|
||||
|
|
|
@ -7,8 +7,8 @@ import 'package:nc_photos/cache_manager_util.dart';
|
|||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/np_api_util.dart';
|
||||
import 'package:nc_photos/object_extension.dart';
|
||||
import 'package:nc_photos/widget/cached_network_image_mod.dart' as mod;
|
||||
import 'package:np_common/object_util.dart';
|
||||
|
||||
/// A square thumbnail widget for a file
|
||||
class NetworkRectThumbnail extends StatelessWidget {
|
||||
|
|
|
@ -31,6 +31,7 @@ import 'package:nc_photos/widget/trashbin_viewer.dart';
|
|||
import 'package:nc_photos/widget/zoom_menu_button.dart';
|
||||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
|
||||
part 'trashbin_browser.g.dart';
|
||||
|
||||
|
|
26
np_common/lib/object_util.dart
Normal file
26
np_common/lib/object_util.dart
Normal file
|
@ -0,0 +1,26 @@
|
|||
import 'dart:async';
|
||||
|
||||
extension ObjectExtension<T> on T {
|
||||
/// Run [fn] with this, and return this
|
||||
T also(void Function(T obj) fn) {
|
||||
fn(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Run [fn] with this, and return this
|
||||
Future<T> alsoFuture(FutureOr<void> Function(T obj) fn) async {
|
||||
await fn(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Run [fn] with this, and return the results of [fn]
|
||||
U let<U>(U Function(T obj) fn) => fn(this);
|
||||
|
||||
/// Run [fn] with this, and return the results of [fn]
|
||||
Future<U> letFuture<U>(FutureOr<U> Function(T obj) fn) async {
|
||||
return await fn(this);
|
||||
}
|
||||
|
||||
/// Cast this as U, or null if this is not an object of U
|
||||
U? as<U>() => this is U ? this as U : null;
|
||||
}
|
Loading…
Reference in a new issue