-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
v1.8.0 integration #2024
Conversation
`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. ```
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:
|
size-limit report 📦
|
✔️ 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 |
BREAKING CHANGE: forkedTask.result now rejects if parent listener is either completed or cancelled.
…ener-is-cancelled
- Added public/internal labels on all types - Removed export of `createListenerEntry` - Renamed 'S/D' generic args to 'State/Dispatch' for clarity
…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.
Same bug as be6e198 This appears to be some kind of issue with either ESBuild, TS, or both of them being used together. Replay of the bug: https://app.replay.io/recording/rtk-listener-middleware-not-updating--1bb6f325-3e75-4958-83b5-1d87719d4b6c
Docs feedbackI'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 changes1. Expand
|
Okay, yeah, I think that makes sense. |
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.