-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
…o improve-treeshakeability
- Loading branch information
Showing
127 changed files
with
6,710 additions
and
1,585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@examples-type-portability/bundler", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "testing type portability for moduleResolution Bundler", | ||
"keywords": [], | ||
"main": "src/index.tsx", | ||
"dependencies": { | ||
"@reduxjs/toolkit": "workspace:^", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"react-redux": "^9.1.2", | ||
"react-router-dom": "^6.25.1", | ||
"react-scripts": "5.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.11", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"typescript": "^5.5.4" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app" | ||
], | ||
"rules": { | ||
"react/react-in-jsx-scope": "off" | ||
} | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "yarn clean && tsc -p tsconfig.json" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Link, Route, Routes } from 'react-router-dom' | ||
import { Lazy } from './features/bundleSplitting' | ||
import { CounterList } from './features/counter/CounterList' | ||
import { PollingToggles } from './features/polling/PollingToggles' | ||
import { PostsManager } from './features/posts/PostsManager' | ||
import { TimeList } from './features/time/TimeList' | ||
|
||
export function App() { | ||
return ( | ||
<div className="App"> | ||
<div className="row"> | ||
<div className="column column1"> | ||
<span> | ||
<Link to="/">Times</Link> | <Link to="/posts">Posts</Link> |{' '} | ||
<Link to="/counters">Counter</Link> |{' '} | ||
<Link to="/bundleSplitting">Bundle Splitting</Link> | ||
</span> | ||
</div> | ||
<div className="column column1"> | ||
<PollingToggles /> | ||
</div> | ||
</div> | ||
<div /> | ||
<div> | ||
<Routes> | ||
<Route path="/" element={<TimeList />} /> | ||
<Route path="/counters" element={<CounterList />} /> | ||
<Route path="/posts/*" element={<PostsManager />} /> | ||
<Route path="/bundleSplitting" element={<Lazy />} /> | ||
</Routes> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { | ||
Api, | ||
BaseQueryFn, | ||
CoreModule, | ||
EndpointDefinitions, | ||
Module, | ||
} from '@reduxjs/toolkit/query' | ||
import { buildCreateApi, coreModule } from '@reduxjs/toolkit/query' | ||
|
||
export const customModuleName = Symbol('customModule') | ||
export type CustomModule = typeof customModuleName | ||
|
||
// If we remove this, We should get a TypeScript error. | ||
declare module '@reduxjs/toolkit/query' { | ||
export interface ApiModules< | ||
BaseQuery extends BaseQueryFn, | ||
Definitions extends EndpointDefinitions, | ||
ReducerPath extends string, | ||
TagTypes extends string, | ||
> { | ||
[customModuleName]: { | ||
endpoints: { | ||
[K in keyof Definitions]: { | ||
myEndpointProperty: string | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const myModule = (): Module<CustomModule> => ({ | ||
name: customModuleName, | ||
init(api, options, context) { | ||
// initialize stuff here if you need to | ||
|
||
return { | ||
injectEndpoint(endpoint, definition) { | ||
const anyApi = api as any as Api< | ||
any, | ||
Record<string, any>, | ||
string, | ||
string, | ||
CustomModule | CoreModule | ||
> | ||
anyApi.endpoints[endpoint].myEndpointProperty = 'test' | ||
}, | ||
} | ||
}, | ||
}) | ||
|
||
export const myCreateApi = buildCreateApi(coreModule(), myModule()) |
10 changes: 10 additions & 0 deletions
10
examples/type-portability/bundler/src/app/dynamicMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createDynamicMiddleware } from '@reduxjs/toolkit' | ||
|
||
export const dynamicMiddleware = createDynamicMiddleware() | ||
|
||
export const { addMiddleware, instanceId, middleware, withMiddleware } = | ||
dynamicMiddleware | ||
|
||
export const { withTypes, match, type } = withMiddleware | ||
|
||
export const { withTypes: _withTypes } = addMiddleware |
19 changes: 19 additions & 0 deletions
19
examples/type-portability/bundler/src/app/dynamicReactMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createDynamicMiddleware } from '@reduxjs/toolkit/react' | ||
import { listenerMiddleware } from './listenerMiddleware' | ||
|
||
export const dynamicReactMiddleware = createDynamicMiddleware() | ||
|
||
export const { | ||
addMiddleware, | ||
createDispatchWithMiddlewareHook, | ||
createDispatchWithMiddlewareHookFactory, | ||
instanceId, | ||
middleware, | ||
withMiddleware, | ||
} = dynamicReactMiddleware | ||
|
||
export const { withTypes } = addMiddleware | ||
|
||
export const useDispatchWithMiddleware = createDispatchWithMiddlewareHook( | ||
listenerMiddleware.middleware, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useDispatch, useSelector, useStore } from 'react-redux' | ||
import type { AppDispatch, AppStore, RootState } from './store' | ||
|
||
export const useAppDispatch = useDispatch.withTypes<AppDispatch>() | ||
export const useAppSelector = useSelector.withTypes<RootState>() | ||
export const useAppStore = useStore.withTypes<AppStore>() |
10 changes: 10 additions & 0 deletions
10
examples/type-portability/bundler/src/app/listenerMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createListenerMiddleware } from '@reduxjs/toolkit' | ||
|
||
export const listenerMiddleware = createListenerMiddleware() | ||
|
||
export const { clearListeners, middleware, startListening, stopListening } = | ||
listenerMiddleware | ||
|
||
export const { withTypes } = startListening | ||
|
||
export const { withTypes: _withTypes } = stopListening |
Oops, something went wrong.