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

Type inference for ofType, removal of ActionsObservable in favor of just Observable #681

Merged
merged 1 commit into from Nov 14, 2019

Conversation

@jayphelps
Copy link
Member

jayphelps commented Oct 19, 2019

Heavily inspired by examples that @thorn0 @tjfryan did in #622


For v2.0.0 I'd like to finally have ofType infer the TypeScript types automatically, so that you don't need to pass in the generic param or define your filter action(s) as the argument type of the next operator. This requires some voodoo and a new-ish version of TypeScript, but I'm not yet sure which minimum version. I'll have to try them until it breaks, before merging this, then I can document it in the changelog/docs.

At the same time, I want to get away from ActionsObservable because in the pipeable operator world, there's no need for it and it just adds friction/learning.

The primary reason StateObservable is not BehaviorSubject is because we want to expose state$.value but _we do not want to expose state$.next(something) because that would be a huge footgun that wouldn't do what you might think--no reason to do it inside your epics.


Have objections or other thoughts? Please lmk! We'll likely do the normal pre-alpha, alpha, beta, rc, etc cycle for 2.0, but depending on how smooth it goes, how many changes there are (don't expect too many) we might skip a step or two of those.

@jayphelps jayphelps force-pushed the oftype branch from 718c1db to 2e9e657 Oct 19, 2019
Copy link

cartant left a comment

LGTM

@jayphelps jayphelps force-pushed the oftype branch from 2e9e657 to 24ae92c Oct 19, 2019
@kwonoj

This comment has been minimized.

Copy link
Contributor

kwonoj commented Oct 19, 2019

🚢

@evertbouw

This comment has been minimized.

Copy link
Member

evertbouw commented Oct 19, 2019

I don't think it's necessary to deprecate ActionObservable before removing it. Changing the ofType method to an imported function is not a huge change and probably the only thing users will have to do, and they may have already done it.

@@ -42,7 +41,7 @@ export function createEpicMiddleware<T extends Action, O extends T = T, S = void
const stateSubject$ = new Subject<S>().pipe(
observeOn(uniqueQueueScheduler)
) as any as Subject<S>;

This comment has been minimized.

Copy link
@csvn

csvn Oct 22, 2019

Contributor

Nit: as any as Subject<S> can be removed, now that a regular Observable is used instead of ActionsObservable.

I love this PR, as I think it simplifies both usage and the code quite a bit. Sorry if I just jumped in with this review.

This comment has been minimized.

Copy link
@jayphelps

jayphelps Nov 14, 2019

Author Member

Wonderful! Thank you for pointing this out.

This comment has been minimized.

Copy link
@jayphelps

jayphelps Nov 14, 2019

Author Member

Turns out it couldn't just be removed as-is because while observeOn() uses RxJS's internal lift() function so it does return a Subject, the type definition does not reflect that with pipe() so from the type system point of view it's just an Observable and doesn't have .next() nor .asObservable(). No biggie as I was able to refactor the code in another way to avoid the casts.

…ble in favor of just Observable

BREAKING CHANGE: ActionsObservable existed so we could provide an ofType() method to the prototype of action$, before RxJS had pipeable operators. Now that pipeable operators have been out for quite some time we are removing ActionsObservable in favor or using the pipeable ofType() instead.

```js
// BEFORE
function someEpic(action$) {
  return action$
    .ofType('PING')
    .mapTo({ type: 'PONG' });
}

// AFTER
import { ofType } from 'redux-observable';
import { mapTo } from 'rxjs/operators';
function someEpic(action$) {
  return action$.pipe(
    ofType('PING')
    mapTo({ type: 'PONG' })
  );
}
```
@jayphelps jayphelps force-pushed the oftype branch from 73dfebd to 7805892 Nov 14, 2019
@jayphelps jayphelps changed the title WIP: Type inference for ofType, removal of ActionsObservable in favor of just Observable Type inference for ofType, removal of ActionsObservable in favor of just Observable Nov 14, 2019
@jayphelps jayphelps merged commit 16f083d into master Nov 14, 2019
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@jayphelps

This comment has been minimized.

Copy link
Member Author

jayphelps commented Nov 15, 2019

Thanks for all the reviews! I've cut a pre-release 2.0.0-alpha.0 or the next tag (which will be updated to whatever the latest pre-release is.

@csvn

This comment has been minimized.

Copy link
Contributor

csvn commented Dec 4, 2019

@jayphelps I noticed the release commit 9a85f64, but no publish seems to have been done to NPM (https://www.npmjs.com/package/redux-observable?activeTab=versions). Maybe there's some issue with the publishing pipeline. Should I create an issue for this?

@jayphelps

This comment has been minimized.

Copy link
Member Author

jayphelps commented Dec 4, 2019

Whoa. I know 100% for sure the 2.0 alpha was released and tagged as next. It’s been installed and used in several apps that I’m aware of. Not sure what happened. I’ll look into it ASAP likely this weekend. Thanks for the heads up! Feel free to make a ticket if you’d like to subscribe to updates

@jayphelps

This comment has been minimized.

Copy link
Member Author

jayphelps commented Dec 4, 2019

Proof I’m not crazy.
A370ED88-F3F5-4D76-9D86-142AB2CF758E

@evertbouw

This comment has been minimized.

Copy link
Member

evertbouw commented Dec 4, 2019

npm info redux-observable shows

dist-tags:
latest: 1.2.0        next: 2.0.0-alpha.0  
@jayphelps

This comment has been minimized.

Copy link
Member Author

jayphelps commented Dec 4, 2019

Phew! Thanks for checking that @evertbouw it must just be a UI bug or DB issue. I’m not able to try to install it right now, but anyone should let us know if you can’t install.

@csvn

This comment has been minimized.

Copy link
Contributor

csvn commented Dec 4, 2019

That's weird... I didn't run npm info redux-observable, I just checked the NPM page, but it's still not showing the new alpha version 🤔

image

Thanks a lot, sorry for the noise!

edit: Running the npm command shows latest: 1.2.0 next: 2.0.0-alpha.0 as dist tags correctly
edit2: ...and npm install redux-observable@next works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.