Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
55946fa
:art: added new core classes
sarbagyastha Dec 30, 2022
2b0c27a
:truck: reorganize classes
sarbagyastha Dec 30, 2022
94832ec
:truck: reorganize ui classes
sarbagyastha Dec 30, 2022
5b0d693
:truck: move example outside of the package
sarbagyastha Dec 30, 2022
0b289c8
:sparkles: added new example app
sarbagyastha Dec 30, 2022
4340712
:white_check_mark: added gateway test
sarbagyastha Jan 2, 2023
41bbf5b
:white_check_mark: added use case tests
sarbagyastha Jan 2, 2023
5033bca
:white_check_mark: added use case transformer tests
sarbagyastha Jan 2, 2023
2247aae
:white_check_mark: refined transformer tests
sarbagyastha Jan 2, 2023
5bba046
:rotating_light: made analyzer happy
sarbagyastha Jan 2, 2023
8765f80
Merge pull request #96 from MattHamburger/pv2-tests
sarbagya-acme Jan 2, 2023
3a488a6
:sparkles: everything is place for example
sarbagyastha Jan 3, 2023
2cf04e3
:bug: fixed issue while using old classes
sarbagyastha Jan 4, 2023
3b82918
:lipstick: added palette card
sarbagyastha Jan 4, 2023
b472d6a
:lipstick: design improvements
sarbagyastha Jan 4, 2023
50fab77
:lipstick: show pokemon name in caps
sarbagyastha Jan 4, 2023
f443dc0
:lipstick: design refinement
sarbagyastha Jan 4, 2023
b92e2b5
:bug: minor fix
sarbagyastha Jan 4, 2023
e8643f2
:sparkles: added pokemon search
sarbagyastha Jan 4, 2023
06394cd
:art: added pokemon search field widget
sarbagyastha Jan 4, 2023
63dc8fa
:art: added pokemon card widget
sarbagyastha Jan 4, 2023
d0ccfcc
:sparkles: added refresh indicator
sarbagyastha Jan 4, 2023
f61c0a8
:sparkles: added loading failed ui
sarbagyastha Jan 4, 2023
700e5d4
:sparkles: implemented router
sarbagyastha Jan 4, 2023
8fa64f0
:sparkles: added profile page
sarbagyastha Jan 4, 2023
c890420
:sparkles: added cached image
sarbagyastha Jan 4, 2023
43171bc
:sparkles: added spotlight image
sarbagyastha Jan 5, 2023
deb247a
:lipstick: improved transition
sarbagyastha Jan 5, 2023
5df94e9
:lipstick: setup spotlight
sarbagyastha Jan 5, 2023
8c70f46
:sparkles: added pokemon profile gateway
sarbagyastha Jan 5, 2023
dd1d739
:bug: minor fix
sarbagyastha Jan 5, 2023
b674d88
:sparkles: added pokemon type
sarbagyastha Jan 5, 2023
f13d95c
:sparkles: added pokemon description
sarbagyastha Jan 5, 2023
34a7a3e
:sparkles: added height weight
sarbagyastha Jan 5, 2023
f6d739a
:lipstick: fixed gradient
sarbagyastha Jan 5, 2023
339f24a
:lipstick: minor fix
sarbagyastha Jan 5, 2023
76b37e4
:truck: moved models to separate dir
sarbagyastha Jan 5, 2023
0a575db
:bug: minor fix
sarbagyastha Jan 5, 2023
27ef795
:art:
sarbagyastha Jan 5, 2023
55ee486
:sparkles: added stats
sarbagyastha Jan 5, 2023
be2df0e
:white_check_mark:
sarbagyastha Jan 5, 2023
ed6cd45
:white_check_mark: fixed failing test
sarbagyastha Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:clean_framework/clean_framework_core.dart';

class HomeEntity extends Entity {
@override
List<Object?> get props => [];
}
1 change: 1 addition & 0 deletions packages/clean_framework/lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export 'external_interface/request.dart';
export 'external_interface/response.dart';
export 'gateway/gateway.dart';
export 'gateway/gateway_provider.dart';
export 'use_case/entity.dart';
export 'use_case/use_case.dart';
export 'use_case/use_case_provider.dart';
43 changes: 16 additions & 27 deletions packages/clean_framework/lib/src/core/gateway/gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import 'package:meta/meta.dart';

