brianegan/redux_thunk

Action did not get called as expect

lasseschmitt opened this issue · 7 comments

Hey @brianegan ,

if I follow your instruction

final action = (Store<String> store) async {
  final searchResults = await new Future.delayed(
    new Duration(seconds: 1),
    () => "Search Results",
  );
  store.dispatch(searchResults);
};

.....
store.dispatch(action)

First thing I noticed. Intellij give me the following warning:

info: The type of the function literal can't be inferred because the literal has a block as its body.

Second the the action did not get called. So I had a look whats actually happens.

void thunkMiddleware<State>(Store<State> store, action, NextDispatcher next) {
  print("thunkMiddlewareA: ${ThunkAction}");
  print("thunkMiddlewareB: ${action}");
  print("thunkMiddlewareB: ${action is ThunkAction}");
  if (action is ThunkAction) {
    action(store);
  } else {
    next(action);
  }
}

The result of the logs are:

thunkMiddlewareA: (Store) => void
thunkMiddlewareB: Closure: (Store) => Future
thunkMiddlewareB: false

Im on the latest flutter master channel.

Flutter (Channel master, v0.2.5-pre.28, on Mac OS X 10.13.3 17D102, locale en-DE)

Any idea?

Thanks for the report! I'll get Dart 2 support going for Redux then address this as a next step.

Hrm, this one is also super weird :( I've got a test that matches exactly what you've got and it's passing :( :( :(

WHY DART 2!!?!

Could you please try running the tests from this lib on your machine with the Dart that ships with flutter?

Mmm I noticed I didn't turn on --preview-dart-2 but the dart2 features like AwesomeClass() instead of new AwesomeClass() where available anyway. Do you think that could be somehow related?

Hrm, sounds like something funny is going on for sure. Also, I'd recommend using new and const until this issue is fully resolved: dart-lang/sdk#32553

I've run into some weird issues with optional new / const myself ;(

Ok Im not sure whats happing now..

/Users/eikebartels/Applications/flutter/bin/flutter --no-color test --machine test/redux_thunk_test.dart
Testing started at 19:28 ...
compiler message: file:///Users/eikebartels/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:56:10: Error: The return type of the method 'TypeSafeStream::firstWhere' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<#lib1::TypeSafeStream::T>).
compiler message: Change to a subtype of dart.async::Future<#lib1::TypeSafeStream::T>.
compiler message:   Future firstWhere(bool test(T element), {Object defaultValue()}) =>
compiler message:          ^
compiler message: file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream.dart: Context: This is the overriden method ('firstWhere').
compiler message: file:///Users/eikebartels/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:56:10: Error: The method 'TypeSafeStream::firstWhere' has fewer named arguments than those of overridden method 'Stream::firstWhere'.
compiler message:   Future firstWhere(bool test(T element), {Object defaultValue()}) =>
compiler message:          ^
compiler message: file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream.dart: Context: This is the overriden method ('firstWhere').
compiler message: file:///Users/eikebartels/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:59:10: Error: The return type of the method 'TypeSafeStream::lastWhere' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<#lib1::TypeSafeStream::T>).
compiler message: Change to a subtype of dart.async::Future<#lib1::TypeSafeStream::T>.
compiler message:   Future lastWhere(bool test(T element), {Object defaultValue()}) =>
compiler message:          ^
compiler message: file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream.dart: Context: This is the overriden method ('lastWhere').
compiler message: file:///Users/eikebartels/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:59:10: Error: The method 'TypeSafeStream::lastWhere' has fewer named arguments than those of overridden method 'Stream::lastWhere'.
compiler message:   Future lastWhere(bool test(T element), {Object defaultValue()}) =>
compiler message:          ^
compiler message: file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream.dart: Context: This is the overriden method ('lastWhere').
compiler message: file:///Users/eikebartels/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:62:13: Error: The method 'TypeSafeStream::singleWhere' has fewer named arguments than those of overridden method 'Stream::singleWhere'.
compiler message:   Future<T> singleWhere(bool test(T element)) async =>
compiler message:             ^
compiler message: file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream.dart: Context: This is the overriden method ('singleWhere').
package:test                                                                                   serializeSuite
/var/folders/r6/wfjk122d2hv88767fbydx92h0000gn/T/dart_test_listenerVy37xc/listener.dart 18:27  main

Failed to load "/Users/eikebartels/Documents/driveddy/external/redux_thunk/test/redux_thunk_test.dart":
type 'List' is not a subtype of type 'List<String>' where
  List is from dart:core
  List is from dart:core
  String is from dart:core

side note. I also run the tests from flutter_redux to check if any tests are running and yea they running trough with 100% success

Looking at that stack trace, it seems something (probably the test package) is relying on an old Version of the async package (1.13.3) which doesn't support Dart 2 :(

All right, figured out that, despite using the --preview-dart-2 flag with the Dart 2 SDK, it wasn't quite enabling all of the same features that Flutter was, haha. Figured out the problem, new version has been deployed: 0.2.0