Skip to content

Conversation

@AlexanderOtavka
Copy link
Contributor

This is invaluable when using redux-observable since RxJS is written in typescript and has super solid type checking when the Observable.prototype.filter function gets a valid one-arg type guard.

I am open to changing the function name, I considered createTypeGuard or maybe something else.

@aikoven
Copy link
Owner

aikoven commented Aug 18, 2017

This is cool, thanks!

How about createTypePredicate? Or maybe even just typePredicate, short enough to just inline it

const epic = (actions$: Observable<Action>) =>
  actions$.filter(typePredicate(myAction))

Another idea is to add some method to the action creator itself, like test or match:

const epic = (actions$: Observable<Action>) =>
  actions$.filter(myAction.match)

The latter would be handy in reducers as well as an alternative to isType:

// before
if (isType(action, myAction)) {
  // ...
}

// after
if (myAction.match(action)) {
  // ...
}

What do you think?

@AlexanderOtavka
Copy link
Contributor Author

I love the match method idea. I hadn't considered that. I'll make the changes.

@NicholasBoll
Copy link

👍 @AlexanderOtavka Found this PR looking for a solution for your exact use-case (redux-observable epics)

@aikoven
Copy link
Owner

aikoven commented Aug 23, 2017

Looks good!

Could you please also add a regular test, apart from typings test?

@AlexanderOtavka
Copy link
Contributor Author

@aikoven Done!

@AlexanderOtavka AlexanderOtavka changed the title Add createTypeChecker function for partial application type guard Add ActionCreator#match method for single-argument type guard Aug 23, 2017
@aikoven aikoven merged commit 904a91f into aikoven:master Aug 24, 2017
@AlexanderOtavka AlexanderOtavka deleted the create-type-checker branch August 24, 2017 03:45
@aikoven
Copy link
Owner

aikoven commented Aug 24, 2017

Thanks! I'll make a release very soon.

@AlexanderOtavka
Copy link
Contributor Author

You are welcome! I look forward to upgrading my project.

@aikoven
Copy link
Owner

aikoven commented Aug 24, 2017

Just released v2.5.0

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

Successfully merging this pull request may close these issues.

3 participants