Skip to content

Commit de9edc1

Browse files
committed
mvi app compelte
1 parent 93c4176 commit de9edc1

File tree

156 files changed

+3985
-660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+3985
-660
lines changed

mvi_base/lib/mvi_base.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library blocs;
2-
31
export 'src/models/models.dart';
42
export 'src/mvi_core.dart';
53
export 'src/mvi_stats.dart';

mvi_base/lib/src/models/todo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Todo {
4949
entity.task,
5050
complete: entity.complete,
5151
note: entity.note,
52-
id: entity.id ?? Uuid().generateV4(),
52+
id: entity.id,
5353
);
5454
}
5555
}

mvi_base/lib/src/mvi_stats.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import 'package:mvi_base/mvi_base.dart';
2-
import 'package:mvi_base/src/mvi_core.dart';
32
import 'package:rxdart/rxdart.dart';
43

54
class StatsPresenter extends MviPresenter<StatsModel> {
65
StatsPresenter(TodoListInteractor interactor)
76
: super(
7+
initialModel: StatsModelLoading(),
88
stream: Rx.combineLatest2(
99
interactor.todos.map(_numActive),
1010
interactor.todos.map(_numComplete),
11-
(numActive, numComplete) => StatsModel(numActive, numComplete),
11+
(numActive, numComplete) =>
12+
StatsModelLoaded(numActive: numActive, numComplete: numComplete),
1213
),
1314
);
1415

@@ -21,16 +22,20 @@ class StatsPresenter extends MviPresenter<StatsModel> {
2122
}
2223
}
2324