abstract class Gateway<O extends Output, R extends Request,
P extends SuccessResponse, S extends SuccessInput> {
UseCase? _useCase;

void attach(
ProviderRef<Object> ref, {
required List<UseCaseProvider> providers,
}) {
_ref = ref;
_useCaseProviders = providers;

for (final useCaseProvider in providers) {
useCaseProvider.notifier.then(
(notifier) {
Expand All @@ -28,6 +29,9 @@ abstract class Gateway<O extends Output, R extends Request,
}
}

late final ProviderRef<Object> _ref;
late final List<UseCaseProvider> _useCaseProviders;

@visibleForTesting
@nonVirtual
// ignore: use_setters_to_change_properties
Expand Down Expand Up @@ -60,40 +64,25 @@ abstract class Gateway<O extends Output, R extends Request,
}
}

abstract class BridgeGateway<SUBSCRIBER_OUTPUT extends Output,
PUBLISHER_OUTPUT extends Output, SUBSCRIBER_INPUT extends Input> {
BridgeGateway({
required UseCase subscriberUseCase,
required UseCase publisherUseCase,
}) : _subscriberUseCase = subscriberUseCase,
_publisherUseCase = publisherUseCase {
_subscriberUseCase.subscribe<SUBSCRIBER_OUTPUT, SUBSCRIBER_INPUT>(
(output) {
return Either<FailureInput, SUBSCRIBER_INPUT>.right(
onResponse(
_publisherUseCase.getOutput<PUBLISHER_OUTPUT>(),
),
);
},
);
}
late final UseCase _subscriberUseCase;
late final UseCase _publisherUseCase;

SUBSCRIBER_INPUT onResponse(PUBLISHER_OUTPUT output);
}

abstract class WatcherGateway<
O extends Output,
R extends Request,
P extends SuccessResponse,
S extends SuccessInput> extends Gateway<O, R, P, S> {
@override
FailureInput onFailure(FailureResponse failureResponse) => FailureInput();
FailureInput onFailure(FailureResponse failureResponse) {
return FailureInput(message: failureResponse.message);
}

@nonVirtual
void yieldResponse(P response) {
_useCase?.setInput(onSuccess(response));
for (final useCaseProvider in _useCaseProviders) {
useCaseProvider.notifier.then(
(notifier) {
_ref.read(notifier).setInput(onSuccess(response));
},
);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/clean_framework/lib/src/core/use_case/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import 'package:flutter/foundation.dart';
abstract class Entity extends Equatable {
@override
bool get stringify => true;

external Entity copyWith();
}
4 changes: 3 additions & 1 deletion packages/clean_framework/lib/src/core/use_case/use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ abstract class UseCase<E extends Entity> extends StateNotifier<E>
with UseCaseDebounceMixin {
UseCase({
required E entity,
List<UseCaseTransformer<E>>? transformers,
@Deprecated('Use transformers instead') OutputFilterMap<E>? outputFilters,
@Deprecated('Use transformers instead') InputFilterMap<E>? inputFilters,
List<UseCaseTransformer<E>>? transformers,
}) : _outputFilters = Map.of(outputFilters ?? const {}),
_inputFilters = Map.of(inputFilters ?? const {}),
super(entity) {
Expand All @@ -34,6 +34,7 @@ abstract class UseCase<E extends Entity> extends StateNotifier<E>
@protected
E get entity => super.state;

@visibleForTesting
@protected
set entity(E newEntity) => super.state = newEntity;

Expand All @@ -49,6 +50,7 @@ abstract class UseCase<E extends Entity> extends StateNotifier<E>
_requestSubscriptions.add<O>(subscription);
}

@visibleForTesting
@protected
Future<void> request<O extends Output, S extends SuccessInput>(
O output, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mixin UseCaseDebounceMixin {
/// in a given frame of [duration].
///
/// If [immediate] is false, then then first action will also be debounced.
@visibleForTesting
@protected
void debounce({
required void Function() action,
Expand Down
137 changes: 137 additions & 0 deletions packages/clean_framework/test/core/gateway/gateway_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import 'package:clean_framework/clean_framework.dart';
import 'package:clean_framework/clean_framework_core.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('Gateway tests |', () {
test('success', () async {
final gateway = TestGateway()
..feedResponse(
(request) async => Either.right(
TestSuccessResponse('Hello ${request.name}!'),
),
);

final input = await gateway.buildInput(
TestGatewayOutput('Acme Software'),
);

expect(input.isRight, isTrue);
expect(input.right.message, 'Hello Acme Software!');
});

test('failure', () async {
final gateway = TestGateway()
..feedResponse(
(request) async => const Either.left(
TypedFailureResponse(
message: 'Something went wrong',
type: 'failure',
),
),
);

final input = await gateway.buildInput(
TestGatewayOutput('Acme Software'),
);

expect(input.isLeft, isTrue);
expect(input.left.message, 'Something went wrong');
});
});

group('Watcher Gateway', () {
test('success', () async {
final gateway = TestWatcherGateway()
..feedResponse(
(request) async => Either.right(
TestSuccessResponse('Hello ${request.name}!'),
),
);

final input = await gateway.buildInput(
TestGatewayOutput('Acme Software'),
);

expect(input.isRight, isTrue);
expect(input.right.message, 'Hello Acme Software!');
});

test('failure', () async {
final gateway = TestWatcherGateway()
..feedResponse(
(request) async => const Either.left(
TypedFailureResponse(
message: 'Something went wrong',
type: 'failure',
),
),
);

final input = await gateway.buildInput(
TestGatewayOutput('Acme Software'),
);

expect(input.isLeft, isTrue);
expect(input.left.message, 'Something went wrong');
});
});
}

class TestGateway extends Gateway<TestGatewayOutput, TestRequest,
TestSuccessResponse, TestSuccessInput> {
@override
TestRequest buildRequest(TestGatewayOutput output) {
return TestRequest(output.name);
}

@override
FailureInput onFailure(FailureResponse failureResponse) {
return FailureInput(message: failureResponse.message);
}

@override
TestSuccessInput onSuccess(TestSuccessResponse response) {
return TestSuccessInput(response.message);
}
}

class TestWatcherGateway extends WatcherGateway<TestGatewayOutput, TestRequest,
TestSuccessResponse, TestSuccessInput> {
@override
TestRequest buildRequest(TestGatewayOutput output) {
return TestRequest(output.name);
}

@override
TestSuccessInput onSuccess(covariant TestSuccessResponse response) {
return TestSuccessInput(response.message);
}
}

class TestGatewayOutput extends Output {
TestGatewayOutput(this.name);

final String name;

@override
List<Object?> get props => [name];
}

class TestSuccessInput extends SuccessInput {
TestSuccessInput(this.message);

final String message;
}

class TestSuccessResponse extends SuccessResponse {
const TestSuccessResponse(this.message);

final String message;
}

class TestRequest extends Request {
const TestRequest(this.name);

final String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void main() {}
Loading