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

v1.8.0 integration #2024

Merged
merged 37 commits into from
Feb 27, 2022
Merged

v1.8.0 integration #2024

merged 37 commits into from
Feb 27, 2022

Conversation

markerikson
Copy link
Collaborator

This is our ongoing integration branch for changes that will be released as part of RTK 1.8.

See #2003 for related planning and discussion.

markerikson and others added 12 commits February 6, 2022 12:31
`getDefaultMiddleware` defines an initial type that may or may not
include `thunk`, depending on options. From there, `EnhancedStore`
tries to extract any extensions to `dispatch` from "the type of all
middleware as an array", to fully infer the correct type of
`store.dispatch`.

This was flaky. In particular, the `MiddlewareArray` type ended up
with "a union of all middleware" type, and that meant the extensions
weren't always getting read correctly.

This commit rewrites the inference to be more correct:

- `MiddlewareArray` now tracks an exact tuple type for its contents
- `.concat/prepend` now update that middleware tuple type
- We exactly extract the dispatch extensions from the tuple,
  and retain the exact order of the middleware as declared
- All the extensions are intersected together with `Dispatch`

This should now correctly represent cases like the listener
middleware returning an `Unsubscribe` callback in response to
`dispatch(addListenerAction())`

This commit also drops support for passing `null` as the `extraArg`
generic for `ThunkAction`, as that is an outdated pattern and
we want to discourage it.
This commit makes major breaking changes to the listener middleware.

First, we've renamed all the public methods and action creators,
so that we have a consistent naming scheme without clashes:

- API: `createListenerMiddleware`
- Returns: `{middleware, startListening, stopListening, clearListeners}`
- Docs examples show the object as `listenerMiddleware`
- One entry: "listener"
- Field in that listener entry: `effect`
- Action creators: `addListener`, `removeListener`, `removeAllListeners`

Next, `createListenerMiddleware` now returns an object containing
`{middleware, start/stop/clear}`, rather than the middleware itself
with those methods attached.

This works around the TS inference issues from attaching the add
and remove functions directly to the middleware function itself,
and allows `const unsub = dispatch(addListener())` to have
correct TS types for the return value.
…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

codesandbox-ci bot commented Feb 12, 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 7cdd615:

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

@github-actions
Copy link

github-actions bot commented Feb 12, 2022

size-limit report 📦

Path Size
1. entry point: @reduxjs/toolkit (cjs.production.min.js) 14.54 KB (+12.46% 🔺)
1. entry point: @reduxjs/toolkit (esm.js) 12.38 KB (+14.75% 🔺)
1. entry point: @reduxjs/toolkit/query (cjs.production.min.js) 24.29 KB (+7.17% 🔺)
1. entry point: @reduxjs/toolkit/query (esm.js) 19.01 KB (-0.13% 🔽)
1. entry point: @reduxjs/toolkit/query/react (cjs.production.min.js) 26.58 KB (+6.72% 🔺)
1. entry point: @reduxjs/toolkit/query/react (esm.js) 21.7 KB (-0.14% 🔽)
2. entry point: @reduxjs/toolkit (without dependencies) (cjs.production.min.js) 7.33 KB (+28.38% 🔺)
2. entry point: @reduxjs/toolkit (without dependencies) (esm.js) 7.28 KB (+28.53% 🔺)
2. entry point: @reduxjs/toolkit/query (without dependencies) (cjs.production.min.js) 10.12 KB (0%)
2. entry point: @reduxjs/toolkit/query (without dependencies) (esm.js) 10.55 KB (0%)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (cjs.production.min.js) 2.8 KB (0%)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (esm.js) 3.21 KB (0%)
3. createSlice (esm.js) 5.08 KB (+0.96% 🔺)
3. createEntityAdapter (esm.js) 6.44 KB (+2.57% 🔺)
3. configureStore (esm.js) 5.82 KB (+3.05% 🔺)
3. createApi (esm.js) 17.22 KB (-0.13% 🔽)
3. createApi (react) (esm.js) 19.93 KB (-0.11% 🔽)
3. fetchBaseQuery (esm.js) 11.6 KB (-0.21% 🔽)
3. setupListeners (esm.js) 10.46 KB (+0.36% 🔺)
3. ApiProvider (esm.js) 18.56 KB (-0.13% 🔽)

@netlify
Copy link

netlify bot commented Feb 12, 2022

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

🔨 Explore the source changes: 7cdd615

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

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

markerikson and others added 3 commits February 26, 2022 18:46
…lled or completed

