Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart 2 issue #22

Closed
lasseschmitt opened this issue Mar 21, 2018 · 10 comments
Closed

Dart 2 issue #22

lasseschmitt opened this issue Mar 21, 2018 · 10 comments

Comments

@lasseschmitt
Copy link

lasseschmitt commented Mar 21, 2018

Hello,

after updating to dart 2. I get the following error when using Reducer

error is happend type '(OnBoardingState, LicensesLoadedAction) => OnBoardingState' is not a subtype of type '(OnBoardingState, dynamic) => OnBoardingState'

My code looks like the following:

final onBoardingReducer = combineTypedReducers<OnBoardingState>([
  new ReducerBinding <OnBoardingState, LicensesLoadedAction>(_setLoadedLicenses),
]);

OnBoardingState _setLoadedLicenses(OnBoardingState onBoardingData, LicensesLoadedAction action) {
  return onBoardingData.copyWith(licenses: action.licenses);
}

If I set the type to dynamic it works but I would prefer to not have to case the action.

OnBoardingState _setLoadedSchools(OnBoardingState onBoardingData, dynamic action) {
  if(action is SchoolsLoadedAction) {
    return onBoardingData.copyWith(schools: action.schools);
  }
  return onBoardingData;
}

Any idea?

@envious
Copy link

envious commented Mar 22, 2018

I get a similar issue when dispatching actions using my store:

I/flutter ( 3621): The following assertion was thrown while handling a gesture: I/flutter ( 3621): type '(AppState, ChangeViewAction) => AppState' is not a subtype of type '(AppState, dynamic) => I/flutter ( 3621): AppState'

I believe changes to the redux_dart library need to be made in order to bring it up to speed with Dart 2, i'll try to investigate further

@brianegan
Copy link
Collaborator

Thanks for the reports! I'll try to find time soon to look into the issues :)

@brianegan
Copy link
Collaborator

brianegan commented Mar 23, 2018

@driveddy Hrm, are you passing the onBoardingReducer directly to the store? This is a curious case. I've run the tests again using the latest version of the Dart SDK from Flutter, which cover reducers and combining reducers, and the tests are currently passing.

@envious Are you also using combineTypedReducer? Could you please provide the signature of your Reducer?

If either of you are providing your own Reducer to the store (not one generated by combineTypedReducers), it must match the signature (State, dynamic) -> State. You cannot provide your own type signature for the action parameter, as this would break 3rd party libraries that need to dispatch actions. If combineTypedReducers is returning the wrong type signature, then we might need to submit a bug report to the dart SDK repo, since it returns a function of that signature.

@lasseschmitt
Copy link
Author

lasseschmitt commented Mar 23, 2018

My Store looks like this

 final store = new Store<AppState>(
  appStateReducer,
  initialState: new AppState.init(),
  middleware: createStoreMiddleware()
  );
class AppState {
  final FirebaseUser firebaseUser;
  final OnBoardingState onBoardingData;
  ....
}
AppState appStateReducer(AppState state, action) {
  return new AppState(
      firebaseUser: authReducer(state.firebaseUser, action),
      onBoardingData: onBoardingReducer(state.onBoardingData, action),
  );
}

And as in #3 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?

@brianegan
Copy link
Collaborator

brianegan commented Mar 23, 2018

Hrm, that's an interesting one! If you add the typing to the action in your appStateReducer then all should be good for Dart 2. E.g.

AppState appStateReducer(AppState state, dynamic action) {

If you're on master branch, it should be running Dart2 by default now, so you don't need to add the flag.

@lasseschmitt
Copy link
Author

Unfortunalty no -_-

Even if I add dynamic to AppState appStateReducer(AppState state, dynamic action) I still get

error is happend type '(OnBoardingState, LicensesLoadedAction) => OnBoardingState' is not a subtype of type '(OnBoardingState, dynamic) => OnBoardingState'

@brianegan
Copy link
Collaborator

brianegan commented Mar 24, 2018

Thanks for the reports! Sorry about these issues. I've found that all tests pass using the standalone Dart 2 SDK, but fail using Flutter test. Redux runs all its tests using the standalone SDK since it's a pure dart lib, but this might be hiding an error, or Flutter might be running into an error.

I've filed a bug on the repo: flutter/flutter#15900

@dodyg
Copy link

dodyg commented Mar 28, 2018

I encounter the same issue
I/flutter ( 5391): type '(IdentityState, LoginSuccessfulAction) => IdentityState' is not a subtype of type I/flutter ( 5391): '(IdentityState, dynamic) => IdentityState on

Flutter 0.2.5-pre.55 • channel master • https://github.com/flutter/flutter.git
Framework • revision 39eeec47d6 (13 hours ago) • 2018-03-27 15:27:24 -0700
Engine • revision 3e877d371a
Tools • Dart 2.0.0-dev.40.0.flutter-06949dc985

@brianegan
Copy link
Collaborator

brianegan commented Mar 28, 2018

Thanks for the report @dodyg!

As a heads up, I'm waiting on a response from the Flutter team to see if they can help us out here. Hard to know if this is a legit type issue that needs fixing or a Dart 2 problem since Redux works with the Dart 2 SDK but not on Flutter with the Dart 2 SDK.

@brianegan
Copy link
Collaborator

brianegan commented Mar 30, 2018

Hey @driveddy, @envious & @dodyg -- Just a heads up that I've released a new version of Redux 3.0.0 which addresses this problem. It also simplified the Redux API a bit, but requires a small migration. Please see the README for details: https://github.com/johnpryan/redux.dart/#redux-300-migration--dart-2-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants