Skip to content

v1.8.0 integration #2024

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

Merged
merged 37 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
762f729
Rewrite gDM type inference for better extraction of `dispatch`
markerikson Feb 5, 2022
2085614
Rewrite MiddlewareArray typetest to use a real store to fix CI
markerikson Feb 6, 2022
42607da
Drop TS versions before 4.1 from the test matrix
markerikson Feb 6, 2022
3ff7137
Fix type issues with listener fork test
markerikson Feb 6, 2022
793c5d5
Merge pull request #2001 from reduxjs/feature/gdm-array-types
markerikson Feb 6, 2022
ac77814
Carry type of `extra` argument through the listener config
markerikson Feb 6, 2022
faf5438
Rename API to createListenerMiddleware
markerikson Feb 6, 2022
41f70e8
Rename listener middleware public APIs and rework return value
markerikson Feb 12, 2022
5c398cd
Merge pull request #2005 from reduxjs/feature/listener-signature-changes
markerikson Feb 12, 2022
75e8275
feat(alm): add meaningful cancellation reasons to TaskAbortError and …
FaberVitale Feb 12, 2022
1635f8c
Merge pull request #2023 from FaberVitale/feat/alm-improve-task-abort…
markerikson Feb 12, 2022
8441ec5
Release 0.8.0
markerikson Feb 12, 2022
010d824
fix(alm): apply alm breaking API changes to counter-example
FaberVitale Feb 13, 2022
8e8676d
fix(CI): update lockfile
FaberVitale Feb 13, 2022
519ed40
fix(alm): ListenerMiddlewareInstance not exported
FaberVitale Feb 13, 2022
d1d9ef9
Merge pull request #2026 from FaberVitale/fix/alm-missing-type-export
markerikson Feb 13, 2022
6e1d675
Merge pull request #2025 from FaberVitale/fix/alm-update-counter-example
markerikson Feb 13, 2022
840bc47
fix(alm): prevent zombie listeners caused by forked tasks
FaberVitale Feb 26, 2022
91f4c08
chore: build '@examples-query-react/*' examples when running "build:…
FaberVitale Feb 26, 2022
b96ffe1
Merge pull request #2070 from FaberVitale/fix/alm-reject-task-if-list…
markerikson Feb 26, 2022
8a13bb0
Move the listener middleware source into the RTK package
markerikson Feb 26, 2022
0cbe6a2
Clean up listener middleware TS types
markerikson Feb 26, 2022
f1f1fb2
Add listener middleware API ref / usage guide
markerikson Feb 26, 2022
9167d3c
Update TS test matrix to cover 4.6
markerikson Feb 26, 2022
1ddf6cc
Fix potential TS 4.7-related syntax issues
markerikson Feb 26, 2022
2af92f8
Remove standalone listener package folder entirely
markerikson Feb 26, 2022
88819e3
Merge pull request #2072 from reduxjs/feature/listener-middleware-int…
markerikson Feb 26, 2022
19b8904
fix(alm): cancel forkApi.delay and forkApi.pause if listener is cance…
FaberVitale Feb 26, 2022
effab14
Merge pull request #2074 from reduxjs/feature/listener-abort-task
markerikson Feb 26, 2022
1ddda6c
Fix broken transpilation of map iteration in listener middleware
markerikson Feb 27, 2022
202a88a
Release 1.8.0-rc.0
markerikson Feb 27, 2022
22cbc98
Update lockfile from release
markerikson Feb 27, 2022
7cedc2d
chore(alm): update counter example to 1.8.0
FaberVitale Feb 27, 2022
cb97bfa
Merge pull request #2076 from FaberVitale/chore/update-counter-exampl…
markerikson Feb 27, 2022
5d39ecf
Rename `removeAllListeners` to `clearAllListeners`
markerikson Feb 27, 2022
5acc6ef
Enable cancelling listeners when unsubscribing
markerikson Feb 27, 2022
7cdd615
Merge pull request #2078 from reduxjs/feature/final-1.8-cleanup
markerikson Feb 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
"packages": [
"packages/toolkit",
"packages/rtk-query-graphql-request-base-query",
"packages/action-listener-middleware",
"packages/rtk-query-codegen-openapi"
],
"publishDirectory": {
"@reduxjs/toolkit": "packages/toolkit",
"@rtk-query/graphql-request-base-query": "packages/rtk-query-graphql-request-base-query",
"@rtk-incubator/action-listener-middleware": "packages/action-listener-middleware",
"@rtk-query/codegen-openapi": "packages/rtk-query-codegen-openapi"
}
}
31 changes: 0 additions & 31 deletions .github/workflows/listenerTests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
fail-fast: false
matrix:
node: ['14.x']
ts: ['3.9', '4.0', '4.1', '4.2', '4.3', '4.4', '4.5', 'next']
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6.1-rc', 'next']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
701 changes: 701 additions & 0 deletions docs/api/createListenerMiddleware.mdx

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions examples/action-listener/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@reduxjs/toolkit": "^1.6.0-rc.1",
"@rtk-incubator/action-listener-middleware": "^0.6.0",
"@reduxjs/toolkit": "^1.8.0-rc.0",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
Expand Down
35 changes: 35 additions & 0 deletions examples/action-listener/counter/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useEffect } from 'react'
import { Provider } from 'react-redux'
import type { Unsubscribe } from '@reduxjs/toolkit'
import { setupThemeListeners } from '../../services/theme/listeners'
import { setupCounterListeners } from '../../services/counter/listeners'
import { ChangeThemeForm } from '../ChangeThemeForm/ChangeThemeForm'
import { CounterList } from '../CounterList/CounterList'
import { CreateCounterForm } from '../CreateCounterForm/CreateCounterForm'
import { store, startAppListening } from '../../store'

export function App() {
useEffect(() => {
const subscriptions: Unsubscribe[] = [
setupCounterListeners(startAppListening),
setupThemeListeners(startAppListening),
]

return () => subscriptions.forEach((unsubscribe) => unsubscribe())
}, [])

return (
<React.StrictMode>
<Provider store={store}>
<main className={'main'}>
<header className="App-header">
<h1>Counter example</h1>
</header>
<ChangeThemeForm />
<CreateCounterForm />
<CounterList />
</main>
</Provider>
</React.StrictMode>
)
}
22 changes: 2 additions & 20 deletions examples/action-listener/counter/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import { Provider } from 'react-redux'
import { store } from './store'
import { themeActions } from './services/theme/slice'
import { ChangeThemeForm } from './components/ChangeThemeForm/ChangeThemeForm'
import { CounterList } from './components/CounterList/CounterList'
import { CreateCounterForm } from './components/CreateCounterForm/CreateCounterForm'
import { App } from './components/App/App'

if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
store.dispatch(themeActions.changeColorScheme('dark'))
}

ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<main className={'main'}>
<header className="App-header">
<h1>Counter example</h1>
</header>
<ChangeThemeForm />
<CreateCounterForm />
<CounterList />
</main>
</Provider>
</React.StrictMode>,
document.getElementById('root')
)
ReactDOM.render(<App />, document.getElementById('root'))
26 changes: 16 additions & 10 deletions examples/action-listener/counter/src/services/counter/listeners.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { counterActions, counterSelectors } from './slice'
import { AnyAction, isAllOf, isAnyOf, PayloadAction } from '@reduxjs/toolkit'
import type { AppListenerApi, AppActionListenerMiddleware } from '../../store'
import {
AnyAction,
isAllOf,
isAnyOf,
PayloadAction,
Unsubscribe,
} from '@reduxjs/toolkit'
import type { AppListenerEffectAPI, AppStartListening } from '../../store'