-- Test log

$ yarn workspace @reduxjs/toolkit run test
 PASS  src/query/tests/buildHooks.test.tsx (21.737 s)
 PASS  src/listenerMiddleware/tests/listenerMiddleware.test.ts
 PASS  src/tests/createAsyncThunk.test.ts
 PASS  src/query/tests/createApi.test.ts
 PASS  src/entities/tests/sorted_state_adapter.test.ts
 PASS  src/query/tests/fetchBaseQuery.test.tsx
 PASS  src/tests/createReducer.test.ts
 PASS  src/entities/tests/unsorted_state_adapter.test.ts
 PASS  src/query/tests/cacheLifecycle.test.ts
 PASS  src/query/tests/errorHandling.test.tsx
 PASS  src/query/tests/queryLifecycle.test.tsx
 PASS  src/tests/serializableStateInvariantMiddleware.test.ts
 PASS  src/tests/matchers.test.ts
 PASS  src/listenerMiddleware/tests/fork.test.ts
 PASS  src/query/tests/devWarnings.test.tsx
 PASS  src/query/tests/queryFn.test.tsx
 PASS  src/query/tests/refetchingBehaviors.test.tsx
 PASS  src/tests/immutableStateInvariantMiddleware.test.ts
 PASS  src/query/tests/useMutation-fixedCacheKey.test.tsx
 PASS  src/listenerMiddleware/tests/effectScenarios.test.ts
 PASS  src/query/tests/optimisticUpdates.test.tsx
 PASS  src/tests/createSlice.test.ts
 PASS  src/query/tests/retry.test.ts
 PASS  src/tests/getDefaultMiddleware.test.ts
 PASS  src/tests/configureStore.test.ts
 PASS  src/query/tests/matchers.test.tsx
 PASS  src/listenerMiddleware/tests/useCases.test.ts
 PASS  src/query/tests/buildThunks.test.tsx
 PASS  src/tests/createAction.test.ts
 PASS  src/tests/combinedTest.test.ts
 PASS  src/query/tests/fakeBaseQuery.test.tsx
 PASS  src/query/tests/buildMiddleware.test.tsx
 PASS  src/entities/tests/state_selectors.test.ts
 PASS  src/query/tests/invalidation.test.tsx
 PASS  src/query/tests/cacheCollection.test.ts
 PASS  src/query/tests/utils.test.ts
 PASS  src/query/tests/cleanup.test.tsx
 PASS  src/query/tests/polling.test.tsx
 PASS  src/entities/tests/entity_state.test.ts
 PASS  src/query/tests/copyWithStructuralSharing.test.ts
 PASS  src/entities/tests/state_adapter.test.ts
 PASS  src/query/tests/buildSlice.test.ts
 PASS  src/entities/tests/utils.spec.ts
 PASS  src/query/tests/apiProvider.test.tsx
 PASS  src/query/tests/defaultSerializeQueryArgs.test.ts
 PASS  src/tests/createDraftSafeSelector.test.ts
 PASS  src/tests/isPlainObject.test.ts

Test Suites: 2 skipped, 47 passed, 47 of 49 total
Tests:       23 skipped, 685 passed, 708 total
Snapshots:   51 passed, 51 total
Time:        65.182 s
Ran all test suites.
@markerikson markerikson marked this pull request as ready for review February 27, 2022 00:47
@FaberVitale
Copy link
Contributor

Docs feedback

I've taken a look at the docs: https://deploy-preview-2024--redux-starter-kit-docs.netlify.app/api/createListenerMiddleware#overview and I'm quite impressed:

They're really good 💯 but I've noticed that there are things that could be improved.

Suggested changes

1. Expand clearListeners and removeAllListeners description

We have to specify that we're also cancelling active listeners.


2. Rename removeAllListeners to clearAllListeners

I think that the name removeAllListeners is problematic:

it implies a behavior similar to removeListener but this function will not only unsubscribe all entries but also cancel all running listeners.

When we remove listeners we're just unsubscribing entries.
When we clear listeners we're removing subscriptions and cancelling active listeners.

I believe that we have to rename removeAllListeners to clearAllListeners.

@markerikson
Copy link
Collaborator Author

Okay, yeah, I think that makes sense.

@markerikson markerikson changed the title [DRAFT] v1.8.0 integration v1.8.0 integration Feb 27, 2022
@markerikson markerikson merged commit bc62c9e into master Feb 27, 2022
@markerikson markerikson deleted the v1.8.0-integration branch February 27, 2022 20:45
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