Skip to content

Commit

Permalink
InterceptorCallback and InterceptorResolver now public;
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Mar 13, 2023
1 parent 5e96040 commit ba75fed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## V1.1.6

- InterceptorCallback and InterceptorResolver now public;

## V1.1.5

- Updated action CI;
Expand Down
23 changes: 14 additions & 9 deletions lib/src/presenter/interceptors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Interceptors {
/// return error;
/// });
/// ```
final request = _InterceptorCallback<Request>();
final request = InterceptorCallback<Request>();

/// Manage response interceptors.
///
Expand All @@ -32,11 +32,12 @@ class Interceptors {
/// return error;
/// });
/// ```
final response = _InterceptorCallback<Response>();
final response = InterceptorCallback<Response>();
}

class _InterceptorCallback<T> {
final _interceptors = <_InterceptorResolver<T>>[];
/// Organize interceptors
class InterceptorCallback<T> {
final _interceptors = <InterceptorResolver<T>>[];

/// Creates a new interceptor.
/// [resolve]: Resolve request or response.
Expand All @@ -57,12 +58,12 @@ class _InterceptorCallback<T> {
/// return error;
/// });
/// ```
_InterceptorResolver<T> use(
InterceptorResolver<T> use(
FutureOr<T> Function(T) resolve, {
FutureOr<dynamic> Function(UnoError)? onError,
bool Function(T)? runWhen,
}) {
final interceptor = _InterceptorResolver<T>(resolve, onError, runWhen);
final interceptor = InterceptorResolver<T>(resolve, onError, runWhen);
_interceptors.add(interceptor);
return interceptor;
}
Expand All @@ -72,7 +73,7 @@ class _InterceptorCallback<T> {
/// final myInterceptor = uno.interceptors.request.use((request) {/*...*/});
/// uno.interceptors.request.eject(myInterceptor);
/// ```
void eject(_InterceptorResolver<T> interceptor) => _interceptors.remove(
void eject(InterceptorResolver<T> interceptor) => _interceptors.remove(
interceptor,
);

Expand All @@ -86,9 +87,11 @@ class _InterceptorCallback<T> {
return data;
}

/// only test
@visibleForTesting
Future<T> resolveTest(T data) => _resolve(data);

/// only test
@visibleForTesting
Future<dynamic> resolveErrorTest(UnoError error) => _resolveError(error);

Expand All @@ -105,10 +108,12 @@ class _InterceptorCallback<T> {
}
}

class _InterceptorResolver<T> {
/// Resolver interceptors
class InterceptorResolver<T> {
final FutureOr<T> Function(T) _resolve;
final FutureOr<dynamic> Function(UnoError)? _errorResolve;
final bool Function(T)? _runWhen;

_InterceptorResolver(this._resolve, this._errorResolve, this._runWhen);
/// Resolver interceptors
InterceptorResolver(this._resolve, this._errorResolve, this._runWhen);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: uno
description: Uno is a multiplatform HTTP client, based on Axios and built following the Clean Dart approach by the Flutterando Community.
version: 1.1.5
version: 1.1.6
homepage: https://github.com/Flutterando/uno.git

environment:
Expand Down

0 comments on commit ba75fed

Please sign in to comment.