davidmarne / built_redux_rx

epic middleware for built_redux
MIT License
6 stars 4 forks source link

type 'Observable<Action>' is not a subtype of type 'Observable<Action<Null>>' where #3

Closed long1eu closed 6 years ago

tobytraylor commented 6 years ago

I'm getting something similar.

type 'Observable<Action>' is not a subtype of type 'Observable<Action>' where E/flutter ( 4609): Observable is from package:rxdart/src/observable.dart E/flutter ( 4609): Action is from package:built_redux/src/action.dart E/flutter ( 4609): Observable is from package:rxdart/src/observable.dart E/flutter ( 4609): Action is from package:built_redux/src/action.dart E/flutter ( 4609): String is from dart:core

E/flutter ( 4609): #0 EpicBuilder.add. (package:built_redux_rx/src/built_redux_rx.dart:55:28) E/flutter ( 4609): #1 createEpicMiddleware.. (package:built_redux_rx/src/built_redux_rx.dart:22:57) E/flutter ( 4609): #2 MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29) E/flutter ( 4609): #3 ListIterable.any (dart:_internal/iterable.dart:89:16) E/flutter ( 4609): #4 MergeStream._buildController (package:rxdart/src/streams/merge.dart:33:24) E/flutter ( 4609): #5 new MergeStream (package:rxdart/src/streams/merge.dart:19:22) E/flutter ( 4609): #6 new Observable.merge (package:rxdart/src/observable.dart:548:29)

After i upgraded from built_redux: ^7.0.0 to built_redux: ^7.4.1-dev as part of the move to Dart2.

Was thinking the issue was related to the signature of my Epics which look like this...

new EpicBuilder<AppState, AppStateBuilder, AppActions>() ..add(AppActionsNames.trialSelected, (stream, mwApi) { return stream.switchMap( (action) => firebaseStore.subscribeToTrial(action.payload) .map((results) { mwApi.actions.stateTrialUpdated(results); } ) ); })

Struggling to figure out what is going wrong so any help is appreciated...

tobytraylor commented 6 years ago

Found it. Change add<T>(ActionName<T> actionName, EpicHandler<V, B, A, T> handler) { To add<T>(ActionName<T> actionName, EpicHandler<V, B, A, dynamic> handler) { in the EpicBuilder implementation

class EpicBuilder<V extends Built<V, B>, B extends Builder<V, B>,
    A extends ReduxActions> {
  final _epics = new List<Epic<V, B, A>>();

  add<T>(ActionName<T> actionName, EpicHandler<V, B, A, dynamic> handler) {
    _epics.add(
        (Observable<Action<dynamic>> action, MiddlewareApi<V, B, A> mwApi) =>
            handler(action.where((a) => a.name == actionName.name), mwApi));
  }

  Iterable<Epic<V, B, A>> build() => _epics;
}
zgusth commented 6 years ago

@tobytraylor this is not good because we're required to use dynamic for all payloads.

In dart 2 we have to cast it to our action type.

Replace this handler(action.where((a) => a.name == actionName.name), mwApi));

With this handler(action.where((a) => a.name == actionName.name).cast<Action<T>>(), mwApi));

@davidmarne Please add a dart-2-dev branch to this repository. If you prefer I can open a pull request.

tkshnwesper commented 6 years ago

@zgusth Nice fix!

Make a PR, maybe? I see that your fork has this fix in place.

@davidmarne What do you think?

long1eu commented 6 years ago

or you could all switch to https://pub.dartlang.org/packages/redux witch is more maintained than this library and have a lot a extensions that just work, beside this they have a really supportive dev. I had 3 app written with this 'awesome' library that were all modified with the new one. Two are in production and they really work as expected.

So again if you don't wanna cry NOW is the time to switch. for flutter => https://pub.dartlang.org/packages/flutter_redux

tkshnwesper commented 6 years ago

Well, it's not much of a change. Just a tiny little cast that will make a developer's experience way better while using the library.

As for the libraries that you mentioned, I am already using both of them. However, there's nothing out there that can fully replace what this library has to offer.

The reason this isn't maintained is probably because the creator feels that there's not much left to add to it. But this teeny tiny change is absolutely necessary to make it complete.

That said, I would request you to kindly reopen this issue. I would be happy if the creator would take this issue into their consideration.

Thank you.

davidmarne commented 6 years ago

Sorry yall, you are right @tkshnwesper this library was kind of a proof of concept and I don't give it the attention it deserves. Furthermore, I was AFK for a while when this issue was created and when I got back my github was blown up and I missed this one. With that said I will make the change right now. I'm sorry this has been open for so long.

@long1eu is right, I cannot myself support these libraries as well as brian does for flutter_redux. Again I'm sorry for the slow response :(

tkshnwesper commented 6 years ago

Seeing how well it fits into my application, it feels more than just a proof-of-concept. Kudos 🎉

Thank you very much @davidmarne! :)