function shouldStopAsyncTasksOf(id: string) {
return isAllOf(
Expand All @@ -14,7 +20,7 @@ async function onUpdateByPeriodically(
{
payload: { id, delta },
}: ReturnType<typeof counterActions.updateByPeriodically>,
{ dispatch, getState, getOriginalState, condition }: AppListenerApi
{ dispatch, getState, getOriginalState, condition }: AppListenerEffectAPI
) {
const counter = counterSelectors.selectById(getState(), id)

Expand Down Expand Up @@ -44,7 +50,7 @@ async function onUpdateAsync(
{
payload: { id, delta, delayMs },
}: ReturnType<typeof counterActions.updateByAsync>,
{ condition, dispatch, getState }: AppListenerApi
{ condition, dispatch, getState }: AppListenerEffectAPI
) {
const counter = counterSelectors.selectById(getState(), id)

Expand All @@ -71,16 +77,16 @@ async function onUpdateAsync(
* ```
*/
export function setupCounterListeners(
actionListener: AppActionListenerMiddleware
) {
startListening: AppStartListening
): Unsubscribe {
const subscriptions = [
actionListener.addListener({
startListening({
actionCreator: counterActions.updateByPeriodically,
listener: onUpdateByPeriodically,
effect: onUpdateByPeriodically,
}),
actionListener.addListener({
startListening({
actionCreator: counterActions.updateByAsync,
listener: onUpdateAsync,
effect: onUpdateAsync,
}),
]

Expand Down
25 changes: 13 additions & 12 deletions examples/action-listener/counter/src/services/theme/listeners.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { themeActions } from './slice'
import type { AppActionListenerMiddleware } from '../../store'
import type { AppStartListening } from '../../store'
import { Unsubscribe } from '@reduxjs/toolkit'

function onChangeColorScheme(
action: ReturnType<typeof themeActions.changeColorScheme>
) {
if (action.payload === 'light') {
document.documentElement.classList.remove('dark')
} else {
document.documentElement.classList.add('dark')
}
document.documentElement.classList.toggle('dark', action.payload !== 'light')
}

export function setupThemeListeners(
actionListener: AppActionListenerMiddleware
) {
return actionListener.addListener({
actionCreator: themeActions.changeColorScheme,
listener: onChangeColorScheme,
})
startListening: AppStartListening
): Unsubscribe {
const listeners = [
startListening({
actionCreator: themeActions.changeColorScheme,
effect: onChangeColorScheme,
}),
]

return () => listeners.forEach((unsubscribe) => unsubscribe())
}
38 changes: 17 additions & 21 deletions examples/action-listener/counter/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import { configureStore } from '@reduxjs/toolkit'
import { counterSlice } from './services/counter/slice'
import {
createActionListenerMiddleware,
ActionListenerMiddlewareAPI,
ActionListenerMiddleware,
} from '@rtk-incubator/action-listener-middleware'
configureStore,
createListenerMiddleware,
TypedStartListening,
TypedAddListener,
ListenerEffectAPI,
addListener,
} from '@reduxjs/toolkit'
import { counterSlice } from './services/counter/slice'
import { themeSlice } from './services/theme/slice'
import { setupCounterListeners } from './services/counter/listeners'
import { setupThemeListeners } from './services/theme/listeners'

const actionListenerMiddleware = createActionListenerMiddleware({
const listenerMiddlewareInstance = createListenerMiddleware({
onError: () => console.error,
})

Expand All @@ -19,7 +19,7 @@ const store = configureStore({
[counterSlice.name]: counterSlice.reducer,
[themeSlice.name]: themeSlice.reducer,
},
middleware: (gDM) => gDM().prepend(actionListenerMiddleware),
middleware: (gDM) => gDM().prepend(listenerMiddlewareInstance.middleware),
})

export { store }
Expand All @@ -29,19 +29,15 @@ export type RootState = ReturnType<typeof store.getState>
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch

export type AppListenerApi = ActionListenerMiddlewareAPI<RootState, AppDispatch>
export type AppActionListenerMiddleware = ActionListenerMiddleware<
RootState,
AppDispatch
>
export type AppListenerEffectAPI = ListenerEffectAPI<RootState, AppDispatch>

// Typed version of `actionListenerMiddleware`
export const appActionListener =
actionListenerMiddleware as AppActionListenerMiddleware
export type AppStartListening = TypedStartListening<RootState>
export type AppAddListener = TypedAddListener<RootState>

export const startAppListening =
listenerMiddlewareInstance.startListening as AppStartListening
export const addAppListener = addListener as AppAddListener

// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = () => useDispatch<AppDispatch>()
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

setupCounterListeners(appActionListener)
setupThemeListeners(appActionListener)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"scripts": {
"build": "yarn build:packages",
"test": "yarn test:packages",
"build:examples": "yarn workspaces foreach --include '@reduxjs/*' --include '@examples-query-react/*' -vtp run build",
"build:examples": "yarn workspaces foreach --include '@reduxjs/*' --include '@examples-query-react/*' --include '@examples-action-listener/*' -vtp run build",
"build:docs": "yarn workspace website run build",
"build:packages": "yarn workspaces foreach --include '@reduxjs/*' --include '@rtk-query/*' --include '@rtk-incubator/*' --topological-dev run build",
"build:packages": "yarn workspaces foreach --include '@reduxjs/*' --include '@rtk-query/*' --topological-dev run build",
"test:packages": "yarn workspaces foreach --include '@reduxjs/*' --include '@rtk-query/*' --include '@rtk-incubator/*' run test",
"dev:docs": "yarn workspace website run start"
}
Expand Down
4 changes: 0 additions & 4 deletions packages/action-listener-middleware/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions packages/action-listener-middleware/LICENSE

This file was deleted.

Loading