From 6e766cda1295b6b56ba6029312b24de9a436c7f8 Mon Sep 17 00:00:00 2001 From: mk-dev-1 <41755310+mk-dev-1@users.noreply.github.com> Date: Fri, 23 Apr 2021 14:52:21 +0200 Subject: [PATCH 1/3] Made TResult of StreamView non-nullable --- lib/rx_command.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rx_command.dart b/lib/rx_command.dart index 4e7b939..51ec4f2 100644 --- a/lib/rx_command.dart +++ b/lib/rx_command.dart @@ -115,7 +115,7 @@ class CommandError { /// where [TParam] is the type of data that is passed when calling [execute] and /// [TResult] denotes the return type of the handler function. To signal that /// a handler doesn't take a parameter or returns no value use the type `void` -abstract class RxCommand extends StreamView { +abstract class RxCommand extends StreamView { bool _isRunning = false; bool _canExecute = true; bool _executionLocked = false; @@ -539,7 +539,7 @@ abstract class RxCommand extends StreamView { .last; late Subject> _commandResultsSubject; - final Subject _resultsSubject; + final Subject _resultsSubject; final BehaviorSubject _isExecutingSubject = BehaviorSubject(); final BehaviorSubject _canExecuteSubject = BehaviorSubject(); final PublishSubject> _thrownExceptionsSubject = @@ -657,7 +657,9 @@ class RxCommandSync extends RxCommand { result = null; } lastResult = result; - _resultsSubject.add(result); + if (result != null || null is TResult) { + _resultsSubject.add(result as TResult); + } commandResult = CommandResult(param, result, null, false); _commandResultsSubject.add(commandResult); From 3728d9e019f1730a7738e4a3c9854dca6a0f0d7f Mon Sep 17 00:00:00 2001 From: mk-dev-1 <41755310+mk-dev-1@users.noreply.github.com> Date: Tue, 27 Apr 2021 16:51:59 +0200 Subject: [PATCH 2/3] Fixed getter next to be non-nullable --- lib/rx_command.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rx_command.dart b/lib/rx_command.dart index 51ec4f2..b3df666 100644 --- a/lib/rx_command.dart +++ b/lib/rx_command.dart @@ -533,8 +533,8 @@ abstract class RxCommand extends StreamView { loggingHandler; /// This property is a utility which allows us to chain RxCommands together. - Future get next => - Rx.merge([this, this.thrownExceptions.cast()]) + Future get next => + Rx.merge([this, this.thrownExceptions.cast()]) .take(1) .last; From 344be3b774b4efabb6f686fc83b6d672c9a0a514 Mon Sep 17 00:00:00 2001 From: mk-dev-1 <41755310+mk-dev-1@users.noreply.github.com> Date: Tue, 27 Apr 2021 16:52:18 +0200 Subject: [PATCH 3/3] Added additional test for non-nullable getter next --- test/rx_command_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/rx_command_test.dart b/test/rx_command_test.dart index 32a00fd..a65494f 100644 --- a/test/rx_command_test.dart +++ b/test/rx_command_test.dart @@ -667,6 +667,19 @@ void main() { command2.execute("Non-nullable string"); }); + + test("Nullability test for next'able", () async { + final cmd = RxCommand.createAsyncNoParam(() async { + await Future.delayed(Duration(milliseconds: 1000)); + return 42; + }, initialLastResult: 0); + + cmd.execute(); + final result = await cmd.next is int; + + expect(result, true); + }); + // No idea why it's not posible to catch the exception with expect(command.results, emitsError(isException)); /* test('RxCommand.createFromStreamWithException throw exeption = true', ()