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

feat(alm): add cancellation message to TaskAbortError, listenerApi.signal & forkApi.signal. #2023

Conversation

FaberVitale
Copy link
Contributor

Description

adds meaningful cancellation message to TaskAbortError, listenerApi.signal & forkApi.signal.

listenerApi.signal.reason can be one of

  • 'listener-cancelled'
  • 'listener-completed'

forkApi.signal.reason & TaskAbortError.code can be one of

  • 'listener-cancelled'
  • 'listener-completed'
  • 'task-cancelled'
  • 'task-completed'

Usage

startListening({ 
  predicate: () => true,
  async effect({ payload }, { signal }) {
    signal.addEventListener('abort', () => { 
        console.log(signal.reason)  // prints either "listener-completed" or "listener-cancelled"
    })
  },
})

Build log

$ yarn workspace @rtk-incubator/action-listener-middleware run build
Build "actionListenerMiddleware" to dist/esm:
       1739 B: index.modern.js.gz
       1566 B: index.modern.js.br
Build "actionListenerMiddleware" to dist/module:
      2.41 kB: index.js.gz
      2.15 kB: index.js.br
Build "actionListenerMiddleware" to dist/cjs:
       2.4 kB: index.js.gz
      2.15 kB: index.js.br

Test log

$ yarn workspace @rtk-incubator/action-listener-middleware run test --coverage
 PASS  src/tests/listenerMiddleware.test.ts (5.738 s)
 PASS  src/tests/effectScenarios.test.ts
 PASS  src/tests/fork.test.ts
 PASS  src/tests/useCases.test.ts
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files      |   97.72 |    91.38 |   94.64 |   97.55 |
 exceptions.ts |     100 |        0 |     100 |     100 | 17
 index.ts      |    97.4 |     97.5 |    92.5 |   97.32 | 190,214,252-253
 task.ts       |   97.06 |       80 |     100 |    96.3 | 30
 utils.ts      |     100 |    85.71 |     100 |     100 | 52
---------------|---------|----------|---------|---------|-------------------

Test Suites: 4 passed, 4 total
Tests:       72 passed, 72 total
Snapshots:   0 total
Time:        6.796 s
Ran all test suites.

…listenerApi.signal

listenerApi.signal.reason can be one of

- 'listener-cancelled'
- 'listener-completed'

forkApi.signal.reason can be one of

- 'listener-cancelled'
- 'listener-completed'
- 'task-cancelled'
- 'task-completed'

BREAKING CHANGE: renamed TaskAbortError.reason -> TaskAbortError.code

---

- Build log

```bash
$ yarn workspace @rtk-incubator/action-listener-middleware run build
Build "actionListenerMiddleware" to dist/esm:
       1739 B: index.modern.js.gz
       1566 B: index.modern.js.br
Build "actionListenerMiddleware" to dist/module:
      2.41 kB: index.js.gz
      2.15 kB: index.js.br
Build "actionListenerMiddleware" to dist/cjs:
       2.4 kB: index.js.gz
      2.15 kB: index.js.br
```

- Test log

```bash
$ yarn workspace @rtk-incubator/action-listener-middleware run test --coverage
 PASS  src/tests/listenerMiddleware.test.ts (5.738 s)
 PASS  src/tests/effectScenarios.test.ts
 PASS  src/tests/fork.test.ts
 PASS  src/tests/useCases.test.ts
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files      |   97.72 |    91.38 |   94.64 |   97.55 |
 exceptions.ts |     100 |        0 |     100 |     100 | 17
 index.ts      |    97.4 |     97.5 |    92.5 |   97.32 | 190,214,252-253
 task.ts       |   97.06 |       80 |     100 |    96.3 | 30
 utils.ts      |     100 |    85.71 |     100 |     100 | 52
---------------|---------|----------|---------|---------|-------------------

Test Suites: 4 passed, 4 total
Tests:       72 passed, 72 total
Snapshots:   0 total
Time:        6.796 s
Ran all test suites.
```
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 75e8275:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

@markerikson
Copy link
Collaborator

LGTM!

The bundle size has crept up slightly over the last few PRs, but given the functionality I'm okay with it.

@markerikson markerikson merged commit 1635f8c into reduxjs:v1.8.0-integration Feb 12, 2022
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.

2 participants