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

Added optional cancel action to the createAsyncAction API #146

Merged
merged 2 commits into from
Apr 27, 2019
Merged

Conversation

piotrwitek
Copy link
Owner

@piotrwitek piotrwitek commented Apr 27, 2019

Description

Added optional cancel action to the createAsyncAction API

// actions.ts
import { createAsyncAction } from 'typesafe-actions';

const fetchTodosAsync = createAsyncAction(
  'FETCH_TODOS_REQUEST',
  'FETCH_TODOS_SUCCESS',
  'FETCH_TODOS_FAILURE',
  'FETCH_TODOS_CANCEL'
)<string, Todo[], Error, string>();

// epics.ts
import { fetchTodosAsync } from './actions';

const fetchTodosFlow: Epic<RootAction, RootAction, RootState, Services> = (action$, store, { todosApi }) =>
  action$.pipe(
    filter(isActionOf(fetchTodosAsync.request)),
    switchMap(action =>
      from(todosApi.getAll(action.payload)).pipe(
        map(fetchTodosAsync.success),
        catchError(pipe(fetchTodosAsync.failure, of)),
        takeUntil(action$.pipe(filter(isActionOf(fetchTodosAsync.cancel)))),
      )
    );

Related issues:

Checklist

  • I have read CONTRIBUTING.md
  • I have linked all related issues above
  • I have rebased my branch

For bugfixes:

  • I have added at least one unit test to confirm the bug have been fixed

For new features:

  • I have updated API docs and tutorial (if applicable)
  • I have added short examples to demonstrate new feature usage
  • I have added type unit tests with dts-jest
  • I have added runtime unit tests with dts-jest

@piotrwitek piotrwitek merged commit 95d0505 into master Apr 27, 2019
@piotrwitek piotrwitek deleted the #144 branch April 27, 2019 18:26
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.

Extend createAsyncAction to support cancellation
1 participant