Skip to content

Commit

Permalink
Dart 3 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland committed Oct 5, 2023
1 parent 6a2f54f commit 5ceab12
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 218 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.0
* Dart 3 upgrade

## 1.0.1
* Document improvements ([#34](https://github.com/xmartlabs/stock/pull/34))
* Make SourceOfTruth non-required in the Stock constrictor ([#33](https://github.com/xmartlabs/stock/pull/33))
Expand Down
4 changes: 2 additions & 2 deletions lib/src/extensions/stock_response_internal_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// ignore_for_file: public_member_api_docs
// ignore_for_file: public_member_api_docs, unnecessary_lambdas

import 'package:stock/src/stock_response.dart';
import 'package:stock/src/stock_response_extensions.dart';

extension StockResponseExtensions<T> on StockResponse<T> {
StockResponse<R> swapType<R>() => when(
onData: (origin, data) => StockResponse.data(origin, data as R),
onLoading: (origin) => StockResponse.loading(origin),
onLoading: StockResponse.loading,
onError: (origin, error, stacktrace) =>
StockResponse.error(origin, error, stacktrace),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/implementations/factory_fetcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class FutureFetcher<Key, Output> extends FactoryFetcher<Key, Output> {
}

class StreamFetcher<Key, Output> extends FactoryFetcher<Key, Output> {
StreamFetcher(Stream<Output> Function(Key key) factory) : super(factory);
StreamFetcher(super.factory);
}
8 changes: 4 additions & 4 deletions lib/src/stock_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StockResponse<Output> {
@immutable
class StockResponseLoading<T> extends StockResponse<T> {
/// StockResponseLoading constructor
const StockResponseLoading(ResponseOrigin origin) : super._(origin);
const StockResponseLoading(super.origin) : super._();

@override
String toString() => 'StockResponse<$T>.loading(origin: $origin)';
Expand All @@ -58,7 +58,7 @@ class StockResponseLoading<T> extends StockResponse<T> {
@immutable
class StockResponseData<T> extends StockResponse<T> {
/// StockResponseData constructor
const StockResponseData(ResponseOrigin origin, this.value) : super._(origin);
const StockResponseData(super.origin, this.value) : super._();

/// The data value
final T value;
Expand All @@ -82,8 +82,8 @@ class StockResponseData<T> extends StockResponse<T> {
@immutable
class StockResponseError<T> extends StockResponse<T> {
/// StockResponseError constructor
const StockResponseError(ResponseOrigin origin, this.error, [this.stackTrace])
: super._(origin);
const StockResponseError(super.origin, this.error, [this.stackTrace])
: super._();

/// The error
final Object error;
Expand Down
13 changes: 5 additions & 8 deletions lib/src/stock_response_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ extension StockResponseExtensions<T> on StockResponse<T> {
/// [onLoading] or [orElse] as fallback if the response is loading, and
/// [onError] or [orElse] as fallback if the response is an error.
E maybeMap<E>({
required E Function() orElse,
E Function(StockResponseLoading<T> value)? onLoading,
E Function(StockResponseData<T> value)? onData,
E Function(StockResponseError<T> value)? onError,
required E Function() orElse,
}) =>
map(
onLoading: onLoading ?? (_) => orElse(),
Expand Down Expand Up @@ -113,8 +113,7 @@ extension StockResponseExtensions<T> on StockResponse<T> {
ResponseOrigin origin,
Object error,
StackTrace? stackTrace,
)
onError,
) onError,
}) =>
map(
onLoading: (value) => onLoading(value.origin),
Expand All @@ -137,8 +136,7 @@ extension StockResponseExtensions<T> on StockResponse<T> {
ResponseOrigin origin,
Object error,
StackTrace? stackTrace,
)?
onError,
)? onError,
}) =>
maybeWhen(
onLoading: onLoading,
Expand All @@ -151,15 +149,14 @@ extension StockResponseExtensions<T> on StockResponse<T> {
/// [onLoading] or [orElse] as fallback if the response is loading, and
/// [onError] or [orElse] as fallback if the response is an error.
E maybeWhen<E>({
required E Function(ResponseOrigin origin) orElse,
E Function(ResponseOrigin origin)? onLoading,
E Function(ResponseOrigin origin, T data)? onData,
E Function(
ResponseOrigin origin,
Object error,
StackTrace? stackTrace,
)?
onError,
required E Function(ResponseOrigin origin) orElse,
)? onError,
}) =>
when(
onLoading: onLoading ?? (origin) => orElse(origin),
Expand Down
Loading

0 comments on commit 5ceab12

Please sign in to comment.