Skip to content

Commit d1e8e38

Browse files
authored
Merge pull request #42 from bwu-dart-contributing/dispose_wait_for_close
`store.dispose()` should wait for `_stateController.close()` to complete
2 parents 0945b9b + dbfcb1a commit d1e8e38

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/src/store.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class Store<
6666
}
6767

6868
/// [dispose] removes closes both the dispatch and subscription stream
69-
void dispose() {
70-
_stateController.close();
69+
Future<Null> dispose() async {
70+
await _stateController.close();
7171
_state = null;
7272
_actions = null;
7373
}

test/unit/store_test.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ void main() {
3535
final onStateChangeCompleter = new Completer<
3636
StoreChange<BaseCounter, BaseCounterBuilder, dynamic>>();
3737

38-
final storeChagneHandler = createChangeHandler(onStateChangeCompleter);
39-
storeChagneHandler.build(store);
40-
// dipatch 2 different actions, since the handler is only set to listen to base.increment
38+
final storeChangeHandler = createChangeHandler(onStateChangeCompleter);
39+
storeChangeHandler.build(store);
40+
// dispatch 2 different actions, since the handler is only set to listen to base.increment
4141
// if both are handled by the handler the completer with throw an error
4242
store.actions.decrement(1);
4343
store.actions.increment(4);
4444

4545
final stateChange = await onStateChangeCompleter.future;
4646
expect(stateChange.prev.count, 0);
4747
expect(stateChange.next.count, 4);
48-
storeChagneHandler.dispose();
48+
storeChangeHandler.dispose();
4949
});
5050

5151
test('replaceState', () async {
@@ -119,5 +119,16 @@ void main() {
119119
expect(stateChange.next.count, 3);
120120
expect(stateChange.action.payload, 2);
121121
});
122+
123+
test('should not reset state and actions before closing', () async {
124+
store
125+
.substateStream((s) => s)
126+
.listen((_) => expect(store.actions, isNotNull));
127+
128+
// intentionally don't wait
129+
store.dispose();
130+
131+
store.actions.increment(1);
132+
});
122133
});
123134
}

0 commit comments

Comments
 (0)