24-
class StatsModel {
25+
sealed class StatsModel {}
26+
27+
class StatsModelLoading implements StatsModel {}
28+
29+
class StatsModelLoaded implements StatsModel {
2530
final int numActive;
2631
final int numComplete;
2732

28-
StatsModel(this.numActive, this.numComplete);
33+
StatsModelLoaded({required this.numActive, required this.numComplete});
2934

3035
@override
3136
bool operator ==(Object other) =>
3237
identical(this, other) ||
33-
other is StatsModel &&
38+
other is StatsModelLoaded &&
3439
runtimeType == other.runtimeType &&
3540
numActive == other.numActive &&
3641
numComplete == other.numComplete;
@@ -40,6 +45,6 @@ class StatsModel {
4045

4146
@override
4247
String toString() {
43-
return 'StatsModel{numActive: $numActive, numComplete: $numComplete}';
48+
return 'StatsModelLoaded{numActive: $numActive, numComplete: $numComplete}';
4449
}
4550
}

mvi_base/lib/src/mvi_todos_list.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import 'dart:async';
22

3-
import 'package:collection/equality.dart';
3+
import 'package:collection/collection.dart';
44
import 'package:mvi_base/src/models/models.dart';
55
import 'package:mvi_base/src/mvi_core.dart';
66
import 'package:mvi_base/src/todo_list_interactor.dart';
77
import 'package:mvi_base/src/user_interactor.dart';
88
import 'package:rxdart/rxdart.dart';
99

10-
class TodosListModel {
10+
class TodoListModel {
1111
final VisibilityFilter activeFilter;
1212
final bool allComplete;
1313
final bool hasCompletedTodos;
1414
final List<Todo> visibleTodos;
1515
final bool loading;
1616
final User user;
1717

18-
TodosListModel({
18+
TodoListModel({
1919
required this.activeFilter,
2020
required this.allComplete,
2121
required this.hasCompletedTodos,
@@ -24,7 +24,7 @@ class TodosListModel {
2424
required this.user,
2525
});
2626

27-
factory TodosListModel.initial() => TodosListModel(
27+
factory TodoListModel.initial() => TodoListModel(
2828
loading: true,
2929
activeFilter: VisibilityFilter.all,
3030
allComplete: false,
@@ -41,7 +41,7 @@ class TodosListModel {
4141
@override
4242
bool operator ==(Object other) =>
4343
identical(this, other) ||
44-
other is TodosListModel &&
44+
other is TodoListModel &&
4545
runtimeType == other.runtimeType &&
4646
activeFilter == other.activeFilter &&
4747
allComplete == other.allComplete &&
@@ -60,7 +60,7 @@ class TodosListModel {
6060
user.hashCode;
6161
}
6262

63-
class TodosListView implements MviView {
63+
mixin class TodoListView implements MviView {
6464
final addTodo = StreamController<Todo>.broadcast(sync: true);
6565

6666
final deleteTodo = StreamController<String>.broadcast(sync: true);
@@ -88,18 +88,18 @@ class TodosListView implements MviView {
8888
}
8989
}
9090

91-
class TodosListPresenter extends MviPresenter<TodosListModel> {
92-
final TodosListView _view;
91+
class TodoListPresenter extends MviPresenter<TodoListModel> {
92+
final TodoListView _view;
9393
final TodoListInteractor _interactor;
9494

95-
TodosListPresenter({
96-
required TodosListView view,
95+
TodoListPresenter({
96+
required TodoListView view,
9797
required TodoListInteractor todosInteractor,
9898
required UserInteractor userInteractor,
9999
}) : _view = view,
100100
_interactor = todosInteractor,
101101
super(
102-
initialModel: TodosListModel.initial(),
102+
initialModel: TodoListModel.initial(),
103103
stream: _buildStream(view, todosInteractor, userInteractor),
104104
);
105105

@@ -114,8 +114,8 @@ class TodosListPresenter extends MviPresenter<TodosListModel> {
114114
]);
115115
}
116116

117-
static Stream<TodosListModel> _buildStream(
118-
TodosListView view,
117+
static Stream<TodoListModel> _buildStream(
118+
TodoListView view,
119119
TodoListInteractor interactor,
120120
UserInteractor repository,
121121
) {
@@ -132,7 +132,7 @@ class TodosListPresenter extends MviPresenter<TodosListModel> {
132132
_filterTodos,
133133
),
134134
(activeFilter, allComplete, hasCompletedTodos, visibleTodos) {
135-
return TodosListModel(
135+
return TodoListModel(
136136
user: user,
137137
activeFilter: activeFilter,
138138
allComplete: allComplete,

mvi_base/test/mvi_stats_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ void main() {
2222

2323
final presenter = StatsPresenter(interactor);
2424

25-
expect(presenter, emitsThrough(StatsModel(1, 2)));
25+
expect(
26+
presenter,
27+
emitsThrough(StatsModelLoaded(numActive: 1, numComplete: 2)),
28+
);
2629
});
2730
});
2831
}

mvi_base/test/mvi_todos_list_test.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() {
1212
group('MviTodosList', () {
1313
group('View', () {
1414
test('should clean up after itself', () {
15-
final view = TodosListView();
15+
final view = TodoListView();
1616

1717
view.tearDown();
1818

@@ -28,20 +28,20 @@ void main() {
2828
group('Presenter', () {
2929
test('should have an initial state', () {
3030
final interactor = MockTodoListInteractor();
31-
final view = TodosListView();
31+
final view = TodoListView();
3232

33-
final presenter = TodosListPresenter(
33+
final presenter = TodoListPresenter(
3434
view: view,
3535
todosInteractor: interactor,
3636
userInteractor: MockUserInteractor(),
3737
);
3838

39-
expect(presenter.latest, TodosListModel.initial());
39+
expect(presenter.latest, TodoListModel.initial());
4040
});
4141

4242
test('should show all todos by default', () {
4343
final interactor = MockTodoListInteractor();
44-
final view = TodosListView();
44+
final view = TodoListView();
4545
final todos = [Todo('Hi')];
4646

4747
when(interactor.todos).thenAnswer((_) => Stream.fromIterable([todos]));
@@ -52,7 +52,7 @@ void main() {
5252
interactor.hasCompletedTodos,
5353
).thenAnswer((_) => Stream.fromIterable([false]));
5454

55-
final presenter = TodosListPresenter(
55+
final presenter = TodoListPresenter(
5656
view: view,
5757
todosInteractor: interactor,
5858
userInteractor: MockUserInteractor(),
@@ -68,7 +68,7 @@ void main() {
6868

6969
test('should display completed todos', () {
7070
final interactor = MockTodoListInteractor();
71-
final view = TodosListView();
71+
final view = TodoListView();
7272
final todos = [
7373
Todo('Hallo', complete: false),
7474
Todo('Friend', complete: true),
@@ -82,7 +82,7 @@ void main() {
8282
interactor.hasCompletedTodos,
8383
).thenAnswer((_) => Stream.fromIterable([false]));
8484

85-
final presenter = TodosListPresenter(
85+
final presenter = TodoListPresenter(
8686
view: view,
8787
todosInteractor: interactor,
8888
userInteractor: MockUserInteractor(),
@@ -94,7 +94,7 @@ void main() {
9494

9595
test('should display active todos', () {
9696
final interactor = MockTodoListInteractor();
97-
final view = TodosListView();
97+
final view = TodoListView();
9898
final todos = [
9999
Todo('Hallo', complete: false),
100100
Todo('Friend', complete: true),
@@ -108,7 +108,7 @@ void main() {
108108
interactor.hasCompletedTodos,
109109
).thenAnswer((_) => Stream.fromIterable([false]));
110110

111-
final presenter = TodosListPresenter(
111+
final presenter = TodoListPresenter(
112112
view: view,
113113
todosInteractor: interactor,
114114
userInteractor: MockUserInteractor(),
@@ -120,7 +120,7 @@ void main() {
120120

121121
test('allComplete should stream state of interactor', () {
122122
final interactor = MockTodoListInteractor();
123-
final view = TodosListView();
123+
final view = TodoListView();
124124
final todos = [
125125
Todo('Hallo', complete: false),
126126
Todo('Friend', complete: true),
@@ -134,7 +134,7 @@ void main() {
134134
interactor.hasCompletedTodos,
135135
).thenAnswer((_) => Stream.fromIterable([false]));
136136

137-
final presenter = TodosListPresenter(
137+
final presenter = TodoListPresenter(
138138
view: view,
139139
todosInteractor: interactor,
140140
userInteractor: MockUserInteractor(),
@@ -145,7 +145,7 @@ void main() {
145145

146146
test('hasCompletedTodos should reflect the interactor', () {
147147
final interactor = MockTodoListInteractor();
148-
final view = TodosListView();
148+
final view = TodoListView();
149149
final todos = [
150150
Todo('Hallo', complete: false),
151151
Todo('Friend', complete: true),
@@ -159,7 +159,7 @@ void main() {
159159
interactor.hasCompletedTodos,
160160
).thenAnswer((_) => Stream.fromIterable([true]));
161161

162-
final presenter = TodosListPresenter(
162+
final presenter = TodoListPresenter(
163163
view: view,
164164
todosInteractor: interactor,
165165
userInteractor: MockUserInteractor(),
@@ -170,7 +170,7 @@ void main() {
170170

171171
test('should add todos to the interactor', () async {
172172
final interactor = MockTodoListInteractor();
173-
final view = TodosListView();
173+
final view = TodoListView();
174174
final todos = [
175175
Todo('Hallo', complete: false),
176176
Todo('Friend', complete: true),
@@ -184,7 +184,7 @@ void main() {
184184
interactor.hasCompletedTodos,
185185
).thenAnswer((_) => Stream.fromIterable([true]));
186186

187-
final presenter = TodosListPresenter(
187+
final presenter = TodoListPresenter(
188188
view: view,
189189
todosInteractor: interactor,
190190
userInteractor: MockUserInteractor(),
@@ -197,7 +197,7 @@ void main() {
197197

198198
test('should send deletions to the interactor', () async {
199199
final interactor = MockTodoListInteractor();
200-
final view = TodosListView();
200+
final view = TodoListView();
201201
final todos = [
202202
Todo('Hallo', complete: false),
203203
Todo('Friend', complete: true),
@@ -211,7 +211,7 @@ void main() {
211211
interactor.hasCompletedTodos,
212212
).thenAnswer((_) => Stream.fromIterable([true]));
213213

214-
final presenter = TodosListPresenter(
214+
final presenter = TodoListPresenter(
215215
view: view,
216216
todosInteractor: interactor,
217217
userInteractor: MockUserInteractor(),
@@ -224,7 +224,7 @@ void main() {
224224

225225
test('should remove completed todos from the interactor', () async {
226226
final interactor = MockTodoListInteractor();
227-
final view = TodosListView();
227+
final view = TodoListView();
228228
final todos = [
229229
Todo('Hallo', complete: false),
230230
Todo('Friend', complete: true),
@@ -238,7 +238,7 @@ void main() {
238238
interactor.hasCompletedTodos,
239239
).thenAnswer((_) => Stream.fromIterable([true]));
240240

241-
final presenter = TodosListPresenter(
241+
final presenter = TodoListPresenter(
242242
view: view,
243243
todosInteractor: interactor,
244244
userInteractor: MockUserInteractor(),
@@ -251,7 +251,7 @@ void main() {
251251

252252
test('should toggle complete', () async {
253253
final interactor = MockTodoListInteractor();
254-
final view = TodosListView();
254+
final view = TodoListView();
255255
final todos = [
256256
Todo('Hallo', complete: false),
257257
Todo('Friend', complete: true),
@@ -265,7 +265,7 @@ void main() {
265265
interactor.hasCompletedTodos,
266266
).thenAnswer((_) => Stream.fromIterable([true]));
267267

268-
final presenter = TodosListPresenter(
268+
final presenter = TodoListPresenter(
269269
view: view,
270270
todosInteractor: interactor,
271271
userInteractor: MockUserInteractor(),
@@ -302,7 +302,7 @@ class ModelWith extends Matcher {
302302

303303
@override
304304
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
305-
if (item is TodosListModel) {
305+
if (item is TodoListModel) {
306306
bool match = true;
307307
if (visibleTodos != null) {
308308
match = _listsEqual(visibleTodos!, item.visibleTodos);

0 commit comments

Comments
 (0)