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 alm.clear() method #1952

Merged

Conversation

FaberVitale
Copy link
Contributor

@FaberVitale FaberVitale commented Jan 22, 2022

Description

Adds the following apis

  • alm.clear(): unsubscribes all listeners, cancels running listeners and tasks.
  • clearListenerMiddlewareAction: an action creator whose actions trigger alm.clear().

Context: #1648 (comment)

SSR

I believe that this method can be very useful in SSR, because it provides a simple way to clean up all listeners that are still subscribed or running after rendering the page.

Build log

$ yarn workspace @rtk-incubator/action-listener-middleware run build
Build "actionListenerMiddleware" to dist/esm:
       1644 B: index.modern.js.gz
       1475 B: index.modern.js.br
Build "actionListenerMiddleware" to dist/module:
      2.31 kB: index.js.gz
      2.06 kB: index.js.br
Build "actionListenerMiddleware" to dist/cjs:
       2.3 kB: index.js.gz
      2.06 kB: index.js.br

Test log

$ yarn workspace @rtk-incubator/action-listener-middleware run test --coverage
 PASS  src/tests/listenerMiddleware.test.ts
 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.6 |    92.86 |   94.64 |   97.42 |                   
 exceptions.ts |     100 |      100 |     100 |     100 |                   
 index.ts      |   97.48 |    95.24 |   92.68 |    97.4 | 181,194,232-233   
 task.ts       |   97.06 |       80 |     100 |    96.3 | 31                
 utils.ts      |     100 |      100 |     100 |     100 |                   
---------------|---------|----------|---------|---------|-------------------

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 22, 2022

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 e9230e8:

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

@markerikson
Copy link
Collaborator

Should we add this as an action creator, too?

@FaberVitale
Copy link
Contributor Author

Should we add this as an action creator, too?

Yeah.

I was worried about weird interactions but we do not notify addListener and removeListener to the listeners. 👍

@netlify
Copy link

netlify bot commented Jan 22, 2022

✔️ Deploy Preview for redux-starter-kit-docs ready!

🔨 Explore the source changes: e9230e8

🔍 Inspect the deploy log: https://app.netlify.com/sites/redux-starter-kit-docs/deploys/61ec43fea3a82a00086b4e22

😎 Browse the preview: https://deploy-preview-1952--redux-starter-kit-docs.netlify.app

@markerikson
Copy link
Collaborator

also very interested in any other improvements to the "remove" APIs and behavior you can think of, per #1648 (reply in thread)

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