-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:modulisto/modulisto.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'util/dummy_module.dart'; | ||
|
||
void main() { | ||
group('operation tests', () { | ||
test('react on operation', () async { | ||
const targetNumber = 123; | ||
final dummy = DummyModule(); | ||
final trigger = Trigger<int>(dummy); | ||
final store = Store<int>(dummy, 0); | ||
|
||
Future<int> someNumber(int test) => dummy.runOperation(#test1, () => Future.value(test)); | ||
|
||
final pipeline = Pipeline.sync( | ||
dummy, | ||
($) => $ | ||
..unit(trigger).bind( | ||
(context, value) => context.update(store, value), | ||
) | ||
..operationOnType<int>(#test1).redirect(trigger.call), | ||
); | ||
|
||
Module.initialize(dummy, attach: {pipeline}); | ||
|
||
final number = await someNumber(targetNumber); | ||
expect(number, targetNumber); | ||
expect(number, isNot(0)); | ||
expect(number, equals(store.value)); | ||
}); | ||
test('disable reactions after module dispose', () async { | ||
const targetNumber = 123; | ||
final dummy = DummyModule(); | ||
final trigger = Trigger<int>(dummy); | ||
final store = Store<int>(dummy, 0); | ||
|
||
Future<int> someNumber(int test) => dummy.runOperation(#test1, () => Future.value(test)); | ||
|
||
final pipeline = Pipeline.sync( | ||
dummy, | ||
($) => $ | ||
..unit(trigger).bind( | ||
(context, value) => context.update(store, value), | ||
) | ||
..operationOnType<int>(#test1).redirect(trigger.call), | ||
); | ||
|
||
Module.initialize(dummy, attach: {pipeline}); | ||
|
||
await dummy.dispose(); | ||
|
||
final number = await someNumber(targetNumber); | ||
expect(number, targetNumber); | ||
expect(store.value, isNot(number)); | ||
expect(store.value, equals(0)); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'package:modulisto/modulisto.dart'; | ||
|
||
final class DummyModule extends Module {} | ||
final class DummyModule extends Module { | ||
Future<T> runOperation<T>(Symbol operationId, Future<T> Function() callback) => Operation(operationId, callback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters